Skip to content

Instantly share code, notes, and snippets.

@nloadholtes
Created July 15, 2017 20:25
Show Gist options
  • Save nloadholtes/07a1716a89b53119021592a1d2b56db8 to your computer and use it in GitHub Desktop.
Save nloadholtes/07a1716a89b53119021592a1d2b56db8 to your computer and use it in GitHub Desktop.
An example of using the git hash/tag as a version number
from setuptools import setup, find_packages
import subprocess
def _get_version_hash():
"""Talk to git and find out the tag/hash of our latest commit"""
try:
p = subprocess.Popen(["git", "describe",
"--tags", "--dirty", "--always"],
stdout=subprocess.PIPE)
except EnvironmentError:
print("Couldn't run git to get a version number for setup.py")
return
ver = p.communicate()[0]
return ver.strip()
setup(
name='private-python-utils',
version=_get_version_hash(),
description='Our internal python utils library'
# And all of the other fields
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment