From daa7b6b2b43dd8c208b87799d45d8a93bfc4dee2 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 13 Sep 2024 15:28:45 +0200 Subject: [PATCH 1/2] Drop support for pep8 package It is outdated for many years now and has been replaced by pycodestyle. Stop using it. --- easybuild/framework/easyconfig/style.py | 17 +++-------------- easybuild/tools/systemtools.py | 1 - test/framework/easyconfig.py | 18 +++++++----------- test/framework/options.py | 20 ++++++-------------- test/framework/style.py | 13 +++++-------- 5 files changed, 21 insertions(+), 48 deletions(-) diff --git a/easybuild/framework/easyconfig/style.py b/easybuild/framework/easyconfig/style.py index 28110ca1a4..caf5f10a4c 100644 --- a/easybuild/framework/easyconfig/style.py +++ b/easybuild/framework/easyconfig/style.py @@ -31,7 +31,6 @@ * Ward Poelmans (Ghent University) """ import re -import sys from importlib import reload from easybuild.base import fancylogger @@ -43,12 +42,7 @@ import pycodestyle from pycodestyle import StyleGuide, register_check, trailing_whitespace except ImportError: - try: - # fallback to importing from 'pep8', which was renamed to pycodestyle in 2016 - import pep8 - from pep8 import StyleGuide, register_check, trailing_whitespace - except ImportError: - pass + pass _log = fancylogger.getLogger('easyconfig.style', fname=False) @@ -106,7 +100,7 @@ def _eb_check_trailing_whitespace(physical_line, lines, line_number, checker_sta return result -@only_if_module_is_available(('pycodestyle', 'pep8')) +@only_if_module_is_available('pycodestyle') def check_easyconfigs_style(easyconfigs, verbose=False): """ Check the given list of easyconfigs for style @@ -114,12 +108,7 @@ def check_easyconfigs_style(easyconfigs, verbose=False): :param verbose: print our statistics and be verbose about the errors and warning :return: the number of warnings and errors """ - # importing autopep8 changes some pep8 functions. - # We reload it to be sure to get the real pep8 functions. - if 'pycodestyle' in sys.modules: - reload(pycodestyle) - else: - reload(pep8) + reload(pycodestyle) # register the extra checks before using pep8: # any function in this module starting with `_eb_check_` will be used. diff --git a/easybuild/tools/systemtools.py b/easybuild/tools/systemtools.py index 2fdd9c4ba8..b48f76ad3c 100644 --- a/easybuild/tools/systemtools.py +++ b/easybuild/tools/systemtools.py @@ -202,7 +202,6 @@ 'graphviz-python': ('gv', "rendering dependency graph with Graphviz: --dep-graph"), 'keyring': (None, "storing GitHub token"), 'pbs-python': ('pbs', "using Torque as --job backend"), - 'pep8': (None, "fallback for code style checking: --check-style, --check-contrib"), 'pycodestyle': (None, "code style checking: --check-style, --check-contrib"), 'pysvn': (None, "using SVN repository as easyconfigs archive"), 'python-graph-core': ('pygraph.classes.digraph', "creating dependency graph: --dep-graph"), diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index f50985f609..827e01f1e0 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -85,11 +85,7 @@ try: import pycodestyle # noqa except ImportError: - try: - import pep8 # noqa - except ImportError: - pass - + pass EXPECTED_DOTTXT_TOY_DEPS = """digraph graphname { toy; @@ -2660,8 +2656,8 @@ def test_dump_autopep8(self): def test_dump_extra(self): """Test EasyConfig's dump() method for files containing extra values""" - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping test_dump_extra (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_dump_extra pycodestyle is not available") return rawtxt = '\n'.join([ @@ -2703,8 +2699,8 @@ def test_dump_extra(self): def test_dump_template(self): """ Test EasyConfig's dump() method for files containing templates""" - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping test_dump_template (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_dump_template pycodestyle is not available") return rawtxt = '\n'.join([ @@ -2792,8 +2788,8 @@ def test_dump_template(self): def test_dump_comments(self): """ Test dump() method for files containing comments """ - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping test_dump_comments (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_dump_comments pycodestyle is not available") return rawtxt = '\n'.join([ diff --git a/test/framework/options.py b/test/framework/options.py index 2de7f41d33..f10d01cf8d 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -72,10 +72,7 @@ try: import pycodestyle # noqa except ImportError: - try: - import pep8 # noqa - except ImportError: - pass + pass EXTERNAL_MODULES_METADATA = """[foobar/1.2.3] @@ -5893,14 +5890,9 @@ def test_parse_optarch(self): def test_check_contrib_style(self): """Test style checks performed by --check-contrib + dedicated --check-style option.""" - try: - import pycodestyle # noqa - except ImportError: - try: - import pep8 # noqa - except ImportError: - print("Skipping test_check_contrib_style, since pycodestyle or pep8 is not available") - return + if 'pycodestyle' not in sys.modules: + print("Skipping test_check_contrib_style pycodestyle is not available") + return regex = re.compile(r"Running style check on 2 easyconfig\(s\)(.|\n)*>> All style checks PASSed!", re.M) args = [ @@ -5953,8 +5945,8 @@ def test_check_contrib_style(self): def test_check_contrib_non_style(self): """Test non-style checks performed by --check-contrib.""" - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping test_check_contrib_non_style (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_check_contrib_non_style pycodestyle is not available") return args = [ diff --git a/test/framework/style.py b/test/framework/style.py index bfdf4e026a..0c3060b4cb 100644 --- a/test/framework/style.py +++ b/test/framework/style.py @@ -40,10 +40,7 @@ try: import pycodestyle # noqa except ImportError: - try: - import pep8 # noqa - except ImportError: - pass + pass class StyleTest(EnhancedTestCase): @@ -51,8 +48,8 @@ class StyleTest(EnhancedTestCase): def test_style_conformance(self): """Check the easyconfigs for style""" - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping style checks (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_style_conformance pycodestyle is not available") return # all available easyconfig files @@ -66,8 +63,8 @@ def test_style_conformance(self): def test_check_trailing_whitespace(self): """Test for trailing whitespace check.""" - if not ('pycodestyle' in sys.modules or 'pep8' in sys.modules): - print("Skipping trailing whitespace checks (no pycodestyle or pep8 available)") + if 'pycodestyle' not in sys.modules: + print("Skipping test_check_trailing_whitespace is not available") return lines = [ From 731915ac4819dfa50c75fa824467ed741db2bafb Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 13 Sep 2024 16:50:59 +0200 Subject: [PATCH 2/2] Ignore "ambiguous variable name" warning for EasyConfig style check --- easybuild/framework/easyconfig/style.py | 1 + 1 file changed, 1 insertion(+) diff --git a/easybuild/framework/easyconfig/style.py b/easybuild/framework/easyconfig/style.py index caf5f10a4c..9e264d4f3d 100644 --- a/easybuild/framework/easyconfig/style.py +++ b/easybuild/framework/easyconfig/style.py @@ -126,6 +126,7 @@ def check_easyconfigs_style(easyconfigs, verbose=False): # note that W291 has been replaced by our custom W299 options.ignore = ( 'W291', # replaced by W299 + 'E741', # 'l' is considered an ambiguous name, but we use it often for 'lib' ) options.verbose = int(verbose)