-
-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Context: I'd like to define a "release version" in a file, and then use git versioning for commits in between official releases. Our package generates data and for reproducibility we access the full version number at runtime and save it along with the data.
The documentation about version_file says:
Please take into account that version_file is ignored if any tag is present in the current branch.
This creates the following problems:
- Our repo initially only had a main branch, and as it grew we added a develop branch and have a lightweight form of git-flow going on. Since develop branched from the main branch, which already had some version tags, the version_file is ignored for all eternity.
- Even if that weren't the case, if we update the version file on develop and then merge into main, the version file is ignored again. Even though tags are really just for convenience and the ground truth release version is contained in a file, if we forget to add the tag on main, the version reverts to the previous tag.
I looked into using version_callback instead. I tried adding a __release_version__ = "0.1.0" string inside __init__.py and in a separate _version.py file. The respective entries in pyproject.toml I tried are version_callback = "mypackage:__release_version__" and version_callback = "mypackage._version:__release_version__"
However I ran into some issues with this as well:
- I can't get setuptools-git-versioning to actually use this string. I'm getting
packaging.version.InvalidVersion: Invalid version: 'mypackage._version.__release_version__'when I eitherpip install -e .or runpython -m setuptools_git_versioningin a terminal. Strangely, when I run that last command in a debugger it spits out the correct version number. - Even if I can get past this problem, there's another one I don't see a way around. Since I need the full version number, including any "post" and "git" suffixes at runtime, I'm using the
importlibmethod. However, when the package hasn't been installed, I don't ignore thePackageNotFoundErrorand instead tell users to install the package first. The problem is whenever setuptools-git-versioning would try to import the callback,__init__.pywould get imported as well, and we'd get thisPackageNotFoundErrorsince we're in the process of installing the package.
Maybe I'm not using this tool right, so I'm open to suggestions.
My request however, would be to add an option to let version_file take precedence over any git tags. That would solve the whole problem.