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

Isort might not find its metadata when run in pre-commit hooks #2362

Open
imrehg opened this issue Feb 13, 2025 · 3 comments
Open

Isort might not find its metadata when run in pre-commit hooks #2362

imrehg opened this issue Feb 13, 2025 · 3 comments

Comments

@imrehg
Copy link

imrehg commented Feb 13, 2025

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.

@DanielNoord
Copy link
Member

This seems like a similar concern as #2226

Perhaps we should just hardcode the version?

@kurtmckee
Copy link
Contributor

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 <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

@kurtmckee
Copy link
Contributor

kurtmckee commented Feb 14, 2025

@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.

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

3 participants