From bbbcc56449574b792ba23f646d152eaca5a3cacd Mon Sep 17 00:00:00 2001 From: Sangwook Ha Date: Thu, 24 Mar 2022 23:47:17 -0700 Subject: [PATCH] Bump pre-commit-hooks to v4.1.0 Update pre-commit-hooks from v2.4.0 to v4.1.0: https://github.com/pre-commit/pre-commit-hooks/releases Since flake8 was removed in v4.0.0: https://github.com/pre-commit/pre-commit-hooks/releases/tag/v4.0.0 https://github.com/pre-commit/pre-commit-hooks/pull/597 replace it with PyCQA/flake8: https://github.com/PyCQA/flake8 https://flake8.pycqa.org/en/latest/release-notes/index.html and address flake8 W605 issues detected by the new flake8: https://www.flake8rules.com/rules/W605.html Change-Id: I148b1b862b192a3e44c9ee90292df7678629d8e0 Signed-off-by: Sangwook Ha --- .pre-commit-config.yaml | 10 ++++++---- csit/libraries/ALTO/AltoParser.py | 4 ++-- csit/libraries/BgpRpcClient.py | 2 +- csit/libraries/SwitchClasses/H3C.py | 2 +- csit/libraries/SwitchClasses/ProVision.py | 2 +- csit/libraries/UtilLibrary.py | 8 ++++---- csit/libraries/backuprestore/jsonpathl.py | 2 +- tools/clustering/cluster-deployer/deploy.py | 10 +++++----- .../clustering-performance-test/inventory_crawler.py | 2 +- 9 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5115ec8fcd..83ee03ff36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,18 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 # Use the ref you want to point at + rev: v4.1.0 # Use the ref you want to point at hooks: - - id: flake8 - language_version: python3 - additional_dependencies: ['flake8~=3.5.0'] - id: trailing-whitespace # this hook will remove any blank lines at the end of a file, whereas the robot hook will add one # so to prevent this conflict we will ignore .robot files in this trailing-whitespace hook exclude: '\.robot' + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + - repo: https://github.com/psf/black rev: 20.8b1 hooks: diff --git a/csit/libraries/ALTO/AltoParser.py b/csit/libraries/ALTO/AltoParser.py index 86e5701af3..539fb82ebb 100644 --- a/csit/libraries/ALTO/AltoParser.py +++ b/csit/libraries/ALTO/AltoParser.py @@ -66,11 +66,11 @@ def check_ird_configuration_entry(response, ird_resource_id, context_id, resourc if "dependency" in tag: for one_dependency in tag["dependency"]: _context_id = re.findall( - "\d{8}-\d{4}-\d{4}-\d{4}-\d{12}", one_dependency + r"\d{8}-\d{4}-\d{4}-\d{4}-\d{12}", one_dependency )[0] if _context_id == context_id: long_resource_id = re.findall( - "resource-id='[a-zA-Z\-]*'", one_dependency + r"resource-id='[a-zA-Z\-]*'", one_dependency )[0] short_resource_id = re.findall("'.*'", long_resource_id)[0] _resource_id = short_resource_id.replace("'", "") diff --git a/csit/libraries/BgpRpcClient.py b/csit/libraries/BgpRpcClient.py index fb2b6fe75f..4a1ba83bd8 100644 --- a/csit/libraries/BgpRpcClient.py +++ b/csit/libraries/BgpRpcClient.py @@ -101,5 +101,5 @@ class BgpRpcClient(object): """Verifies two hex messages are equal even in case, their arguments are misplaced. Converts hex message arguments to integers and sums them up and returns the sum.""" return sum( - [int(x, 16) for x in re.compile("[a-f\d]{2}").findall(hex_string[32:])] + [int(x, 16) for x in re.compile(r"[a-f\d]{2}").findall(hex_string[32:])] ) diff --git a/csit/libraries/SwitchClasses/H3C.py b/csit/libraries/SwitchClasses/H3C.py index 57541d2790..48d6d7ca0d 100644 --- a/csit/libraries/SwitchClasses/H3C.py +++ b/csit/libraries/SwitchClasses/H3C.py @@ -113,7 +113,7 @@ class H3C(BaseSwitch): # |---------------------------------(0)---------------------------------| # |------(1)-------||------(2)-----| matches = re.search( - "(.*0x)(\w+) +Connected", self.datapath_id_output_string + r"(.*0x)(\w+) +Connected", self.datapath_id_output_string ) datapath_id_hex = matches.group(2) self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex) diff --git a/csit/libraries/SwitchClasses/ProVision.py b/csit/libraries/SwitchClasses/ProVision.py index 45055573c0..454d3d3a75 100644 --- a/csit/libraries/SwitchClasses/ProVision.py +++ b/csit/libraries/SwitchClasses/ProVision.py @@ -155,6 +155,6 @@ class ProVision(BaseSwitch): # Datapath ID : 000af0921c22bac0 # |-----------------(0)---------------------| # |-----------(1)----------| |------(2)-----| - matches = re.search("(.*: )(\w+)", self.datapath_id_output_string) + matches = re.search(r"(.*: )(\w+)", self.datapath_id_output_string) datapath_id_hex = matches.group(2) self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex) diff --git a/csit/libraries/UtilLibrary.py b/csit/libraries/UtilLibrary.py index d567b08130..6f65fd2061 100644 --- a/csit/libraries/UtilLibrary.py +++ b/csit/libraries/UtilLibrary.py @@ -264,13 +264,13 @@ def isolate_controller(controllers, username, password, isolated): iso_result = "pass" for controller in controllers: controller_regex_string = ( - "[\s\S]*" + isolated_controller + " *" + controller + "[\s\S]*" + r"[\s\S]*" + isolated_controller + " *" + controller + r"[\s\S]*" ) controller_regex = re.compile(controller_regex_string) if not controller_regex.match(ip_tables): iso_result = ip_tables controller_regex_string = ( - "[\s\S]*" + controller + " *" + isolated_controller + "[\s\S]*" + r"[\s\S]*" + controller + " *" + isolated_controller + r"[\s\S]*" ) controller_regex = re.compile(controller_regex_string) if not controller_regex.match(ip_tables): @@ -314,13 +314,13 @@ def rejoin_controller(controllers, username, password, isolated): iso_result = "pass" for controller in controllers: controller_regex_string = ( - "[\s\S]*" + isolated_controller + " *" + controller + "[\s\S]*" + r"[\s\S]*" + isolated_controller + " *" + controller + r"[\s\S]*" ) controller_regex = re.compile(controller_regex_string) if controller_regex.match(ip_tables): iso_result = ip_tables controller_regex_string = ( - "[\s\S]*" + controller + " *" + isolated_controller + "[\s\S]*" + r"[\s\S]*" + controller + " *" + isolated_controller + r"[\s\S]*" ) controller_regex = re.compile(controller_regex_string) if controller_regex.match(ip_tables): diff --git a/csit/libraries/backuprestore/jsonpathl.py b/csit/libraries/backuprestore/jsonpathl.py index 302c193643..e5953f18e6 100644 --- a/csit/libraries/backuprestore/jsonpathl.py +++ b/csit/libraries/backuprestore/jsonpathl.py @@ -271,7 +271,7 @@ def jsonpath(obj, expr, result_type="VALUE", debug=0, use_eval=True): def notvar(m): return "'%s' not in __obj" % m.group(1) - loc = re.sub("!@\.([a-zA-Z@_]+)", notvar, loc) + loc = re.sub(r"!@\.([a-zA-Z@_]+)", notvar, loc) # replace @.name.... with __obj['name'].... # handle @.name[.name...].length diff --git a/tools/clustering/cluster-deployer/deploy.py b/tools/clustering/cluster-deployer/deploy.py index 62cb38ab42..ed14b00179 100755 --- a/tools/clustering/cluster-deployer/deploy.py +++ b/tools/clustering/cluster-deployer/deploy.py @@ -181,11 +181,11 @@ class Deployer: # Determine distribution version distribution_name = os.path.splitext(os.path.basename(self.distribution))[0] distribution_ver = re.search( - "(\d+\.\d+\.\d+-\w+\Z)|" - "(\d+\.\d+\.\d+-\w+)(-RC\d+\Z)|" - "(\d+\.\d+\.\d+-\w+)(-RC\d+(\.\d+)\Z)|" - "(\d+\.\d+\.\d+-\w+)(-SR\d+\Z)|" - "(\d+\.\d+\.\d+-\w+)(-SR\d+(\.\d+)\Z)", + r"(\d+\.\d+\.\d+-\w+\Z)|" + r"(\d+\.\d+\.\d+-\w+)(-RC\d+\Z)|" + r"(\d+\.\d+\.\d+-\w+)(-RC\d+(\.\d+)\Z)|" + r"(\d+\.\d+\.\d+-\w+)(-SR\d+\Z)|" + r"(\d+\.\d+\.\d+-\w+)(-SR\d+(\.\d+)\Z)", distribution_name, ) # noqa diff --git a/tools/odl-mdsal-clustering-tests/clustering-performance-test/inventory_crawler.py b/tools/odl-mdsal-clustering-tests/clustering-performance-test/inventory_crawler.py index 596125e3f6..cb91908d29 100755 --- a/tools/odl-mdsal-clustering-tests/clustering-performance-test/inventory_crawler.py +++ b/tools/odl-mdsal-clustering-tests/clustering-performance-test/inventory_crawler.py @@ -130,7 +130,7 @@ class InventoryCrawler(object): if re.search("openflow", inv[n]["id"]) is not None: sinv.append(inv[n]) - sinv = sorted(sinv, key=lambda k: int(re.findall("\d+", k["id"])[0])) + sinv = sorted(sinv, key=lambda k: int(re.findall(r"\d+", k["id"])[0])) for n in range(len(sinv)): try: -- 2.36.6