From 3651cce54223a480f8affc8a81d327e61bc9b6ab Mon Sep 17 00:00:00 2001 From: kevgliss Date: Mon, 30 Nov 2015 10:43:41 -0800 Subject: [PATCH] adding automatic versioning --- .gitattributes | 3 ++- MANIFEST.in | 2 +- docs/conf.py | 5 +++-- docs/requirements.txt | 2 +- setup.py | 6 ++++-- version.py | 45 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 version.py diff --git a/.gitattributes b/.gitattributes index 21256661..9e7f8e2e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -* text=auto \ No newline at end of file +* text=auto +version.py export-subst \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index ec344cc4..1b517e89 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include setup.py package.json bower.json gulpfile.js README.rst MANIFEST.in LICENSE AUTHORS +include setup.py version.py package.json bower.json gulpfile.js README.rst MANIFEST.in LICENSE AUTHORS recursive-include lemur/plugins/lemur_email/templates * recursive-include lemur/static * global-exclude *~ diff --git a/docs/conf.py b/docs/conf.py index 5a308ee0..3a280a56 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,6 +11,7 @@ # # All configuration values have a default; values that are commented out # serve to show the default. +from version import get_version import sys import os @@ -55,9 +56,9 @@ copyright = u'2015, Netflix Inc.' # built documents. # # The short X.Y version. -version = '0.1' +version = get_version() # The full version, including alpha/beta/rc tags. -release = '0.1.3' +release = get_version() # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/requirements.txt b/docs/requirements.txt index 1480f1b3..01ee7488 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,7 +5,7 @@ docutils>=0.7 markupsafe sphinxcontrib-httpdomain Flask==0.10.1 -Flask-RESTful==0.3.4 +Flask-RESTful==0.3.3 Flask-SQLAlchemy==2.1 Flask-Script==2.0.5 Flask-Migrate==1.6.0 diff --git a/setup.py b/setup.py index a17038dd..9ed80255 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,8 @@ from setuptools.command.sdist import sdist from setuptools import setup, find_packages from subprocess import check_output +from version import get_version + ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__))) install_requires = [ @@ -124,11 +126,11 @@ class BuildStatic(Command): setup( name='lemur', - version='0.1.5', + version=get_version(), author='Kevin Glisson', author_email='kglisson@netflix.com', url='https://github.com/netflix/lemur', - download_url='https://github.com/Netflix/lemur/archive/0.1.3.tar.gz', + download_url='https://github.com/Netflix/lemur/archive/{0}.tar.gz'.format(get_version()), description='Certificate management and orchestration service', long_description=open(os.path.join(ROOT, 'README.rst')).read(), packages=find_packages(), diff --git a/version.py b/version.py new file mode 100644 index 00000000..9e02db92 --- /dev/null +++ b/version.py @@ -0,0 +1,45 @@ +# Source: https://github.com/Changaco/version.py + +from os.path import dirname, isdir, join +import re +from subprocess import CalledProcessError, check_output + + +PREFIX = '' + +tag_re = re.compile(r'\btag: %s([0-9][^,]*)\b' % PREFIX) +version_re = re.compile('^Version: (.+)$', re.M) + + +def get_version(): + # Return the version if it has been injected into the file by git-archive + version = tag_re.search('$Format:%D$') + if version: + return version.group(1) + + d = dirname(__file__) + + if isdir(join(d, '.git')): + # Get the version using "git describe". + cmd = 'git describe --tags --match %s[0-9]* --dirty' % PREFIX + try: + version = check_output(cmd.split()).decode().strip()[len(PREFIX):] + except CalledProcessError: + raise RuntimeError('Unable to get version number from git tags') + + # PEP 440 compatibility + if '-' in version: + if version.endswith('-dirty'): + raise RuntimeError('The working tree is dirty') + version = '.post'.join(version.split('-')[:2]) + + else: + # Extract the version from the PKG-INFO file. + with open(join(d, 'PKG-INFO')) as f: + version = version_re.search(f.read()).group(1) + + return version + + +if __name__ == '__main__': + print(get_version())