Skip to content

Commit

Permalink
Refactor: Resolve W605 Invalid escape sequence
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: Ic2a51f089ef9d6fc45a3db5e96a8f5196d59f02c
  • Loading branch information
zxiiro committed Oct 5, 2021
1 parent 8c6774a commit 3d18b95
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lftools/cli/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lftools/cli/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions lftools/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lftools/nexus/release_docker_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
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):
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(self, org_name, repo_name, repo_from_file):
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+$"
Expand Down
4 changes: 2 additions & 2 deletions lftools/nexus/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"[/\.]")
6 changes: 3 additions & 3 deletions tests/test_release_docker_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_tag_class_manual_version_regexp_str_valid_tags(self):
"""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)
Expand All @@ -183,7 +183,7 @@ def test_tag_class_manual_version_regexp_str_invalid_tags(self):
"""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",
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_tag_class_manual_version_regexp_str_from_file_valid(self, datafiles):
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"
Expand Down

0 comments on commit 3d18b95

Please sign in to comment.