Skip to content

Commit

Permalink
Use raw strings for regular expressions
Browse files Browse the repository at this point in the history
Should avoid `SyntaxWarning: invalid escape sequence`
  • Loading branch information
cottsay committed Mar 22, 2024
1 parent be08140 commit ecec9fa
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bloom/generators/debian/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def get_package_from_branch(branch):
def debianize_string(value):
markup_remover = re.compile(r'<.*?>')
value = markup_remover.sub('', value)
value = re.sub('\s+', ' ', value)
value = re.sub(r'\s+', ' ', value)
value = value.strip()
return value

Expand Down
2 changes: 1 addition & 1 deletion bloom/generators/rpm/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def get_package_from_branch(branch):
def rpmify_string(value):
markup_remover = re.compile(r'<.*?>')
value = markup_remover.sub('', value)
value = re.sub('\s+', ' ', value)
value = re.sub(r'\s+', ' ', value)
value = '\n'.join([v.strip() for v in
textwrap.TextWrapper(width=80, break_long_words=False, replace_whitespace=False).wrap(value)])
return value
Expand Down
4 changes: 2 additions & 2 deletions docs/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
args = parser.parse_args()
with open(args.file, 'r') as f:
lines = f.read()
version_line_regex = re.compile(".*version='\d*[.]\d*[.]\d*'.*")
version_line_regex = re.compile(r".*version='\d*[.]\d*[.]\d*'.*")
version_line = version_line_regex.findall(lines)
version_line = version_line[0]
version_regex = re.compile('\d*[.]\d*[.]\d*')
version_regex = re.compile(r'\d*[.]\d*[.]\d*')
version_str = version_regex.findall(version_line)[0]
version_str = version_str.split('.')
version_str[-1] = str(int(version_str[-1]) + 1)
Expand Down
2 changes: 1 addition & 1 deletion test/system_tests/test_catkin_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_multi_package_repository(directory=None):
package_xml = f.read()
assert package_xml.count('<name>' + pkg + '</name>'), \
"incorrect package.xml for " + str(pkg)
format_version = int(re.search('format="(\d+)"',
format_version = int(re.search(r'format="(\d+)"',
package_xml).group(1))
# Is there a copyright file for this pkg?
with open('debian/copyright', 'r') as f:
Expand Down
6 changes: 3 additions & 3 deletions test/utils/package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def bump_version(version, bump='patch'):
parts reset to 0
"""
# split the version number
match = re.match('^(\d+)\.(\d+)\.(\d+)$', version)
match = re.match(r'^(\d+)\.(\d+)\.(\d+)$', version)
if match is None:
raise ValueError(
'Invalid version string, must be int.int.int: "%s"' % version
Expand All @@ -75,8 +75,8 @@ def _replace_version(package_str, new_version):
"""
# try to replace contens
new_package_str, number_of_subs = re.subn(
'<version([^<>]*)>[^<>]*</version>',
'<version\g<1>>%s</version>' % new_version, package_str
r'<version([^<>]*)>[^<>]*</version>',
r'<version\g<1>>%s</version>' % new_version, package_str
)
if number_of_subs != 1:
raise RuntimeError(
Expand Down

0 comments on commit ecec9fa

Please sign in to comment.