Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pretext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import logging.handlers
import psutil
import re
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re is imported twice in this module (already imported earlier). This will trip linters and is unnecessary; remove the newly added duplicate import.

Suggested change
import re

Copilot uses AI. Check for mistakes.
import typing as t
from . import types as pt # PreTeXt types
from lxml import etree as ET # noqa: N812
Expand Down Expand Up @@ -133,9 +134,10 @@ def requirements_version(dirpath: Optional[Path] = None) -> Optional[str]:
return None
try:
with open(pp / "requirements.txt", "r") as f:
REGEX = r"\s*pretext(book)?(\[.*\])?\s*==\s*(?P<version>[\d\.]*)\s*"gm
Comment thread
oscarlevin marked this conversation as resolved.
Outdated
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REGEX = r"..."gm is invalid Python syntax (it will raise a SyntaxError at import time). If you intended regex flags, pass them via re.compile(..., flags=...) (e.g., re.MULTILINE) instead of appending gm to the literal.

Suggested change
REGEX = r"\s*pretext(book)?(\[.*\])?\s*==\s*(?P<version>[\d\.]*)\s*"gm
REGEX = r"\s*pretext(book)?(\[.*\])?\s*==\s*(?P<version>[\d\.]*)\s*"

Copilot uses AI. Check for mistakes.
for line in f.readlines():
if ("pretext ==" in line) or ("pretextbook ==" in line):
return line.split("==")[1].strip()
if re.match(REGEX, line):
return re.match(REGEX, line).group("version")
Comment thread
oscarlevin marked this conversation as resolved.
Outdated
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requirements_version() parsing logic changed, but there are no targeted tests covering supported requirement lines (e.g., pretext[prefigure] == 2.36.0, pretextbook == ..., whitespace variations). Add a unit test to lock in the intended matching behavior and prevent regressions.

Copilot uses AI. Check for mistakes.
except Exception as e:
log.debug("Could not read `requirements.txt`:")
log.debug(e)
Expand Down
Loading