Permalink
Browse files

Replace hardcoded version number with latest Git tag

With this change, the version number is no longer hard-coded inside setup.py. Instead, the
version number is derived from the latest git tag using "git describe". The Makefile (which
is now more than a pure convenience Makefile) will generate setup.py from setup.py.in
(which has been renamed accordingly), so that a source distribution (.tar.gz) will have
the correct version number inside.

As a special rule, whenever the Git checkout is not at a tag, "git describe" will generate
a string similar to "0.2-21-g0e10fca", indicating that there have been 21 commits since the
last tag "0.2" and the latest commit is g0e10fca. We translate this to "0.2_next21_g0e10fca"
so a.) RPM does not complain about the dashes (it doesn't allow them in its "Version" field)
and b.) the "next" indicates that this is a forthcoming version.
  • Loading branch information...
1 parent 0e10fca commit 7e920bb4e372f29cc3e0167224689e15bed14104 @pief committed Feb 25, 2013
Showing with 28 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +26 −6 Makefile
  3. +1 −1 setup.py → setup.py.in
View
@@ -1,4 +1,5 @@
MANIFEST
build
dist
+setup.py
*.pyc
View
@@ -3,10 +3,18 @@
# Copyright (c) 2013 Pieter Hollants <pieter@hollants.com>
# Licensed under the GNU Public License (GPL) version 3
#
-# Convenience Makefile
+# Makefile for Git repository-based builds
#
-VERSION := $(shell sed -n '/version.*=/ {s/^.*= *"//;s/",//;p}' setup.py)
+# The version is derived from the latest git tag set
+VERSION := $(shell git describe)
+
+# Some features should be available for proper releases with a x.y.z tag only
+ifeq ($(shell echo $(VERSION) | sed 's,^[[:digit:]]\+\.[[:digit:]]\+\(\.[[:digit:]]\+\)\?,,'),)
+ TAGGED := 1
+else
+ VERSION := $(shell echo $(VERSION) | sed 's,-,_next,;s,-,_,')
+endif
all: help
@@ -15,22 +23,34 @@ help:
@echo " python-netsnmpagent Module"
@echo " Copyright (c) 2013 Pieter Hollants <pieter@hollants.com>"
@echo
+ @echo "Version from \"git describe\": $(VERSION)"
+ @echo
@echo "Targets:"
@echo " install - Install locally"
@echo " srcdist - Create source distribution archive in .tar.gz format"
+ifeq ($(TAGGED),1)
@echo " upload - Upload source distribution archive to PyPI"
+endif
@echo " rpms - Build RPMs for the current distribution"
@echo " clean - Clean up"
@echo
-install:
+setup.py: setup.py.in
+ sed 's/@NETSNMPAGENT_VERSION@/$(VERSION)/' setup.py.in >setup.py
+ chmod u+x setup.py
+
+install: setup.py
python setup.py install
-srcdist:
+srcdist: setup.py
python setup.py sdist
-upload:
+upload: setup.py
+ifeq ($(TAGGED),1)
python setup.py sdist upload
+else
+ @echo "Upload not available for untagged versions!"
+endif
rpms: srcdist
@mkdir -p dist/RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} || exit 1
@@ -43,7 +63,7 @@ rpms: srcdist
-ba SPECS/python-netsnmpagent.spec
clean:
- python setup.py clean
+ @[ -e setup.py ] && (python setup.py clean; rm setup.py) || true
@[ -e "*.pyc" ] && rm *.pyc || true
@[ -e build ] && rm -rf build || true
@[ -e dist ] && rm -rf dist || true
View
2 setup.py → setup.py.in 100755 → 100644
@@ -18,7 +18,7 @@
setup(
name = "netsnmpagent",
- version = "0.2",
+ version = "@NETSNMPAGENT_VERSION@",
description = "Facilitates writing Net-SNMP (AgentX) subagents in Python",
long_description = """
python-netsnmpagent is a Python module that facilitates writing Net-SNMP

0 comments on commit 7e920bb

Please sign in to comment.