-
-
Notifications
You must be signed in to change notification settings - Fork 590
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
Isort might not find its metadata when run in pre-commit hooks #2362
Comments
This seems like a similar concern as #2226 Perhaps we should just hardcode the version? |
This is an issue with pre-commit checking out only exactly the one commit that's needed, while isort's hatch config relies on having full access to git via the This can be reproduced on Linux using the steps below, and the solution will have to be writing the isort version into Step 1Clean the pre-commit cache, then get pre-commit to install isort like normal. $ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /home/kurt/dev/test/.git/
$ pre-commit clean
Cleaned /home/kurt/.cache/pre-commit.
$ echo '
repos:
- repo: https://github.com/PyCQA/isort
rev: 6.0.0
hooks:
- id: isort
' > .pre-commit-config.yaml
$ pre-commit run isort
[INFO] Initializing environment for https://github.com/PyCQA/isort.
[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
isort................................................(no files to check)Skipped Step 2Inspect the results. $ cd ~/.cache/pre-commit/repo* # `pre-commit clean`, above, guarantees this works
$ git rev-parse HEAD # The hash below is the isort 6.0.0 tag
0a0b7a830386ba6a31c2ec8316849ae4d1b8240d
$ git tag # No output!
$ git log # Grafted, single commit available!
commit 0a0b7a830386ba6a31c2ec8316849ae4d1b8240d (grafted, HEAD)
Author: staticdev <staticdev-support@proton.me>
Date: Mon Jan 27 22:51:38 2025 +0100
6.0.0
$ ./py_env-*/bin/isort -V # Only one, so this will work. Note 0.1.dev1!
_ _
(_) ___ ___ _ __| |_
| |/ _/ / _ \/ '__ _/
| |\__ \/\_\/| | | |_
|_|\___/\___/\_/ \_/
isort your imports, so you don't have to.
VERSION 0.1.dev1
$ head -n 3 py_env-*/lib/*/site-packages/isort-*.dist-info/METADATA
Metadata-Version: 2.4
Name: isort
Version: 0.1.dev1
$ cat py_env-*/lib/*/site-packages/isort-*.dist-info/WHEEL
Wheel-Version: 1.0
Generator: hatchling 1.27.0
Root-Is-Purelib: true
Tag: py3-none-any |
@DanielNoord Er, it occurs to me that while this is fixable, it doesn't matter in the context of a pre-commit run. It's still version 6.0.0 code.
@imrehg This only appears to affect the version in the metadata; it's still 6.0.0 code. |
I have some issues with running isort, and while debugging that, I've found that the tool also don't seem to know it's own version - and likely some other metadata or setup as well...
Using verison
6.0.0
as a pre-commit hook:and then running that hook directly
pre-commit run isort -a
with some files that need changing so we can actually have a failure and thus a printout:If I run bare
isort -vv ...
orisort --version
when installed the same version, then I get the proper6.0.0
.Verison 5.13.2 was showing the correct info.
This might sound minor, but it might also mean it doesn't find other relevant information that can have side-effects on how isort is run.
The text was updated successfully, but these errors were encountered: