Refactor: Resolve W605 Invalid escape sequence 37/68937/2
authorThanh Ha <zxiiro@gmail.com>
Tue, 5 Oct 2021 16:27:09 +0000 (12:27 -0400)
committerThanh Ha <zxiiro@gmail.com>
Tue, 5 Oct 2021 19:18:32 +0000 (15:18 -0400)
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 <zxiiro@gmail.com>
Change-Id: Ic2a51f089ef9d6fc45a3db5e96a8f5196d59f02c

lftools/cli/license.py
lftools/cli/nexus.py
lftools/license.py
lftools/nexus/release_docker_hub.py
lftools/nexus/util.py
tests/test_release_docker_hub.py

index 04ea33f..3257bd7 100644 (file)
@@ -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.
index 4702ec4..b0f9692 100644 (file)
@@ -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):
index 1366d31..d9c4d48 100644 (file)
@@ -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
 
index 6515d3e..53d5096 100644 (file)
@@ -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+$"
index 21d57d0..f882807 100644 (file)
@@ -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"[/\.]")
index 63dcae3..f86bae2 100644 (file)
@@ -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"