PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
254 stars 202 forks source link

Pretext: escape backslashes in regex #2131

Closed Alex-Jordan closed 2 months ago

Alex-Jordan commented 2 months ago

With Python 3.12.2, running pretext produces these warnings:

/Users/alex.jordan/pretext/pretext/pretext.py:2524: SyntaxWarning: invalid escape sequence '\*'
  elif len(re.findall('^[ ]{2},\*apt} #([a-j]+?) ', line)) > 0:
/Users/alex.jordan/pretext/pretext/pretext.py:2526: SyntaxWarning: invalid escape sequence '\*'
  chapter_number = brf_to_num(re.findall("^[ ]{2},\*apt} #([a-j]+?) ", line)[0])

The intent here is to escape the asterisk in the regex context. But first the backslash must be escaped or python will produce that warning. I'm guessing might \* become *, and this regex was not working as intended. Or maybe \* becomes \*. But this change should have things working as intended and make those warnings go away.

rbeezer commented 2 months ago

I think this may be dead code, for chunking a braille BRF into chapters.

So did you get these warnings while doing something else? You weren't building braille were you? Is it simple a product of using 3.12.

Inclined to merge with very little testing...

Alex-Jordan commented 2 months ago

I think it is just because I upgraded python and it's reporting this where previous python versions sweep it under the rug. Not building braille, building webwork. But python is trying to parse everything in pretext.py, catches this, and gives those warnings.

rbeezer commented 2 months ago

it's reporting this where previous python versions sweep it under the rug

As suspected. Thanks for the confirmation. Merged.

Pinging @alexeikolesnikov since he is interested in this code.