SeanNaren / warp-ctc

Pytorch Bindings for warp-ctc
Apache License 2.0
756 stars 271 forks source link

Use pytest-flake8 or pytest-flakes instead of pytest-pep8 #175

Closed ysk24ok closed 3 years ago

ysk24ok commented 3 years ago

pytest --pep8 fails because pytest>=5.4 makes direct Node construction deprecated (see here).

[root@210afe0473c1 pytorch_binding]# pytest --pep8
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
======================================== test session starts =========================================
platform linux -- Python 3.7.4, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /hdd/nishioka/warp-ctc/pytorch_binding, configfile: setup.cfg
plugins: pep8-1.0.6, flake8-1.0.6, flakes-4.0.1
collected 0 items / 1 error

=============================================== ERRORS ===============================================
___________________________________ ERROR collecting test session ____________________________________
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pluggy/manager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pytest_pep8.py:38: in pytest_collect_file
    return Pep8Item(path, parent, pep8ignore, config._max_line_length)
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/_pytest/nodes.py:95: in __call__
    warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=2)
E   pytest.PytestDeprecationWarning: Direct construction of Pep8Item has been deprecated, please use Pep8Item.from_parent.
E   See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.
====================================== short test summary info =======================================
ERROR  - pytest.PytestDeprecationWarning: Direct construction of Pep8Item has been deprecated, plea...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================== 1 error in 0.07s ==========================================

Why not using pytest-flake8 or pytest-flakes instead of pytest-pep8 ? It seems pytest-pep8 is no longer maintained, the latest release is in 2014! https://pypi.org/project/pytest-pep8/

pytest-flake8 is a little strict about code length.

[root@210afe0473c1 pytorch_binding]# pytest --flake8
[root@210afe0473c1 pytorch_binding]# pytest --flake8
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
======================================== test session starts =========================================
platform linux -- Python 3.7.4, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /hdd/nishioka/warp-ctc/pytorch_binding, configfile: setup.cfg
plugins: pep8-1.0.6, flake8-1.0.6, flakes-4.0.1
collected 12 items

setup.py F                                                                                     [  8%]
tests/test_cpu.py F....                                                                        [ 50%]
tests/test_gpu.py F....                                                                        [ 91%]
warpctc_pytorch/__init__.py F                                                                  [100%]

============================================== FAILURES ==============================================
____________________________________________ FLAKE8-check ____________________________________________
/hdd/nishioka/warp-ctc/pytorch_binding/setup.py:30:80: E501 line too long (89 > 79 characters)
/hdd/nishioka/warp-ctc/pytorch_binding/setup.py:60:80: E501 line too long (81 > 79 characters)

----------------------------------------- Captured log call ------------------------------------------
WARNING  flake8.options.manager:manager.py:211 option --max-complexity: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
____________________________________________ FLAKE8-check ____________________________________________
/hdd/nishioka/warp-ctc/pytorch_binding/tests/test_cpu.py:7:80: E501 line too long (116 > 79 characters)

----------------------------------------- Captured log call ------------------------------------------
WARNING  flake8.options.manager:manager.py:211 option --max-complexity: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
____________________________________________ FLAKE8-check ____________________________________________
/hdd/nishioka/warp-ctc/pytorch_binding/tests/test_gpu.py:8:80: E501 line too long (116 > 79 characters)

----------------------------------------- Captured log call ------------------------------------------
WARNING  flake8.options.manager:manager.py:211 option --max-complexity: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
____________________________________________ FLAKE8-check ____________________________________________
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:6:1: F403 'from ._warp_ctc import *' used; unable to detect undefined names
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:6:1: F401 '._warp_ctc.*' imported but unused
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:54:1: E302 expected 2 blank lines, found 1
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:72:80: E501 line too long (86 > 79 characters)
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:73:80: E501 line too long (92 > 79 characters)
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:74:80: E501 line too long (97 > 79 characters)

----------------------------------------- Captured log call ------------------------------------------
WARNING  flake8.options.manager:manager.py:211 option --max-complexity: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
====================================== short test summary info =======================================
FAILED setup.py::FLAKE8
FAILED tests/test_cpu.py::FLAKE8
FAILED tests/test_gpu.py::FLAKE8
FAILED warpctc_pytorch/__init__.py::FLAKE8
==================================== 4 failed, 8 passed in 2.39s =====================================

Just adding #noqa to from ._warp_ctc import * make it work.

[root@210afe0473c1 pytorch_binding]# pytest --flakes
/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
======================================== test session starts =========================================
platform linux -- Python 3.7.4, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /hdd/nishioka/warp-ctc/pytorch_binding, configfile: setup.cfg
plugins: pep8-1.0.6, flake8-1.0.6, flakes-4.0.1
collected 12 items

setup.py .                                                                                     [  8%]
tests/test_cpu.py s....                                                                        [ 50%]
tests/test_gpu.py s....                                                                        [ 91%]
warpctc_pytorch/__init__.py F                                                                  [100%]

============================================== FAILURES ==============================================
___________________________________________ pyflakes-check ___________________________________________
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:6: ImportStarUsed
'from ._warp_ctc import *' used; unable to detect undefined names
/hdd/nishioka/warp-ctc/pytorch_binding/warpctc_pytorch/__init__.py:6: UnusedImport
'._warp_ctc.*' imported but unused
====================================== short test summary info =======================================
FAILED warpctc_pytorch/__init__.py
=============================== 1 failed, 9 passed, 2 skipped in 2.24s ===============================

Which one do you prefer? If you tell me, I'm going to create a PR later.

SeanNaren commented 3 years ago

Thansk @ysk24ok, seems like the pytest-flakes option is the easiest to get the tests passing, more than happy to accept a PR with this :)