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

Update the autoflake pre-commit hook #43

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

stefan-anmut
Copy link

@stefan-anmut stefan-anmut commented Aug 27, 2024

The mirrors-autoflake pre-commit was giving the following error:

Traceback (most recent call last):
  File "/Users/stefmd/.cache/pre-commit/repou4rvvmfx/py_env-python3.12/bin/autoflake", line 5, in <module>
    from autoflake import main
  File "/Users/stefmd/.cache/pre-commit/repou4rvvmfx/py_env-python3.12/lib/python3.12/site-packages/autoflake.py", line 32, in <module>
    import distutils.sysconfig
ModuleNotFoundError: No module named 'distutils'

due to the fact that the mirrors-autoflake repository that our "autoflake" pre-commit hook uses has been deprecated since the official autoflake released functionality that supports its use with pre-commit, and therefore was stopped from being maintained more than 2 years ago.

In that time, python has deprecated its distutils module from version 3.10 onwards (can read up on that here), which mirrors-autoflake still relies on, meaning it will always give the same error within our pre-commit setup (that seems to be using 3.12 as default as can be seen from the python ref in the error traceback).

To solve this, I have opted to point our "autoflake" pre-commit hook in the direction of the latest version of the official autoflake repo which doesn't have this dependency. Rather than override pre-commit's default_language_version to 3.8 (or any version < 3.10).

Copy link

@csut-anmut csut-anmut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that autoflake has official pre-commit integration, there is no need to use a mirror. Looks geat, good spot @stefan-anmut 🙌.

Copy link

@jmartin-anmut jmartin-anmut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Nice work 👍

@stefan-anmut stefan-anmut merged commit b3c4264 into master Aug 28, 2024
7 checks passed
@stefan-anmut stefan-anmut deleted the update_autoflake_precommit_hook branch August 28, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants