Skip to content

Python library is being installed without its git version tag #3047

@johentsch

Description

@johentsch

search you tried in the issue tracker

is:issue git version tag

describe your issue

We've started using my library ms3 as a pre-commit hook to generate additional files before committing. These include metadata files which routinely state the version of ms3 used to generate them.

Expected behaviour

The library should output the same version that is stated in the .pre-commit-config.yaml file calling it (currently v2.4.0).

Observed behaviour

Instead, the version information is something like 0.0.post1.dev1+gc24101c. Needless to say that under all other circumstances the version output is correctly based on the latest git tag.

Possible explanation

The version output looks like a version tag for a git repo that does not come with any tags. Could it be that pre-commit clones the repository without the relevant version tag?

Useful information

ms3 infers its own version using the importlib.metadata module, which happens here in the top-level init.py. It is written to the file __version__.py from where it can be imported by any other module.

How to reproduce

  1. git clone https://github.com/johentsch/ms3 --depth 1
  2. Replace the contents of .pre-commit-hooks.yaml with the content below
  3. In the repo, execute pre-commit try-repo . --all-files --verbose
Output

0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578
0.0.post1.dev1+gc587578

To convince yourself that under normal circumstances it works correctly, you could pip install . and then execute ms3 --version.

pre-commit --version

pre-commit 3.5.0

.pre-commit-hooks.yaml

-   id: version
    name: Show ms3 version
    entry: ms3 --version
    language: python

~/.cache/pre-commit/pre-commit.log (if present)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions