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

Add version info to druid package and use it for CLI version output #50

Merged
merged 2 commits into from
Oct 22, 2019

Conversation

simonvanderveldt
Copy link
Member

@simonvanderveldt simonvanderveldt commented Oct 21, 2019

This uses https://pypi.org/project/setuptools-scm/ + https://pypi.org/project/setuptools-scm-git-archive/ which is a bit "magic", but from my testing this is the only way to get the version automatically with the following criteria:

  • The only action necessary to update the version is git tag
  • Release archives from GitHub should work and show the correct version
  • During development it should be clear that a "development version" is being used. Ideally the shorthash + something like dev should be shown

Some output examples:

$ druid --version          
druid, version 0.1.2.dev17+g971de94
$ git tag -a 0.1.3 -m "thisisatest"
$ druid --version
druid, version 0.1.3
$ echo "foo" > test.txt
$ git add test.txt
$ druid --version
druid, version 0.1.4.dev0+g07eb4c8.d20191021

And when making a release archive (which is what GitHub does):

$ git tag -a 0.1.3 -m "thisisatest" 
$ git archive add-version-info | gzip > test.tgz
$ tar -axf test.tgz .git_archival.txt -O       
ref-names: HEAD -> add-version-info, tag: 0.1.3, origin/add-version-info

And when installing from this archive

$ pip install test.tgz
...
$ druid --version
druid, version 0.1.3

@csboling what do you think?

Fixes #29

And use this attribute in the CLI when using "druid --version""
Comment on lines +33 to +34
"setuptools_scm",
"setuptools_scm_git_archive",
Copy link
Member Author

@simonvanderveldt simonvanderveldt Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have these installed at runtime as well, otherwise the detection isn't possible.
Not super happy about that but if you want runtime detection there isn't really another option. We can of course discuss if we want/need runtime detection, but personally I quiet like it if we ask someone for some info for a bug that we know that something might or might not have been changed,

@@ -0,0 +1 @@
.git_archival.txt export-subst
Copy link
Member Author

@simonvanderveldt simonvanderveldt Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some git "magic" that processes the file on the left using the attribute on the right.
export-subst basically substitutes some placeholders, see https://git-scm.com/docs/gitattributes#_creating_an_archive for more details.

The result is something like

ref-names: HEAD -> add-version-info, tag: 0.1.3, origin/add-version-info

@simonvanderveldt simonvanderveldt changed the title Add version info to druid package and use it for --version Add version info to druid package and use it for CLI version output Oct 21, 2019
@trentgill
Copy link
Collaborator

This looks good to me, and I don't mind the extra packages now that we're using an automated setup with pip. I can't really comment on the implementation, but it's at least terse and reads cleanly to the uninitiated (read: myself).

Perhaps you could add a section to the readme which describes the necessary steps to make a new release? I know it's going to be automated at some point, but would be good to document the current situation.

@simonvanderveldt
Copy link
Member Author

Perhaps you could add a section to the readme which describes the necessary steps to make a new release? I know it's going to be automated at some point, but would be good to document the current situation.

Good point! I'll add that tomorrow.

@trentgill
Copy link
Collaborator

@simonvanderveldt lmk what I can do to test this out and then let's check it in!

@simonvanderveldt
Copy link
Member Author

@trentgill I don't expect it to behave differently on different OSes but if you could give it a spin on Mac OS and Windows that would be nice (although @csboling might do that as well)

@trentgill
Copy link
Collaborator

Tested all my systems and it seems to be working well! Merging now.

@trentgill trentgill merged commit 2fde665 into monome:master Oct 22, 2019
@csboling
Copy link
Contributor

I just learned like seven new things about pip and git from trying to understand how this works, awesome. Very tidy solution!

@simonvanderveldt simonvanderveldt added this to the 0.2.0 milestone Oct 24, 2019
@simonvanderveldt simonvanderveldt deleted the add-version-info branch October 25, 2019 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command-line option to show version
3 participants