Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for pycodestyle #319

Closed
ssbarnea opened this issue Oct 7, 2018 · 25 comments
Closed

No support for pycodestyle #319

ssbarnea opened this issue Oct 7, 2018 · 25 comments

Comments

@ssbarnea
Copy link
Contributor

ssbarnea commented Oct 7, 2018

flake8 was officialy deprecated and mostly replaced by pycodestyle which is currently does not have a pre-commit-hook.

Initially I was considering repurposing the flake8 hook but I think it will be better to have a new one as doing the swap may also involve renaming its section inside setup.cfg or tox.ini.

@anthrotype
Copy link

flake8 was officialy deprecated and mostly replaced by pycodestyle

I wasn’t aware of that. Have you got a link?

@asottile
Copy link
Member

asottile commented Oct 7, 2018

as far as I can tell it's not deprecated. pycodestyle isn't a replacement for pyflakes + the plugin architecture.

it just hasn't received an update in a while. I've offered to pick up some maintenance but haven't heard back. I guess I'll email the mailing list?

@ssbarnea
Copy link
Contributor Author

ssbarnea commented Oct 7, 2018

My mistake, pep8 was renamed to pycodestyle.
@asottile I will support your maintenance proposal.

@blaggacao
Copy link

blaggacao commented Oct 11, 2018

pre-commit install && pre-comit run --all-files with this:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v1.2.3
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: debug-statements
# -   repo: https://github.com/asottile/pyupgrade
#     rev: v1.8.0
#     hooks:
    # - id: pyupgrade

I get identical failure on all hooks like this

Debug Statements (Python)................................................Failed
hookid: debug-statements

Traceback (most recent call last):
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/bin/debug-statement-hook", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/home/blaggacao/.cache/pre-commit/repoMfhDOU/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pycodestyle<2.4.0,>=2.0.0' distribution was not found and is required by flake8

@asottile
Copy link
Member

1.2.3 is pretty old, does that reproduce with 1.4.0?

I've seen that error in the past -- but it was supposed to be fixed with:

# quickfix to prevent pycodestyle conflicts
'flake8!=2.5.3',
'autopep8>=1.3',

@blaggacao
Copy link

blaggacao commented Oct 11, 2018

does that reproduce with 1.4.0

Yes, it does.

@asottile
Copy link
Member

@blaggacao weird...

$ pre-commit clean
Cleaned /home/asottile/.cache/pre-commit.

$ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed

$ cat .pre-commit-config.yaml repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v1.2.3
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml

$ python --version
Python 2.7.15rc1

$ pre-commit --version
pre-commit 1.11.2

can you show me those commands but in your environment?

also probably env | grep -Ei '(pip|python)'

@blaggacao
Copy link

blaggacao commented Oct 11, 2018

@asottile wired ineed:

$ pre-commit clean
Cleaned /home/blaggacao/.cache/pre-commit.

https://gist.github.com/blaggacao/8b9285898486f1d348ec1ae3a0533c17

$ cat .pre-commit-config.yaml repos:
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v1.4.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: debug-statements
-   repo: https://github.com/asottile/pyupgrade
    rev: v1.8.0
    hooks:
    - id: pyupgrade
cat: 'repos:': No such file or directory

$ python --version
Python 2.7.15rc1

$ pre-commit --version
pre-commit 1.11.2

$ env | grep -Ei '(pip|python)'
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSOPEN=| /usr/bin/lesspipe %s

Key is: https://gist.github.com/blaggacao/8b9285898486f1d348ec1ae3a0533c17

@asottile
Copy link
Member

That is so strange!

What does virtualenv --version give you?

Is there maybe also anything matching env | grep -i virtualenv ?

@blaggacao
Copy link

$ virtualenv --version
15.1.0

$ env | grep -i virtualenv

(no ouput)

@asottile
Copy link
Member

How about (I hope I typed this right on my phone) $(head -1 $(which pre-commit) | cut -d'!' -f2) -mpip freeze --all

@blaggacao
Copy link

Oha, that's a nice one 😉

$ $(head -1 $(which pre-commit) | cut -d'!' -f2) -mpip freeze --all
asn1crypto==0.24.0
aspy.yaml==1.1.1
astroid==1.6.3
backports-abc==0.5
backports.functools-lru-cache==1.5
backports.ssl-match-hostname==3.5.0.1
bzr==2.8.0.dev1
cached-property==1.3.1
certifi==2018.1.18
cfgv==1.1.0
chardet==3.0.4
configobj==5.0.6
configparser==3.5.0
cryptography==2.1.4
docker==2.5.1
docker-compose==1.17.1
docker-pycreds==0.2.1
dockerpty==0.4.1
docopt==0.6.2
docutils==0.14
enum34==1.1.6
funcsigs==1.0.2
functools32==3.2.3.post2
futures==3.2.0
gyp==0.1
httplib2==0.9.2
identify==1.1.7
idna==2.6
ipaddress==1.0.17
isort==4.3.4
jedi==0.12.1
jsonschema==2.6.0
keyring==10.6.0
keyrings.alt==3.0
launchpadlib==1.10.6
lazr.restfulclient==0.13.5
lazr.uri==1.0.3
lazy-object-proxy==1.3.1
lxml==4.2.3
mccabe==0.6.1
mock==2.0.0
nodeenv==1.3.2
oauth==1.0.1
parso==0.3.1
pbr==3.1.1
pip==18.1
pre-commit==1.11.2
prompt-toolkit==1.0.15
ptpython==0.41
pycairo==1.16.2
pycrypto==2.6.1
Pygments==2.2.0
pygobject==3.26.1
pylint==1.8.4
pylint-odoo==2.0.0
pylint-plugin-utils==0.2.4
pyOpenSSL==17.5.0
PyYAML==3.12
requests==2.18.4
restructuredtext-lint==1.1.0
rfc3986==1.1.0
SecretStorage==2.3.1
setuptools==39.0.1
simplejson==3.13.2
singledispatch==3.4.0.3
six==1.11.0
snakeviz==0.4.2
texttable==0.9.1
toml==0.10.0
tornado==5.1
urllib3==1.22
virtualenv==15.1.0
wadllib==1.3.2
wcwidth==0.1.7
websocket-client==0.44.0
wheel==0.31.0
whichcraft==0.4.1
wrapt==1.10.11
yapf==0.21.0
zope.interface==4.3.2

@asottile
Copy link
Member

That still looks fine too... This is quite the puzzler.

Maybe we can look inside the hook env, there should be a couple of repo* dirs in ~/.cache/pre-commit can you py_env-python2.7/bin/pip freeze in the pre-commit-hooks one?

Wow I wish I could debug this in person hah

@blaggacao
Copy link

In the one that just failed:

$ py_env-python2.7/bin/pip freeze
autopep8==1.4
configparser==3.5.0
enum34==1.1.6
flake8==3.5.0
mccabe==0.6.1
pkg-resources==0.0.0
pre-commit-hooks==1.4.0
pycodestyle==2.4.0
pyflakes==1.6.0
PyYAML==3.13
six==1.11.0

@blaggacao
Copy link

Aha! pycodestyle==2.4.0

@asottile
Copy link
Member

But how did it get there? lol

flake8 restricts the version to be <2.4.0

@asottile
Copy link
Member

I bet it's something to do with both autopep8 and flake8 being in the environment. Let me make a branch I've been meaning to make for a while and then I'll give you something to try

@asottile
Copy link
Member

@blaggacao can you try this branch: #321

Here's a config:

-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: 526904b1596ea461616a7b8b20ebd959454b57fc
    hooks:
    -   id: trailing-whitespace
    # ...

@blaggacao
Copy link

Looks good: (the error seems due to my exceptional naming)

Trim Trailing Whitespace.................................................Failed
hookid: trailing-whitespace

Files were modified by this hook. Additional output:

Fixing .travis.yml

Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed
Debug Statements (Python)................................................Failed
hookid: debug-statements

setup.py - Could not parse ast

	Traceback (most recent call last):
	  File "/home/blaggacao/.cache/pre-commit/repoVLbTxp/py_env-python2.7/local/lib/python2.7/site-packages/pre_commit_hooks/debug_statement_hook.py", line 40, in check_file
	    ast_obj = ast.parse(f.read(), filename=filename)
	  File "/usr/lib/python2.7/ast.py", line 37, in parse
	    return compile(source, filename, mode, PyCF_ONLY_AST)
	  File "setup.py", line 27
	    author_email='<put your email here, usually your company's email>',
	                                                             ^
	SyntaxError: invalid syntax

pyupgrade................................................................Passed

@asottile
Copy link
Member

I'm also trying to replicate in docker -- I suspect the difference between my environment and yours is I'm using a virtualenv and you've installed pre-commit to the system python2?

@blaggacao
Copy link

I guess, so:

$ which pre-commit
/usr/local/bin/pre-commit

@asottile
Copy link
Member

bingo! that's what it is:

root@387aa45b7c0b:/astpretty# pre-commit run --all-files
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Trim Trailing Whitespace.................................................Failed
hookid: trailing-whitespace

Traceback (most recent call last):
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/bin/trailing-whitespace-fixer", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/root/.cache/pre-commit/repo_3Nh2O/py_env-python2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pycodestyle<2.4.0,>=2.0.0' distribution was not found and is required by flake8

probably debian's packaging of virtualenv

If I pip install virtualenv (system pip) to get a newer virtualenv it fixes it:

root@387aa45b7c0b:/astpretty# pip install virtualenv --upgrade
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
    100% |################################| 1.9MB 698kB/s 
Installing collected packages: virtualenv
  Found existing installation: virtualenv 15.1.0
    Not uninstalling virtualenv at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed virtualenv-16.0.0
root@387aa45b7c0b:/astpretty# pre-commit clean
Cleaned /root/.cache/pre-commit.
root@387aa45b7c0b:/astpretty# pre-commit run --all-files
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Trim Trailing Whitespace.................................................Passed

@asottile
Copy link
Member

@blaggacao pre-commit-hooks v2.0.0 has been released which contains the fix for that 🎉 -- thanks again for the detailed report and the back and forth!

@blaggacao
Copy link

@asottile Thanks! You're welcome! Such (rare) responsiveness was great fun, also on this end.

@asottile
Copy link
Member

I think (?) this is less relevant now that I've released flake8 3.6.0 🎉

otherwise, feel free to reopen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants