cs-pub-ro / operating-systems

Teaching resources (OER) for Operating Systems
https://cs-pub-ro.github.io/operating-systems/
Other
7 stars 55 forks source link

generate_skels.py: SyntaxWarning for RegEx calls on Python 3.12 #107

Closed mucel29 closed 1 month ago

mucel29 commented 1 month ago

Description

Python 3.12 emmits a SyntaxWarning when using unescaped character inside a RegEx string.

Sample code

re.match(".*\.sh$", src)
A full example cand be found here

Make skels output

mkdir -p support/src
python3 generate_skels.py --input ./solution/src --output ./support/src
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:103: SyntaxWarning: invalid escape sequence '\.'
  or re.match(".*\.sh$", src)
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:104: SyntaxWarning: invalid escape sequence '\.'
  or re.match(".*\.[sS]$", src)
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:106: SyntaxWarning: invalid escape sequence '\s'
  pattern = "(^\s*#\s*TODO)( [0-9]*)(:.*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:107: SyntaxWarning: invalid escape sequence '\s'
  replace = "(^\s*#\s*REPLACE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:108: SyntaxWarning: invalid escape sequence '\s'
  remove = "(^\s*#\s*REMOVE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:111: SyntaxWarning: invalid escape sequence '\.'
  elif re.match(".*\.asm$", src):
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:112: SyntaxWarning: invalid escape sequence '\s'
  pattern = "(^\s*;\s*TODO)( [0-9]*)(:.*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:113: SyntaxWarning: invalid escape sequence '\s'
  replace = "(^\s*;\s*REPLACE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:114: SyntaxWarning: invalid escape sequence '\s'
  remove = "(^\s*;\s*REMOVE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:118: SyntaxWarning: invalid escape sequence '\.'
  re.match(".*\.[ch]$", src)
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:119: SyntaxWarning: invalid escape sequence '\.'
  or re.match(".*\.cpp$", src)
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:120: SyntaxWarning: invalid escape sequence '\.'
  or re.match(".*\.hpp$", src)
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:122: SyntaxWarning: invalid escape sequence '\*'
  pattern = "(.*/\*\s*TODO)([ 0-9]*)(:.*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:123: SyntaxWarning: invalid escape sequence '\*'
  replace = "(.*/\*\s*REPLACE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:124: SyntaxWarning: invalid escape sequence '\*'
  remove = "(.*/\*\s*REMOVE)( [0-9]*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:125: SyntaxWarning: invalid escape sequence '\*'
  replace_pairs = [("/\* ", ""), (" \*/", "")]
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:125: SyntaxWarning: invalid escape sequence '\*'
  replace_pairs = [("/\* ", ""), (" \*/", "")]
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:127: SyntaxWarning: invalid escape sequence '\.'
  elif re.match(".*\.d$", src):
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:128: SyntaxWarning: invalid escape sequence '\s'
  pattern = "(.*//\s*TODO)([ 0-9]*)(:.*)"
/home/mucel/so/operating-systems/chapters/data/working-with-memory/drills/tasks/memory-protection/generate_skels.py:129: SyntaxWarning: invalid escape sequence '\s'
  replace = "(.*//\s*REPLACE)( [0-9]*)"
./support/src/Makefile
./support/src/mem_prot.c
cp solution/src/str.py support/src/str.py
cp -r ./solution/tests ./support/tests
fabianpatras commented 1 month ago

Please check out this (external) issue: https://github.com/HandBrake/HandBrake/issues/5454.

Alex-deVis commented 1 month ago

Thank you for noticing this, @mucel29. I merged #108 which prefixes all patterns with r, as @fabianpatras suggested.