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

Use environment variables for setuptools_scm version schemes #6

Merged
merged 1 commit into from
May 7, 2020

Conversation

rpanderson
Copy link
Owner

This PR amends #5, by using environment variables SCM_VERSION_SCHEME and SCM_LOCAL_SCHEME to set setuptools_scm.version_scheme and setuptools_scm.local_scheme, respectively. The default scheme if either environment variable is absent.

This can be tested by setting either of these environment variables to something other than the default scheme and running python setup.py --version. For example:

$ echo $SCM_VERSION_SCHEME

$ echo $SCM_LOCAL_SCHEME

$ python setup.py --version
0.1.0rc4.dev5+gcfe4fa1.d20200504
$ export SCM_LOCAL_SCHEME=no-local-version
$ python setup.py --version
0.1.0rc4.dev5
$ export SCM_VERSION_SCHEME=post-release
$ python setup.py --version
0.1.0rc3.post6

@rpanderson rpanderson added the enhancement New feature or request label May 4, 2020
@rpanderson rpanderson requested a review from philipstarkey May 4, 2020 08:09
@rpanderson rpanderson merged commit 394c710 into master May 7, 2020
@rpanderson rpanderson deleted the version_scheme_environ branch May 7, 2020 00:00
rpanderson added a commit that referenced this pull request May 7, 2020
Environment variable `SCM_LOCAL_VERSION` should have been `SCM_LOCAL_SCHEME` in release.yml.
@rpanderson
Copy link
Owner Author

Oddly, the workflow fails after merging this PR (and amending the typo in SCM_LOCAL_SCHEME), as it gets the version wrong, as 0.1dev1 rather than 0.1.0rc4.dev8 as above. This already exists on the repository and the upload fails.

@chrisjbillington
Copy link
Collaborator

Gets it wrong on your machine, or with github actions?

Works on my machine:

$ SCM_LOCAL_SCHEME=no-local-version python setup.py --version
0.1.0rc4.dev8

@rpanderson
Copy link
Owner Author

Actions. It works fine on my machine (Win/Linux).

@chrisjbillington
Copy link
Collaborator

Hm. Seems almost like the bot isn't fetching the tags. I know you have to push tags manually, I wonder if whatver "Syncing repository: rpanderson/workflow-sandbox" is doing behind the scenes is somehow failing to pull them.

@philipstarkey
Copy link
Collaborator

I think it's to do with the way your GitHub action workflow fetches the repository. This line suggests it is not fethcing the tags: https://github.com/rpanderson/workflow-sandbox/runs/651389010?check_suite_focus=true#step:3:31

@rpanderson
Copy link
Owner Author

It's because the repository cloned by actions/checkout is shallow.

@chrisjbillington
Copy link
Collaborator

chrisjbillington commented May 7, 2020

    # Number of commits to fetch. 0 indicates all history.
    # Default: 1
    fetch-depth: ''

If only there was a "fetch parents, taking the first parent when you hit a merge commit, and then stop when you hit a tag" option.

@chrisjbillington
Copy link
Collaborator

There's a fetch all tags action.

Discussed in setuptools_scm bug report

@rpanderson
Copy link
Owner Author

Yep, I've added another workflow step which is more eager (fetch all history for all tags and branches). This worked. I'll try just the tags.

@chrisjbillington
Copy link
Collaborator

chrisjbillington commented May 7, 2020

Just the tags doesn't seem to work for me locally.

[bilbo:clones]$ git clone --depth 1 https://github.com/rpanderson/workflow-sandbox/
Cloning into 'workflow-sandbox'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 18 (delta 0), reused 10 (delta 0), pack-reused 0
Receiving objects: 100% (18/18), 49.13 KiB | 2.14 MiB/s, done.
[bilbo:clones]$ cd workflow-sandbox/
[bilbo:workflow-sandbox]$ git fetch --depth=1 origin +refs/tags/*:refs/tags/*
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 19 (delta 6), reused 8 (delta 0), pack-reused 0
Unpacking objects: 100% (19/19), 3.28 KiB | 840.00 KiB/s, done.
From https://github.com/rpanderson/workflow-sandbox
 * [new tag]         v0.1.0rc1  -> v0.1.0rc1
 * [new tag]         v0.1.0rc2  -> v0.1.0rc2
 * [new tag]         v0.1.0rc3  -> v0.1.0rc3
[bilbo:workflow-sandbox]$ python setup.py --version
/usr/lib/python3.8/site-packages/setuptools_scm/git.py:68: UserWarning: "/home/bilbo/clones/workflow-sandbox" is shallow and may cause errors
  warnings.warn('"{}" is shallow and may cause errors'.format(wd.path))
0.1.dev1

If I checkout a tag it works for that tag. But I guess with just the tagged commits git just sees these floating island commits with no way to even know what order they're in without the intervening commits.

Good that all history of tags and branches works, but that's just a full depth clone, right? Shame if we can't still have it be shallower, but whatver.

@rpanderson
Copy link
Owner Author

(Snap.) Fetching tags alone doesn't suffice, as it needs to parse the history to form the version properly. There's probably a shallower way to do this, but for now I'll revert to the full clone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants