From 5730a977284047aaf8a91f4842a5917bdb12a1f6 Mon Sep 17 00:00:00 2001 From: Daniel Dehennin Date: Tue, 24 Jul 2012 14:13:27 +0200 Subject: [PATCH] Dynamic version and Makefile target to generate a distribution The version is extracted from the last tag name minus the 'release/' prefix. * AUTHORS: Add mysel as contributor. * setup.py: Add a function to get version from extracted version.in file or from the last tag name. * Makefile: Add a target to generate the version.in file from the last tag name. * .gitignore: Ignore the version.in file. --- .gitignore | 1 + AUTHORS | 2 +- Makefile | 25 +++++++++++++++++++++---- setup.py | 26 +++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a4d3899..5a1e270 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ *# *.pyc +version.in build/ diff --git a/AUTHORS b/AUTHORS index 4541b48..d2a16e7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,4 +3,4 @@ Authors Gwenaël Rémond lead developer Emmanuel Garette contributor - +Daniel Dehennin contributor diff --git a/Makefile b/Makefile index 95cd0ab..33922ac 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ #!/usr/bin/make +PACKAGE := tiramisu + INSTALL := install INSTALL_DATA := install -m 644 INSTALL_PROGRAM := install -m 755 @@ -10,16 +12,31 @@ ifneq ($(DESTDIR),) PYTHON_OPTS += --root $(DESTDIR) endif -all: test +LAST_TAG := $(shell git describe --tags --abbrev=0) +VERSION := $(shell echo $(LAST_TAG) | awk -F'/' '{print $$2}' || true) +VERSION_FILE := version.in + +all: clean: $(RM) -r build $(RM) -r tiramisu.egg-info/ - + test: clean py.test - + install: python setup.py install --no-compile $(PYTHON_OPTS) -.PHONY: all clean test install +# List in .PHONY to force generation at each call +version.in: + @if test -n $(VERSION) ; then \ + echo $(VERSION) > $(VERSION_FILE) ; \ + fi + +dist: version.in + git archive --format=tar --prefix $(PACKAGE)-$(VERSION)/ -o $(PACKAGE)-$(VERSION).tar $(LAST_TAG) \ + && tar --xform "s,\(.*\),$(PACKAGE)-$(VERSION)/\1," -f $(PACKAGE)-$(VERSION).tar -r version.in \ + && gzip -9 $(PACKAGE)-$(VERSION).tar + +.PHONY: all clean test install version.in dist diff --git a/setup.py b/setup.py index 3d5d58e..5f4d89c 100644 --- a/setup.py +++ b/setup.py @@ -2,11 +2,35 @@ # -*- coding: utf-8 -*- from distutils.core import setup +import os + +def fetch_version(): + """Get version from version.in or latest git tag""" + version_file='version.in' + version = "0.0" + git_last_tag_cmd = ['git', 'describe', '--tags', '--abbrev=0'] + + try: + if os.path.isfile(version_file): + version=file(version_file).readline().strip() + elif os.path.isdir('.git'): + popen = subprocess.Popen(git_last_tag_cmd, stdout=subprocess.PIPE) + out, ret = popen.communicate() + for line in out.split('\n'): + if line: + version = line.lstrip('release/') + break + except OSError: + pass # Failing is fine, we just can't print the version then + + return version + + setup( author='Gwenaël Rémond', author_email='gremond@cadoles.com', name='tiramisu', - version='0.1', + version=fetch_version(), description='configuration management tool', url='http://labs.libre-entreprise.org/projects/tiramisu', packages=['tiramisu']