Isort might not find its metadata when run in pre-commit hooks
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:
- repo: https://github.com/PyCQA/isort
rev: 6.0.0
hooks:
- id: isort
args: ['-v']
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:
isort....................................................................Failed
- hook id: isort
- files were modified by this hook
_ _
(_) ___ ___ _ __| |_
| |/ _/ / _ \/ '__ _/
| |\__ \/\_\/| | | |_
|_|\___/\___/\_/ \_/
isort your imports, so you don't have to.
VERSION 0.1.dev1
If I run bare isort -vv ... or isort --version when installed the same version, then I get the proper 6.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.
This seems like a similar concern as https://github.com/PyCQA/isort/pull/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 hatch-vcs plugin (presumably the tags).
This can be reproduced on Linux using the steps below, and the solution will have to be writing the isort version into pyproject.toml, since the git tags/history won't always be available when building the package.
Step 1
Clean 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 2
Inspect 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 <[email protected]>
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.
and likely some other metadata or setup as well [...] it might also mean it doesn't find other relevant information that can have side-effects on how isort is run.
@imrehg This only appears to affect the version in the metadata; it's still 6.0.0 code.
Closing as won't fix!