Skip to content

Fix regex-based version extraction in requirements.txt parsing#1122

Merged
oscarlevin merged 3 commits intoStevenClontz-patch-2from
copilot/sub-pr-1116
Mar 5, 2026
Merged

Fix regex-based version extraction in requirements.txt parsing#1122
oscarlevin merged 3 commits intoStevenClontz-patch-2from
copilot/sub-pr-1116

Conversation

Copy link

Copilot AI commented Mar 5, 2026

requirements_version() failed to parse pretext lines with extras (e.g., pretext[prefigure] == 2.36.0) and contained a syntax error (gm flags appended to a string literal).

Changes

  • pretext/utils.py

    • Remove duplicate import re
    • Fix SyntaxError: remove invalid gm suffix from regex string literal
    • Tighten version capture group from [\d\.]*[\d\.]+ (require at least one digit; prevents matching pretext ==)
    • Store re.match() result to avoid double evaluation
  • tests/test_utils.py

    • Add test_requirements_version() covering:
      • pretext, pretextbook, extras (pretext[prefigure], pretext[prefigure,extra])
      • Whitespace variations
      • Non-matching lines (numpy == ..., pretext ==, bare pretext)
# All of these now parse correctly
"pretext == 2.36.0"           # → "2.36.0"
"pretextbook == 1.2.3"        # → "1.2.3"
"pretext[prefigure] == 2.36.0"  # → "2.36.0"  (previously broken)

# These correctly return None
"pretext =="   # empty version
"numpy == 1.0.0"

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ests

Co-authored-by: oscarlevin <6504596+oscarlevin@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 5, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • runestone.academy
    • Triggering command: /usr/bin/python python scripts/fetch_core.py (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor version extraction with regex Fix regex-based version extraction in requirements.txt parsing Mar 5, 2026
@oscarlevin oscarlevin marked this pull request as ready for review March 5, 2026 02:26
@oscarlevin oscarlevin merged commit 8671c2e into StevenClontz-patch-2 Mar 5, 2026
1 of 2 checks passed
@oscarlevin oscarlevin deleted the copilot/sub-pr-1116 branch March 5, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants