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

Replace pre-commit flake8 and isort with ruff #805

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

pawelngei
Copy link
Contributor

Currently, when trying to run any pre-commit hooks in Python 3.10, poetry crashes with the following log:

[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/alxd/.cache/pre-commit/repords8_k88/py_env-python3/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing /home/alxd/.cache/pre-commit/repords8_k88
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [14 lines of output]
          Traceback (most recent call last):
            File "/home/alxd/.cache/pre-commit/repords8_k88/py_env-python3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
              main()
            File "/home/alxd/.cache/pre-commit/repords8_k88/py_env-python3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
              json_out['return_val'] = hook(**hook_input['kwargs'])
            File "/home/alxd/.cache/pre-commit/repords8_k88/py_env-python3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
              return hook(metadata_directory, config_settings)
            File "/tmp/pip-build-env-wd0r5k17/overlay/lib/python3.10/site-packages/poetry/core/masonry/api.py", line 41, in prepare_metadata_for_build_wheel
              poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
            File "/tmp/pip-build-env-wd0r5k17/overlay/lib/python3.10/site-packages/poetry/core/factory.py", line 58, in create_poetry
              raise RuntimeError("The Poetry configuration is invalid:\n" + message)
          RuntimeError: The Poetry configuration is invalid:
            - [extras.pipfile_deprecated_finder.2] 'pip-shims<=0.3.4' does not match '^[a-zA-Z-_.0-9]+$'
          
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.
Check the log at /home/alxd/.cache/pre-commit/pre-commit.log

This is a known bug of isort, fixed by the 5.15.5 release. It shouldn't break compatibility with Python 3.7.

@pawelngei
Copy link
Contributor Author

I'm not sure what the fail means - from what I see, it didn't originate with my PR or isort. Should it be addressed in this PR?

@vitalik
Copy link
Owner

vitalik commented Aug 2, 2023

Hi @pawelngei

thank you for PR

Overal for next release I migrated from flake8, isort to ruff which covers all of this like 10x faster

do you think it is possible to cahnge this pre-commit as well to ruff ?

@pawelngei
Copy link
Contributor Author

Thank you @vitalik ! I could look into it in a spare moment. Which branch should I be testing with?

@vitalik
Copy link
Owner

vitalik commented Aug 2, 2023

master should have latest

@pawelngei
Copy link
Contributor Author

pawelngei commented Aug 2, 2023

Replaced flake8 and isort with ruff with automatic --fix. Would that be enough?

@pawelngei pawelngei changed the title Bump isort from 5.10.1 to 5.11.5 to avoid poetry pre-commit errors Replace pre-commit flake8 and isort with ruff Aug 2, 2023
@vitalik
Copy link
Owner

vitalik commented Aug 2, 2023

I think so, will see :)

@vitalik vitalik merged commit 8c7c5db into vitalik:master Aug 2, 2023
@pawelngei
Copy link
Contributor Author

pawelngei commented Aug 2, 2023

@vitalik Ah, just realized -

Ruff's pre-commit hook should be placed after other formatting tools, such as Black and isort, unless you enable autofix, in which case, Ruff's pre-commit hook should run before Black, isort, and other formatting tools, as Ruff's autofix behavior can output code changes that require reformatting.

One more commit, sorry for confusion.

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

Successfully merging this pull request may close these issues.

2 participants