From 3d18b950e0597a11f27059f5268dc605c0e089bd Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Tue, 5 Oct 2021 12:27:09 -0400 Subject: [PATCH] Refactor: Resolve W605 Invalid escape sequence W605 is deprecated and will become a syntax error in Python 3.8 (https://www.flake8rules.com/rules/W605.html). Signed-off-by: Thanh Ha Change-Id: Ic2a51f089ef9d6fc45a3db5e96a8f5196d59f02c --- lftools/cli/license.py | 2 +- lftools/cli/nexus.py | 2 +- lftools/license.py | 4 ++-- lftools/nexus/release_docker_hub.py | 4 ++-- lftools/nexus/util.py | 4 ++-- tests/test_release_docker_hub.py | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lftools/cli/license.py b/lftools/cli/license.py index 04ea33f3..3257bd79 100644 --- a/lftools/cli/license.py +++ b/lftools/cli/license.py @@ -45,7 +45,7 @@ def check(ctx, license, source): @click.command(name="check-dir") @click.argument("directory") @click.option("-l", "--license", default="license-header.txt", help="License header file to compare against.") -@click.option("-r", "--regex", default=".+\.py$", help="File regex pattern to match on when searching.") +@click.option("-r", "--regex", default=r".+\.py$", help="File regex pattern to match on when searching.") @click.pass_context def check_directory(ctx, license, directory, regex): """Check directory for files missing license headers. diff --git a/lftools/cli/nexus.py b/lftools/cli/nexus.py index 4702ec46..b0f96924 100644 --- a/lftools/cli/nexus.py +++ b/lftools/cli/nexus.py @@ -224,7 +224,7 @@ def release(ctx, repos, verify, server): required=False, help="Specify a file which contains a regexp expression to validate version number." " File sample: " - " ^\d+.\d+.\d+$ ", + r" ^\d+.\d+.\d+$ ", ) @click.pass_context def copy_from_nexus3_to_dockerhub(ctx, org, repo, exact, summary, verbose, copy, progbar, repofile, version_regexp): diff --git a/lftools/license.py b/lftools/license.py index 1366d317..d9c4d48f 100644 --- a/lftools/license.py +++ b/lftools/license.py @@ -43,7 +43,7 @@ def get_header_text(_file): continue text += " {}".format(string) # Strip unnecessary spacing - text = re.sub("\s+", " ", text).strip() + text = re.sub(r"\s+", " ", text).strip() return text @@ -63,7 +63,7 @@ def check_license(license_file, code_file): return 0 -def check_license_directory(license_file, directory, regex=".+\.py$"): +def check_license_directory(license_file, directory, regex=r".+\.py$"): """Search a directory for files and calls check_license().""" missing_license = False diff --git a/lftools/nexus/release_docker_hub.py b/lftools/nexus/release_docker_hub.py index 6515d3e6..53d50963 100644 --- a/lftools/nexus/release_docker_hub.py +++ b/lftools/nexus/release_docker_hub.py @@ -63,7 +63,7 @@ NEXUS3_CATALOG = "" NEXUS3_PROJ_NAME_HEADER = "" DOCKER_PROJ_NAME_HEADER = "" VERSION_REGEXP = "" -DEFAULT_REGEXP = "^\d+.\d+.\d+$" +DEFAULT_REGEXP = r"^\d+.\d+.\d+$" def _remove_http_from_url(url): @@ -171,7 +171,7 @@ class TagClass: self.repofromfile = repo_from_file def _validate_tag(self, check_tag): - """Local helper function to simplify validity check of version number. + r"""Local helper function to simplify validity check of version number. Returns true or false, depending if the version pattern is a valid one. Valid pattern is #.#.#, or in computer term "^\d+.\d+.\d+$" diff --git a/lftools/nexus/util.py b/lftools/nexus/util.py index 21d57d09..f8828071 100644 --- a/lftools/nexus/util.py +++ b/lftools/nexus/util.py @@ -26,9 +26,9 @@ def create_repo_target_regex(group_id, strict=True): Strict = True : --> "/org/o-ran-sc/org/" """ - repotarget = "^/{}/.*".format(group_id.replace(".", "[/\.]")) + repotarget = "^/{}/.*".format(group_id.replace(".", r"[/\.]")) if strict: return repotarget else: # Replace - with regex - return repotarget.replace("-", "[/\.]") + return repotarget.replace("-", r"[/\.]") diff --git a/tests/test_release_docker_hub.py b/tests/test_release_docker_hub.py index 63dcae35..f86bae21 100644 --- a/tests/test_release_docker_hub.py +++ b/tests/test_release_docker_hub.py @@ -169,7 +169,7 @@ class TestTagsRegExpClass: """Test TagClass""" org = "onap" repo = "base/sdc-sanity" - test_regexp = "^v\d+.\d+.\d+$" + test_regexp = r"^v\d+.\d+.\d+$" repo_from_file = False test_tags = ["v1.2.3", "v1.22.333", "v111.22.3", "v10.11.12", "v1.0.3"] rdh.initialize(org, test_regexp) @@ -183,7 +183,7 @@ class TestTagsRegExpClass: """Test TagClass""" org = "onap" repo = "base/sdc-sanity" - test_regexp = "v^\d+.\d+.\d+$" + test_regexp = r"v^\d+.\d+.\d+$" repo_from_file = False test_tags = [ "1.2.3", @@ -214,7 +214,7 @@ class TestTagsRegExpClass: test_regexp_from_file = os.path.join(str(datafiles), "releasedockerhub_good_regexp") rdh.initialize(org, test_regexp_from_file) assert rdh.validate_regexp() == True - assert rdh.VERSION_REGEXP == "^\d+.\d+" + assert rdh.VERSION_REGEXP == r"^\d+.\d+" def test_tag_class_manual_version_regexp_str_from_file_invalid(self, datafiles): org = "onap" -- 2.16.6