@b4n commented on this pull request.


> +    for line in f:
+        # Look for lines containing 'AC_INIT'
+        if 'AC_INIT' in line:
+            # Use a regular expression to find the pattern:
+            # AC_INIT([ProjectName], [Version], ...)
+            # We want to capture the content of the second square bracket 
group.
+            # The regex looks for 'AC_INIT(', then '[anything]', then a comma
+            # and optional spaces, then captures '[Version]' into group 1.
+            match = re.search(r'AC_INIT\(\[[^\]]+],\s*\[([^\]]+)\].*', line)
+            if match:
+                VERSION = match.group(1)
+                print(f"GOT VERSION {VERSION} FROM {line}")
+            else:
+                print(f"!! FAILED TO GET VERSION FROM {line}")
+            break # Stop after finding the first AC_INIT line with a version

I'd use the more rough but plenty safe enough in practice, and a lot shorter:
```python
    ver = next((l.split(',')[1].strip(' []') for l in f if 
l.startswith('AC_INIT')), None)
    if ver is None:
        print(f"!! FAILED TO GET VERSION FROM {f.name}")
    else:
        VERSION=ver
        print(f"GOT VERSION {VERSION} FROM {f.name}")
```

As with the regex in the YML above, a couple things to keep in mind:
* The macro call has to be the first thing in the line (well… there are 
exceptions to this, but it's irrelevant here).  At most there could likely be 
spaces, nothing else.
* The `[]`s are *optional* quotes, only required when the value contains 
control characters (like `[` or `,` for example).  Here, while it's not 
perfect, we can likely assume the value of each parameter doesn't contain 
either of those.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/4223#pullrequestreview-2928807188
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/4223/review/[email protected]>

Reply via email to