setuptools_scm
setuptools_scm copied to clipboard
Ad-hoc version/local scheme substitution
It is known that PyPI doesn't accept local version identifiers (#322)
so when uploading non-tagged versions to TestPyPI, I need to do something
like echo 'local_scheme = "no-local-version"' >> pyproject.toml which
effectively marks the tree dirty influencing the generated version.
I also want to keep the defaults in all other cases (everything except
for non-tagged commits in CI/CD).
Would it be reasonable to support some sort of an env var based solution
for overriding a local version scheme w/o touching the file system?
this one needs some thought wrt howto integrate it sanely
I guess the immediate workaround would be git update-index --assume-unchanged pyproject.toml in CI.
@webknjaz im considering adding a SETUPTOOLS_SCM_CONFIG_OVERRIDES_FOR_{package-name.capitalize().replace("-","_")] env var containing json
any opinion?
That's exactly what I was thinking about.
By using the (deprecated) setup.py-approach you can implement this via environment variables, e.g.:
# setuptools_scm config local_scheme via env var SETUPTOOLS_SCM_LOCAL_SCHEME:
scm_local_scheme = "node-and-date"
if "SETUPTOOLS_SCM_LOCAL_SCHEME" in os.environ:
local_scheme_values = [
"node-and-date",
"node-and-timestamp",
"dirty-tag",
"no-local-version",
]
if os.environ["SETUPTOOLS_SCM_LOCAL_SCHEME"] in local_scheme_values:
scm_local_scheme = os.environ["SETUPTOOLS_SCM_LOCAL_SCHEME"]
#else:
# print some warning
setup(
...
use_scm_version={
"local_scheme": scm_local_scheme,
},
)
UPDATE: This is a bad idea and does not work well.
~I've discovered another workaround'ish thing that will work for me.~
~So, the initial frustration was coming from having to modified a structured TOML file and hoping not to break anything because of some changes to it that didn't account for the CI/CD workflow. Or having to use a toml library that would almost certainly reformat the contents.~
~But I've recently realized that I could just pre-compute the version externally and produce a .git_archival.txt file with contents similar to what git archive emits. Another bit necessary is removing the .git/ directory, and voilà! — setuptools-scm just picks that up. Tested with older versions and the setuptools_scm_git_archive plugin, as well as with the newer releases without the plugin.~
$ cat .git_archival.txt
node: fake_sha
node-date: 1970-01-01T00:00:00+00:00
describe-name: v0.0.5.dev0-0-gfake_sha
ref-names: FAKE_CI_HEAD -> fake-ci-branch, tag: v0.0.5.dev0
$ rm -rf .git
$ python -m build --sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... ([...])
* Getting build dependencies for sdist...
running egg_info
[...]
Writing dist-0.0.5.dev0/setup.cfg
Creating tar archive
removing 'dist-0.0.5.dev0' (and everything under it)
Successfully built dist-0.0.5.dev0.tar.gz
~A non-fake metadata file version can be produced as follows:~
git show --format='node: %H%nnode-date: %cI%ndescribe-name: %(describe:tags=true,match=*[0-9]*)%nref-names: %D%n' --no-patch > .git_archival.txt
By using the (deprecated)
setup.py
FTR setup.py is not deprecated. Calling it directly is.
~UPD:~
echo 'local_scheme = "no-local-version"' >> pyproject.toml
~Looks like this stopped working with modern setuptools versions :(~
~Exactly what https://github.com/pypa/setuptools_scm/pull/686#issuecomment-1040451127 says. I wonder why nobody filed an issue for this...~
UPD 2: Nevermind, it was a combination of newer setuptools (v69) and older setuptools-scm (v7). Upgrading it to v8 fixed the problem.