setuptools_scm icon indicating copy to clipboard operation
setuptools_scm copied to clipboard

Ad-hoc version/local scheme substitution

Open webknjaz opened this issue 5 years ago • 8 comments
trafficstars

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?

webknjaz avatar Jun 08 '20 22:06 webknjaz

this one needs some thought wrt howto integrate it sanely

RonnyPfannschmidt avatar Jun 09 '20 12:06 RonnyPfannschmidt

I guess the immediate workaround would be git update-index --assume-unchanged pyproject.toml in CI.

webknjaz avatar Jun 10 '20 15:06 webknjaz

@webknjaz im considering adding a SETUPTOOLS_SCM_CONFIG_OVERRIDES_FOR_{package-name.capitalize().replace("-","_")] env var containing json

any opinion?

RonnyPfannschmidt avatar Nov 29 '20 21:11 RonnyPfannschmidt

That's exactly what I was thinking about.

webknjaz avatar Nov 30 '20 00:11 webknjaz

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,
    },
)

bilke avatar Oct 05 '22 08:10 bilke

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

webknjaz avatar Nov 06 '22 23:11 webknjaz

By using the (deprecated) setup.py

FTR setup.py is not deprecated. Calling it directly is.

webknjaz avatar Apr 19 '24 23:04 webknjaz

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

webknjaz avatar Apr 19 '24 23:04 webknjaz