Skip to content

How to have flake8 to print verbose output, if it was through pre-commit ?  #1221

Closed

Description

@chunji08

Here is my .pre-commit-config.yaml settings for flake8:

-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.8
    hooks:
    -   id: flake8
        args: [--config=.flake8]

and here my .flake8 file:

[flake8]
exclude =
    .git,
    __pycache__,
    old,
    build,
    dist,
    migrations,
    .venv

#TODO: enable the following lines
max-line-length = 88
#max-complexity = 18
ignore = E203, E266, E501, W503
select = B,C,E,F,W,T4,B9

when I run pre-commit, it just gives me a "Failed' mark, w/o any further messages. Thanks.

Activity

  1. asottile commented on Nov 13, 2019

    @asottile
    Member

    can you show the full output of pre-commit run --all-files? -- you also shouldn't need --config=.flake8 as flake8 will discover that file automatically

  2. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    If I was run the full set, here is output I got:

     pre-commit run --all-files
    pyupgrade................................................................Passed
    Reorder python imports...................................................Passed
    blacken-docs.............................................................Passed
    black....................................................................Passed
    Check for merge conflicts................................................Passed
    Check for broken symlinks................................................Passed
    Debug Statements (Python)................................................Passed
    Fix End of Files.........................................................Passed
    Fix python encoding pragma...............................................Passed
    Tests should end in _test.py.............................................Passed
    Trim Trailing Whitespace.................................................Passed
    flake8...................................................................Failed
    mypy.....................................................................Passed
    check for eval().........................................................Passed
    use logger.warning(......................................................Passed
    type annotations not comments............................................Passed
    
    

    If I was run flake8 only, here is what I got:

    pre-commit run flake8 --all-files
    flake8...................................................................Failed
    
    
  3. asottile commented on Nov 13, 2019

    @asottile
    Member

    what platform / version information can you provide? and does the output change if you run with --verbose?

  4. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    I am using pre-commit 1.20.0 on Ubuntu 16.0.4. and there is no difference if I was running in this way:

    pre-commit run flake8 --verbose --all-files
    [flake8] flake8..........................................................Failed
    
    

    This flake8 was newly added into .pre-commit-config.yaml file. During the first time running, it does give me failed file information. But after that, it just does not happen any more. Thanks.

  5. asottile commented on Nov 13, 2019

    @asottile
    Member

    hmmm we changed some stuff here recently, can you try with pre-commit 1.19 temporarily?

  6. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    Sure. One more reason I want to check is, if I was using the flake8 command directly, of the same flake8 version, it says my code was clean. So I am just curious about that. Thanks.

  7. asottile commented on Nov 13, 2019

    @asottile
    Member

    Failed means it is exiting nonzero, flake8; echo $? would potentially show that as well -- you may be able to flake8 -vvv to show why it's exiting nonzero

  8. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    OK. I will try.
    I have just installed the pre-commit of 1.19.0. running the full set does give me some extra message, but nothing is on the flake8 part:

    uname -a
    Linux Jenkins-CJI 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
    pre-commit --version
    pre-commit 1.19.0
    
    pre-commit run --verbose --all-files
    [pyupgrade] pyupgrade.............................................................Passed
    [reorder-python-imports] Reorder python imports...................................Passed
    [blacken-docs] blacken-docs.......................................................Passed
    [black] black.....................................................................Passed
    hookid: black
    
    All done! ✨ 🍰 ✨
    525 files left unchanged.
    
    [check-merge-conflict] Check for merge conflicts..................................Passed
    [check-symlinks] Check for broken symlinks........................................Passed
    [debug-statements] Debug Statements (Python)......................................Passed
    [end-of-file-fixer] Fix End of Files..............................................Passed
    [fix-encoding-pragma] Fix python encoding pragma..................................Passed
    [name-tests-test] Tests should end in _test.py....................................Passed
    [trailing-whitespace] Trim Trailing Whitespace....................................Passed
    [flake8] flake8...................................................................Failed
    [mypy] mypy.......................................................................Passed
    hookid: mypy
    
    Success: no issues found in 525 source files
    
    [python-no-eval] check for eval().................................................Passed
    [python-no-log-warn] use logger.warning(..........................................Passed
    [python-use-type-annotations] type annotations not comments.......................Passed
    
    
    
  9. asottile commented on Nov 13, 2019

    @asottile
    Member

    ok, what happens if you set args: [--config=.flake8, -vvv]?

  10. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    Added, but I don't know if there is an ending for this command. 5 mins after, this flake8 part is still on-going ( ?) That is the extra message I got on flake8 part:
    [flake8] flake8...................................................................

  11. asottile commented on Nov 13, 2019

    @asottile
    Member

    does flake8 -vvv outside of pre-commit show the same thing? (and flake8; echo $??)

  12. chunji08 commented on Nov 13, 2019

    @chunji08
    Author

    If I was running on this flake8 on command, It does give me lots of messages. Her is my separately installed flake8 version.

    flake8 --version
    3.7.8 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.5 on Linux
    
    
  13. asottile commented on Nov 13, 2019

    @asottile
    Member

    please run these commands and produce the full output

    # given what you've said above, this should just produce a number
    flake8; echo $?
    # you can attach the `log` file it produces to this issue
    flake8 -vvv > log
  14. chunji08 commented on Nov 14, 2019

    @chunji08
    Author
    flake8; echo $?
    0
    
    

    for the 2nd cmd, it gives such log message,

    log.txt

  15. asottile commented on Nov 14, 2019

    @asottile
    Member

    that's very strange.

    If you take one particular file from your repository does it still fail? pre-commit run flake8 --files setup.py for example (and try this with -vvv)

    you can also locate the exact flake8 binary that's being used via find ~/.cache/pre-commit -type f -name flake8 and might be able to reproduce the exit code from that as well

  16. chunji08 commented on Nov 14, 2019

    @chunji08
    Author

    I have a group of files, and I don't know which one causes that failure, if I in pre-commit mode. And that is the reason I am looking for the verbose message.
    For the one I just sent, I was using a hello world case, which is valid for sure. I thought you were trying to check my environment.

    find ~/.cache/pre-commit -type f -name flake8
    /var/lib/jenkins/.cache/pre-commit/repo2cmcogb7/py_env-python3.7/bin/flake8
    
    /var/lib/jenkins/.cache/pre-commit/repo2cmcogb7/py_env-python3.7/bin/flake8 --version
    3.7.8 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.3 on Linux
    
    

    I think I have 2 flakes, and they are of the same version.

  17. chunji08 commented on Nov 14, 2019

    @chunji08
    Author
    which flake8
    /usr/local/bin/flake8
    
    flake8 --version
    3.7.8 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.5 on Linux
    
    
  18. asottile commented on Nov 14, 2019

    @asottile
    Member

    I'm fairly certain this is something to do with your particular setup or target code as I cannot reproduce. the version information isn't really useful, I need you to run and produce log outputs as I've requested above

  19. chunji08 commented on Nov 14, 2019

    @chunji08
    Author

    the message I submitted was using the flake8 under /usr/local/bin/, Let me try the other one.

  20. asottile commented on Nov 14, 2019

    @asottile
    Member

    I'm most interested in this:

    If you take one particular file from your repository does it still fail? pre-commit run flake8 --files setup.py for example (and try this with -vvv)

  21. chunji08 commented on Nov 14, 2019

    @chunji08
    Author
    1. I was not able to run this way, "flake8; echo$?" , while the flake8 is from my ~/.cache/pre-commit dir. seems to me an endless call.

    2. The good news is I have found a way to solve my "failure" issue, which is to clean the ~/.cache/pre-commit, and rerun that "pre-commit run --all-files" as a fresh one.

    3. I guess what happen was my original ".pre-commit-config.yaml" did not have flake8 checking included, and I had it added later. While the yaml file was updated, the cache never gets synced ? and that causes such false failure. That explains to me when I was using /usr/local/bin/flake8 command to check directly, everything looks ok.

  22. asottile commented on Nov 14, 2019

    @asottile
    Member

    hmmm that should end up at the same result, the cache is meant to be partial and work after adding and removing things. but I guess now that it's fixed we won't be able to find the root problem any more.

    thanks for the persistence and sorry about the run-around!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions