Skip to content

Commit 69a6ca5

Browse files
committed
Convert to git-based versioning.
Derive version number from the nearest git tag. Provide access to the related commit date and SHA checksum. Allow setup.py to be importable if sphinx/docutils need to determine package version.
1 parent 8b1534e commit 69a6ca5

File tree

2 files changed

+90
-9
lines changed

2 files changed

+90
-9
lines changed

Diff for: diffpy/srmise/version.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111
#
1212
##############################################################################
1313

14-
"""Definition of __version__ and __date__ for SrMise.
14+
"""Definition of __version__, __date__, __gitsha__.
1515
"""
1616

17-
# obtain version information
18-
from pkg_resources import get_distribution
19-
__version__ = get_distribution('diffpy.srmise').version
17+
from pkg_resources import resource_stream
18+
from ConfigParser import SafeConfigParser
2019

21-
# we assume that tag_date was used and __version__ ends in YYYYMMDD
22-
__date__ = __version__[-8:-4] + '-' + \
23-
__version__[-4:-2] + '-' + __version__[-2:]
20+
# obtain version information from the version.cfg file
21+
cp = SafeConfigParser()
22+
cp.readfp(resource_stream(__name__, 'version.cfg'))
23+
24+
__version__ = cp.get('DEFAULT', 'version')
25+
__date__ = cp.get('DEFAULT', 'date')
26+
__gitsha__ = cp.get('DEFAULT', 'commit')
27+
28+
del cp
2429

2530
# End of file

Diff for: setup.py

+78-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
11
#!/usr/bin/env python
22

3+
# Installation script for diffpy.srmise
4+
5+
"""diffpy.srmise - identify peaks and peak shoulders in PDF curve
6+
7+
Packages: diffpy.srmise
8+
"""
9+
10+
import os
311
from setuptools import setup, find_packages
4-
setup(
12+
13+
# versioncfgfile holds version data for git commit hash and date.
14+
# It must reside in the same directory as version.py.
15+
MYDIR = os.path.dirname(os.path.abspath(__file__))
16+
versioncfgfile = os.path.join(MYDIR, 'diffpy/srmise/version.cfg')
17+
18+
def gitinfo():
19+
from subprocess import Popen, PIPE
20+
kw = dict(stdout=PIPE, cwd=MYDIR)
21+
proc = Popen(['git', 'describe', '--match=v[[:digit:]]*'], **kw)
22+
desc = proc.stdout.read()
23+
proc = Popen(['git', 'log', '-1', '--format=%H %at %ai'], **kw)
24+
glog = proc.stdout.read()
25+
rv = {}
26+
rv['version'] = '-'.join(desc.strip().split('-')[:2]).lstrip('v')
27+
rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
28+
return rv
29+
30+
31+
def getversioncfg():
32+
from ConfigParser import SafeConfigParser
33+
cp = SafeConfigParser()
34+
cp.read(versioncfgfile)
35+
gitdir = os.path.join(MYDIR, '.git')
36+
if not os.path.isdir(gitdir): return cp
37+
try:
38+
g = gitinfo()
39+
except OSError:
40+
return cp
41+
d = cp.defaults()
42+
if g['version'] != d.get('version') or g['commit'] != d.get('commit'):
43+
cp.set('DEFAULT', 'version', g['version'])
44+
cp.set('DEFAULT', 'commit', g['commit'])
45+
cp.set('DEFAULT', 'date', g['date'])
46+
cp.set('DEFAULT', 'timestamp', g['timestamp'])
47+
cp.write(open(versioncfgfile, 'w'))
48+
return cp
49+
50+
versiondata = getversioncfg()
51+
52+
# define distribution, but make this module importable
53+
setup_args = dict(
554
name = "diffpy.srmise",
6-
version = "0.4a1",
55+
version = versiondata.get('DEFAULT', 'version'),
756
namespace_packages = ['diffpy'],
857
packages = find_packages(),
958
include_package_data = True,
@@ -23,4 +72,31 @@
2372
'srmiseplot = diffpy.srmise.applications.plot:main',
2473
]
2574
},
75+
76+
author = "Luke Granlund",
77+
author_email = "[email protected]",
78+
description = "SrMise - FIXME",
79+
license = 'FIXME',
80+
# url = "",
81+
# keywords = "",
82+
classifiers = [
83+
# List of possible values at
84+
# http://pypi.python.org/pypi?:action=list_classifiers
85+
'Development Status :: 3 - Alpha',
86+
'Environment :: Console',
87+
'Intended Audience :: Developers',
88+
'Intended Audience :: Education',
89+
'Intended Audience :: Science/Research',
90+
'License :: OSI Approved :: BSD License',
91+
'Operating System :: MacOS',
92+
'Operating System :: POSIX',
93+
'Programming Language :: Python :: 2.6',
94+
'Programming Language :: Python :: 2.7',
95+
'Topic :: Scientific/Engineering :: Chemistry',
96+
'Topic :: Scientific/Engineering :: Physics',
97+
'Topic :: Software Development :: Libraries',
98+
],
2699
)
100+
101+
if __name__ == '__main__':
102+
setup(**setup_args)

0 commit comments

Comments
 (0)