Skip to content

Commit

Permalink
Merge pull request #4634 from Flamefire/pep8
Browse files Browse the repository at this point in the history
Drop support for pep8 package
  • Loading branch information
bartoldeman authored Sep 17, 2024
2 parents c4f66c0 + 731915a commit 7d93348
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 48 deletions.
18 changes: 4 additions & 14 deletions easybuild/framework/easyconfig/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Ward Poelmans (Ghent University)
"""
import re
import sys
from importlib import reload

from easybuild.base import fancylogger
Expand All @@ -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)

Expand Down Expand Up @@ -106,20 +100,15 @@ 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
:param easyconfigs: list of file paths to easyconfigs
: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.
Expand All @@ -137,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)

Expand Down
1 change: 0 additions & 1 deletion easybuild/tools/systemtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 7 additions & 11 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down
20 changes: 6 additions & 14 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
13 changes: 5 additions & 8 deletions test/framework/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,16 @@
try:
import pycodestyle # noqa
except ImportError:
try:
import pep8 # noqa
except ImportError:
pass
pass


class StyleTest(EnhancedTestCase):
log = fancylogger.getLogger("StyleTest", fname=False)

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
Expand All @@ -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 = [
Expand Down

0 comments on commit 7d93348

Please sign in to comment.