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

Feature request: override/pretend a version by environment variable #45

Open
gertvdijk opened this issue Feb 5, 2023 · 5 comments
Open
Labels
enhancement New feature or request therefor under consideration Dev has not yet decided whether or how to implement

Comments

@gertvdijk
Copy link

gertvdijk commented Feb 5, 2023

I'm looking for the equivalent of SETUPTOOLS_SCM_PRETEND_VERSION environment variable as available in setuptools-scm, for versioningit.

Would be great if that's possible without the need to write a custom versioningit method. My use case is a build in Docker where I can exclude the (huge) .git/ folder from the Docker context, have no dependency on git tooling in the image and just supply the version from the host as Docker build argument.

@jwodder
Copy link
Owner

jwodder commented Apr 9, 2023

I see the following problems/complications with this idea:

  • When such an environment variable is present, the querying of the VCS would be skipped, and so the only fields available to the write and onbuild steps would be {version} and {version_tuple}. While this has precedent with the fact that only those fields are guaranteed to be present when tool.versioningit.default-version is set, the difference is that the package author must deliberately choose to use default-version, whereas an environment variable can be set by anyone building or installing the package, which leads in to problem number 2....
  • If this is implemented as a single VERSIONINGIT_PRETEND_VERSION envvar, then setting the envvar when building or installing a versioningit-using package will result in the envvar being recursively propagated to all build or runtime dependencies, and if any of those use versioningit, they'd get their versions overridden. setuptools_scm happens to also support a solution to this problem, per-project SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME} envvars, but versioningit can't easily adopt that, as it only has access to the project name when invoked through the setuptools hook and not when run via the versioningit command or the library API.

Side note: You may be able to address your original Dockerization problem by building a wheel (which will have the appropriate version and not contain any .git/ data) for your project outside of Docker, copying the wheel into Docker, and then running pip install ./projectname-*.whl inside Docker.

@jwodder jwodder added the enhancement New feature or request therefor label Apr 9, 2023
@bulletmark
Copy link

I started with setuptools-scm, then went to versioningit due to a small issue, but have now moved back to setuptools-scm due to this issue which pertains not only to Docker. Unfortunately I am finding that building an Arch Linux AUR package is awkward without an SETUPTOOLS_SCM_PRETEND_VERSION equivalent.

@sarnold
Copy link

sarnold commented Aug 25, 2023

I had the same question re OS packages from github-generated archives which seem to be the most common source used for packaging GH projects. Obviously packaging tools differ from one distro to the next, but several of them rely on the SETUPTOOLS_SCM_PRETEND_VERSION thing to facilitate packaging bare GH archives. Could you elaborate a bit more on your rationale? I would thankfully use such a feature and not use setuptools_scm for my own projects.

@basnijholt
Copy link

@jwodder would you be open to accept a PR that reads from .git/OVERWRITE_VERSION or something similar for cases where there is no .git directory? e.g., in a Docker image where we don't want to include the entire .git history?

@basnijholt
Copy link

I opened PR #97 where I implement reading the hardcoded version from .git/versioningit-pretend-version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request therefor under consideration Dev has not yet decided whether or how to implement
Projects
None yet
Development

No branches or pull requests

5 participants