Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raw strings for regex patterns #473

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/tito/builder/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def fetch(self):
self.sources.append(dest_filepath)

# Add a line to replace in the spec for each source:
source_regex = re.compile("^(source%s:\s*)(.+)$" % i, re.IGNORECASE)
source_regex = re.compile(r"^(source%s:\s*)(.+)$" % i, re.IGNORECASE)
new_line = "Source%s: %s\n" % (i, base_name)
replacements.append((source_regex, new_line))

# Replace version and release in spec:
version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE)
release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE)
version_regex = re.compile(r"^(version:\s*)(.+)$", re.IGNORECASE)
release_regex = re.compile(r"^(release:\s*)(.+)$", re.IGNORECASE)

(self.version, self.release) = self._get_version_and_release()
print("Building version: %s" % self.version)
Expand All @@ -180,7 +180,7 @@ def _get_version_and_release(self):
release = "1%{?dist}"

# Example filename: tito-0.4.18.tar.gz:
simple_version_re = re.compile(".*-(.*).(tar.gz|tgz|zip|bz2)")
simple_version_re = re.compile(r".*-(.*).(tar.gz|tgz|zip|bz2)")
match = re.search(simple_version_re, base_name)
if match:
version = match.group(1)
Expand Down
4 changes: 2 additions & 2 deletions src/tito/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def extract_sources(spec_file_lines):
location as the spec file, mostly used with NoTgzBuilder packages.
"""
filenames = []
source_pattern = re.compile('^Source\d+?:\s*(.*)')
source_pattern = re.compile(r'^Source\d+?:\s*(.*)')
for line in spec_file_lines:
match = source_pattern.match(line)
if match:
Expand Down Expand Up @@ -729,7 +729,7 @@ def replace_version(line, new_version):
whitespace, and optional use of single/double quotes.
"""
# Mmmmm pretty regex!
ver_regex = re.compile("(\s*)(version)(\s*)(=)(\s*)(['\"])(.*)(['\"])(.*)",
ver_regex = re.compile(r"(\s*)(version)(\s*)(=)(\s*)(['\"])(.*)(['\"])(.*)",
re.IGNORECASE)
m = ver_regex.match(line)
if m:
Expand Down
6 changes: 3 additions & 3 deletions src/tito/tagger/cargobump.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def tag_new_version(project_path, new_version_release):
@staticmethod
def process_cargo_toml(input_string, new_version):
file_buffer = []
pkg_label = re.compile('^\[package\]$')
label = re.compile('^\[.*\]$')
version = re.compile('(^version\s*=\s*)["\'](.+)["\'](.*$)')
pkg_label = re.compile(r'^\[package\]$')
label = re.compile(r'^\[.*\]$')
version = re.compile(r'(^version\s*=\s*)["\'](.+)["\'](.*$)')
lines = [line.rstrip('\n') for line in input_string]
state = 1
for line in lines:
Expand Down
10 changes: 5 additions & 5 deletions src/tito/tagger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __init__(self, config=None, keep_version=False, offline=False, user_config=N
git_email = self.git_email
if git_email is None:
git_email = ''
self.changelog_regex = re.compile('\\*\s%s\s%s(\s<%s>)?' % (self.today,
self.git_user, git_email.replace("+", "\+").replace(".", "\.")))
self.changelog_regex = re.compile(r'\\*\s{0}\s{1}(\s<{2}>)?'.format(self.today,
self.git_user, git_email))
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks equal to me but I should probably write some tests to be sure.


self._no_auto_changelog = False
self._accept_auto_changelog = False
Expand Down Expand Up @@ -178,7 +178,7 @@ def _changelog_remove_cherrypick(self, line):
if not (self.config.has_option(BUILDCONFIG_SECTION, "changelog_do_not_remove_cherrypick")
and self.config.get(BUILDCONFIG_SECTION, "changelog_do_not_remove_cherrypick")
and self.config.get(BUILDCONFIG_SECTION, "changelog_do_not_remove_cherrypick").strip() != '0'):
m = re.match("(.+)(\(cherry picked from .*\))", line)
m = re.match(r"(.+)(\(cherry picked from .*\))", line)
if m:
line = m.group(1)
return line
Expand Down Expand Up @@ -394,8 +394,8 @@ def _bump_version(self, release=False, zstream=False):
if old_version is None:
old_version = "untagged"
if not self.keep_version:
version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE)
release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE)
version_regex = re.compile(r"^(version:\s*)(.+)$", re.IGNORECASE)
release_regex = re.compile(r"^(release:\s*)(.+)$", re.IGNORECASE)

in_f = open(self.spec_file, 'r')
out_f = open(self.spec_file + ".new", 'w')
Expand Down
2 changes: 1 addition & 1 deletion src/tito/tagger/rheltagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _generate_default_changelog(self, last_tag):
line = line.replace('%', '%%')

# prepend Related/Resolves if subject contains BZ number
m = re.match("(\d+)\s+-\s+(.*)", line)
m = re.match(r"(\d+)\s+-\s+(.*)", line)
if m:
bz_number = m.group(1)
if bz_number in BZ:
Expand Down
6 changes: 3 additions & 3 deletions src/tito/tagger/susetagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def __init__(self, config=None, keep_version=False, offline=False, user_config=N
self.changes_file = os.path.join(self.full_project_dir,
self.changes_file_name)
self._new_changelog_msg = "Initial package release"
self.changelog_regex = re.compile('^\s%s\s%s(\s<%s>)?' % (self.today,
self.git_user, self.git_email.replace("+", "\+").replace(".", "\.")))
self.changelog_regex = re.compile(r'^\s{0}\s{1}(\s<{2}>)?'.format(self.today,
self.git_user, self.git_email))

def _make_changelog(self):
"""
Expand Down Expand Up @@ -135,7 +135,7 @@ def _update_changelog(self, new_version):
buf = StringIO()
found_match = False
done = False
empty_line_regex = re.compile('^\s*$')
empty_line_regex = re.compile(r'^\s*$')

for line in f.readlines():
if not done and not found_match and self.changelog_regex.match(line):
Expand Down
2 changes: 1 addition & 1 deletion src/tito/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def encode_header(self, chunk_props, encode_order=None):
if member in self.octal_members:
# Pad out the octal value to the right length
member_template = self.struct_hash[member]
field_size = int(re.match('(\d+)', member_template).group(1)) - 1
field_size = int(re.match(r'(\d+)', member_template).group(1)) - 1
fmt = "%0" + str(field_size) + "o\x00"
as_string = fmt % chunk_props[member]
pack_values.append(tito.compat.ensure_binary(as_string))
Expand Down