Skip to content

Commit 9c496b3

Browse files
eng, automation, use raw string on regex pattern (Azure#45211)
1 parent 26b8ea0 commit 9c496b3

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

eng/automation/generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def main():
437437

438438
readme = args["readme"]
439439
match = re.match(
440-
"specification/([^/]+)/resource-manager(/.*)*/readme.md",
440+
r"specification/([^/]+)/resource-manager(/.*)*/readme.md",
441441
readme,
442442
re.IGNORECASE,
443443
)

eng/automation/generate_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def generate_changelog_and_breaking_change(
158158

159159

160160
def update_changelog(changelog_file, changelog):
161-
version_pattern = "^## (\d+\.\d+\.\d+(?:-[\w\d\.]+)?) \((.*?)\)"
161+
version_pattern = r"^## (\d+\.\d+\.\d+(?:-[\w\d\.]+)?) \((.*?)\)"
162162
with open(changelog_file, "r") as fin:
163163
old_changelog = fin.read()
164164

@@ -175,8 +175,8 @@ def update_changelog(changelog_file, changelog):
175175

176176
first_version_part = old_changelog[: first_version.end() + second_version.start()]
177177
# remove text starting from the first '###' (usually the block '### Features Added')
178-
first_version_part = re.sub("\n###.*", "\n", first_version_part, flags=re.S)
179-
first_version_part = re.sub("\s+$", "", first_version_part)
178+
first_version_part = re.sub(r"\n###.*", "\n", first_version_part, flags=re.S)
179+
first_version_part = re.sub(r"\s+$", "", first_version_part)
180180

181181
first_version_part += "\n\n"
182182
if changelog.strip() != "":
@@ -252,7 +252,7 @@ def get_version(
252252

253253

254254
def valid_service(service: str):
255-
return re.sub("[^a-z0-9_]", "", service.lower())
255+
return re.sub(r"[^a-z0-9_]", "", service.lower())
256256

257257

258258
def read_api_specs(api_specs_file: str) -> Tuple[str, dict]:

eng/automation/install_instruction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def main():
2525

2626
for artifact in config.get("artifacts", []):
2727
logging.debug("Got artifact: {0}".format(artifact))
28-
if re.match("{0}-\d+\.\d+\.\d+(-beta\.\d+)?\.jar".format(artifact_id), artifact):
28+
if re.match(r"{0}-\d+\.\d+\.\d+(-beta\.\d+)?\.jar".format(artifact_id), artifact):
2929
logging.debug("Match jar package: {0}".format(artifact))
3030
download_url = config.get("downloadUrlPrefix", "") + artifact
3131
with open(sys.argv[2], "w") as fout:

eng/automation/sdk_generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def main():
252252

253253
readme = args["readme"]
254254
match = re.match(
255-
"specification/([^/]+)/resource-manager/readme.md",
255+
r"specification/([^/]+)/resource-manager/readme.md",
256256
readme,
257257
re.IGNORECASE,
258258
)

eng/automation/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add_module_to_default_profile(pom: str, module: str) -> Tuple[bool, str]:
4141
for profile in re.finditer(r"<profile>[\s\S]*?</profile>", pom):
4242
profile_value = profile.group()
4343
if re.search(r"<id>default</id>", profile_value):
44-
if len(re.findall("<modules>", profile_value)) > 1:
44+
if len(re.findall(r"<modules>", profile_value)) > 1:
4545
logging.error("[POM][Profile][Skip] find more than one <modules> in <profile> default")
4646
return (False, "")
4747
modules = re.search(r"<modules>[\s\S]*</modules>", profile_value)
@@ -61,7 +61,7 @@ def add_module_to_pom(pom: str, module: str) -> Tuple[bool, str]:
6161
logging.info("[POM][Skip] pom already has module {0}".format(module))
6262
return (True, pom)
6363

64-
if len(re.findall("<modules>", pom)) > 1:
64+
if len(re.findall(r"<modules>", pom)) > 1:
6565
if pom.find("<profiles>") >= 0:
6666
return add_module_to_default_profile(pom, module)
6767
logging.error("[POM][Skip] find more than one <modules> in pom")
@@ -164,7 +164,7 @@ def update_service_files_for_new_lib(sdk_root: str, service: str, group: str, mo
164164
)
165165

166166
ci_yml_str = yaml.dump(ci_yml, width=sys.maxsize, sort_keys=False, Dumper=ListIndentDumper)
167-
ci_yml_str = re.sub("(\n\S)", r"\n\1", ci_yml_str)
167+
ci_yml_str = re.sub(r"(\n\S)", r"\n\1", ci_yml_str)
168168

169169
with open(ci_yml_file, "w") as fout:
170170
fout.write(CI_HEADER)
@@ -310,7 +310,7 @@ def set_or_increase_version(
310310
) -> Tuple[str, str]:
311311
version_file = os.path.join(sdk_root, "eng/versioning/version_client.txt")
312312
project = "{0}:{1}".format(group, module)
313-
version_pattern = "(\d+)\.(\d+)\.(\d+)(-beta\.\d+)?"
313+
version_pattern = r"(\d+)\.(\d+)\.(\d+)(-beta\.\d+)?"
314314
version_format = "{0}.{1}.{2}{3}"
315315
default_version = version if version else DEFAULT_VERSION
316316

0 commit comments

Comments
 (0)