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

New pre-commit hook for autoflake #755

Closed
hofbi opened this issue Sep 28, 2022 · 3 comments
Closed

New pre-commit hook for autoflake #755

hofbi opened this issue Sep 28, 2022 · 3 comments

Comments

@hofbi
Copy link

hofbi commented Sep 28, 2022

Great collection of tools for notebooks. It would be great if you could add a pre-commit hook for https://github.com/PyCQA/autoflake

@MarcoGorelli
Copy link
Collaborator

Hey @hofbi

I'm not 100% confident about including autoflake, because imports might be used in parts of the notebook that nbqa can't currently process, see https://nbqa.readthedocs.io/en/latest/known-limitations.html

Having said that, you can already make a hook yourself to use autoflake:

- repo: https://github.com/nbQA-dev/nbQA
  rev: 1.5.2
  hooks:
    - id: nbqa
      entry: nbqa autoflake -i
      name: nbqa-autoflake
      alias: nbqa-autoflake
      additional_dependencies: [autoflake==<version number>]  # put which version of autoflake you want here

@hofbi
Copy link
Author

hofbi commented Sep 29, 2022

Thanks @MarcoGorelli for the quick reply. I saw that it is possible to use custom tools. Would you be interested to add autoflake to your https://github.com/nbQA-dev/nbQA/blob/main/.pre-commit-hooks.yaml? I could come up with a PR. I just tried in on my notebooks and worked well so far.

@MarcoGorelli
Copy link
Collaborator

I'd rather not, sorry, just a bit concerned about imports that might be used in parts of the notebook that nbqa can't currently process, see https://nbqa.readthedocs.io/en/latest/known-limitations.html

It's one thing for flake8 to flag them, and there may be false positive, but I feel less easy about autoflake removing unused imports due to a known limitation in nbqa

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