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

flake8 config options count and statistics causing inference with yesqa run #132

Closed
matthewfeickert opened this issue Aug 10, 2022 · 3 comments

Comments

@matthewfeickert
Copy link
Sponsor

matthewfeickert commented Aug 10, 2022

Hi. Thanks for making yesqa. I am trying to run yesqa for a project but am finding that for reasons that are not obvious to me that the flake8 options that I have set in setup.cfg are apparently causing a ValueError from yesqa.

Specifically, the count = True and statistics = True are the problems.

$ tail -n 8 setup.cfg 
[flake8]
# E203: whitespace before ':'
# E402: module level import not at top of file
# E501: line too long
extend-ignore = E203, E402, E501
max-line-length = 88
count = True
statistics = True

If I comment them out/change them to False then yesqa is able to run without issues. If you have advice on how to mitigate this that would be quite helpful.

Reproducer

I'll do this all inside a Docker image and hopefully that isn't too annoying for any copy and pasting

$ docker run --rm -ti python:3.10 /bin/bash
root@2b4b222ff02e:/# python -m venv venv && . venv/bin/activate
(venv) root@2b4b222ff02e:/# python -m pip --quiet install --upgrade pip
(venv) root@2b4b222ff02e:/# python -m pip --quiet install 'yesqa==1.4.0'
(venv) root@2b4b222ff02e:/# python -m pip list
Package     Version
----------- -------
flake8      5.0.4
mccabe      0.7.0
pip         22.2.2
pycodestyle 2.9.1
pyflakes    2.5.0
setuptools  63.2.0
tokenize-rt 4.2.1
yesqa       1.4.0
(venv) root@2b4b222ff02e:/# git clone --quiet https://github.com/scikit-hep/pyhf.git
(venv) root@2b4b222ff02e:/# cd pyhf
(venv) root@2b4b222ff02e:/pyhf# git checkout 1494b66ef4edbb2d76e982771523d8b94c2d73e4
(venv) root@2b4b222ff02e:/pyhf# tail -n 8 setup.cfg 
[flake8]
# E203: whitespace before ':'
# E402: module level import not at top of file
# E501: line too long
extend-ignore = E203, E402, E501
max-line-length = 88
count = True
statistics = True
(venv) root@2b4b222ff02e:/pyhf# git grep --name-only "noqa"
src/pyhf/__init__.py
src/pyhf/contrib/cli.py
src/pyhf/infer/__init__.py
src/pyhf/infer/calculators.py
src/pyhf/optimize/opt_minuit.py
(venv) root@2b4b222ff02e:/pyhf# git grep --name-only "noqa" | xargs yesqa
Traceback (most recent call last):
  File "/venv/bin/yesqa", line 8, in <module>
    sys.exit(main())
  File "/venv/lib/python3.10/site-packages/yesqa.py", line 179, in main
    retv |= fix_file(filename)
  File "/venv/lib/python3.10/site-packages/yesqa.py", line 142, in fix_file
    flake8_results = _run_flake8(path)
  File "/venv/lib/python3.10/site-packages/yesqa.py", line 36, in _run_flake8
    lineno, code = line.split('\t')
ValueError: not enough values to unpack (expected 2, got 1)
(venv) root@2b4b222ff02e:/pyhf# apt update && apt install -y vim
(venv) root@2b4b222ff02e:/pyhf# vi setup.cfg 
(venv) root@2b4b222ff02e:/pyhf# git diff
diff --git a/setup.cfg b/setup.cfg
index dbe241c..9f7d130 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -56,5 +56,5 @@ console_scripts =
 # E501: line too long
 extend-ignore = E203, E402, E501
 max-line-length = 88
-count = True
-statistics = True
+# count = True
+# statistics = True
(venv) root@2b4b222ff02e:/pyhf# git grep --name-only "noqa" | xargs yesqa
Rewriting src/pyhf/infer/__init__.py
(venv) root@2b4b222ff02e:/pyhf# git grep --name-only "noqa" | xargs yesqa
@matthewfeickert
Copy link
Sponsor Author

matthewfeickert commented Aug 10, 2022

Looking more I see that this is similar to Issue #43. There you mentioned #43 (comment)

I think I'll add an option to flake8 which makes this easier, I assume other plugin tools have the same problem

which lead to PyCQA/flake8#995, but is there a generic way to disable options for calling tools that users should be using?

@asottile
Copy link
Owner

dupe: PyCQA/flake8#1458

I would recommend not using those options, they're kinda noisy/ useless imo anyway

@matthewfeickert
Copy link
Sponsor Author

I would recommend not using those options, they're kinda noisy/ useless imo anyway

An alternative that also works is to remove them from the flake8 config and stick them on the flake8 pre-commit hook as args (scikit-hep/pyhf#1932). As pre-commit is the main way that I'm running flake8 anyway this works just as well.

kratsg pushed a commit to scikit-hep/pyhf that referenced this issue Aug 10, 2022
* Add and apply yesqa pre-commit hook.
* Move flake8 options 'count' and 'statistics' from the flake8 config
in setup.cfg to args for the flake8 pre-commit hook to avoid problems
with yesqa.
   - c.f. asottile/yesqa#132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants