Skip to content

Commit 571e1fb

Browse files
committed
update setup.py
1 parent 124707a commit 571e1fb

File tree

7 files changed

+81
-52
lines changed

7 files changed

+81
-52
lines changed

AUTHORS.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
Xiaohao Yang
1+
This code is developed by:
2+
3+
Xiaohao Yang
4+
5+
This code was developed as part of the xPDFsuite project to create software
6+
and tools for general researchers to use PDF in their work. For more
7+
information on the DiffPy project email [email protected]

LICENSENOTICE.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ prohibited. If you don’t know whether or not your anticipated use is under
55
a license, you must contact Prof. Simon Billinge at [email protected].
66
Use of this software without a license is prohibited.
77

8-
Copyright 2009-2014, Trustees of Columbia University in the City of New York.
9-
8+
Copyright 2009-2016, Trustees of Columbia University in the City of New York.
109

1110
For more information please email Prof. Simon Billinge at [email protected]

conda-recipe/bld.bat

Whitespace-only changes.

conda-recipe/build.sh

Whitespace-only changes.

conda-recipe/meta.yaml

Whitespace-only changes.

setup.cfg

Lines changed: 0 additions & 4 deletions
This file was deleted.

setup.py

Lines changed: 73 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,70 @@
99
"""
1010

1111
import os
12-
import glob
1312
from setuptools import setup, find_packages
13+
from setuptools.command.build_py import build_py
14+
import py_compile
15+
16+
17+
class custom_build_pyc(build_py):
18+
19+
def byte_compile(self, files):
20+
for file in files:
21+
if file.endswith('.py'):
22+
py_compile.compile(file)
23+
os.unlink(file)
24+
25+
# Use this version when git data are not available, like in git zip archive.
26+
# Update when tagging a new release.
27+
FALLBACK_VERSION = '1.0'
1428

1529
# versioncfgfile holds version data for git commit hash and date.
1630
# It must reside in the same directory as version.py.
1731
MYDIR = os.path.dirname(os.path.abspath(__file__))
1832
versioncfgfile = os.path.join(MYDIR, 'dpx', 'confutils', 'version.cfg')
33+
gitarchivecfgfile = versioncfgfile.replace('version.cfg', 'gitarchive.cfg')
34+
1935

2036
def gitinfo():
2137
from subprocess import Popen, PIPE
2238
kw = dict(stdout=PIPE, cwd=MYDIR)
23-
rv = {}
2439
proc = Popen(['git', 'describe', '--match=v[[:digit:]]*'], **kw)
2540
desc = proc.stdout.read()
2641
proc = Popen(['git', 'log', '-1', '--format=%H %at %ai'], **kw)
2742
glog = proc.stdout.read()
28-
if desc != '':
29-
rv['version'] = desc.strip().split('-')[0].lstrip('v')
30-
else:
31-
rv['version'] = '1.0'
32-
if glog != '':
33-
rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
34-
else:
35-
rv['commit'], rv['timestamp'], rv['date'] = 'no git', 'no git', 'no git'
43+
rv = {}
44+
rv['version'] = '.post'.join(desc.strip().split('-')[:2]).lstrip('v')
45+
rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
3646
return rv
3747

3848

3949
def getversioncfg():
40-
from ConfigParser import SafeConfigParser
41-
cp = SafeConfigParser()
42-
cp.read(versioncfgfile)
50+
import re
51+
from ConfigParser import RawConfigParser
52+
vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
53+
# first fetch data from gitarchivecfgfile, ignore if it is unexpanded
54+
g = vd0.copy()
55+
cp0 = RawConfigParser(vd0)
56+
cp0.read(gitarchivecfgfile)
57+
if '$Format:' not in cp0.get('DEFAULT', 'commit'):
58+
g = cp0.defaults()
59+
mx = re.search(r'\btag: v(\d[^,]*)', g.pop('refnames'))
60+
if mx:
61+
g['version'] = mx.group(1)
62+
# then try to obtain version data from git.
4363
gitdir = os.path.join(MYDIR, '.git')
44-
if not os.path.isdir(gitdir):
45-
# not a git repo
46-
cp.set('DEFAULT', 'version', '1.0')
47-
cp.set('DEFAULT', 'commit', 'no git')
48-
cp.set('DEFAULT', 'date', 'no git')
49-
cp.set('DEFAULT', 'timestamp', 'no git')
50-
cp.write(open(versioncfgfile, 'w'))
51-
try:
52-
g = gitinfo()
53-
except OSError:
54-
return cp
64+
if os.path.exists(gitdir) or 'GIT_DIR' in os.environ:
65+
try:
66+
g = gitinfo()
67+
except OSError:
68+
pass
69+
# finally, check and update the active version file
70+
cp = RawConfigParser()
71+
cp.read(versioncfgfile)
5572
d = cp.defaults()
56-
if g['version'] != d.get('version') or g['commit'] != d.get('commit'):
73+
rewrite = not d or (g['commit'] and (
74+
g['version'] != d.get('version') or g['commit'] != d.get('commit')))
75+
if rewrite:
5776
cp.set('DEFAULT', 'version', g['version'])
5877
cp.set('DEFAULT', 'commit', g['commit'])
5978
cp.set('DEFAULT', 'date', g['date'])
@@ -63,27 +82,36 @@ def getversioncfg():
6382

6483
versiondata = getversioncfg()
6584

85+
86+
def dirglob(d, *patterns):
87+
from glob import glob
88+
rv = []
89+
for p in patterns:
90+
rv += glob(os.path.join(d, p))
91+
return rv
92+
6693
# define distribution
6794
setup_args = dict(
68-
name='dpx.confutils',
69-
version=versiondata.get('DEFAULT', 'version'),
70-
namespace_packages=['dpx'],
71-
packages=find_packages(),
72-
include_package_data=True,
73-
zip_safe=False,
74-
entry_points={
75-
# define console_scripts here, see setuptools docs for details.
76-
},
77-
78-
author='Simon J.L. Billinge',
79-
author_email='[email protected]',
80-
description='configuration utilities for dpx project',
81-
maintainer='Xiaohao Yang',
82-
maintainer_email='[email protected]',
83-
license='see LICENSENOTICE.txt',
84-
url='',
85-
keywords='dpx configuration utilities',
86-
classifiers=[
95+
name='dpx.confutils',
96+
cmdclass=dict(build_py=custom_build_pyc),
97+
version=versiondata.get('DEFAULT', 'version'),
98+
namespace_packages=['dpx'],
99+
packages=find_packages(),
100+
include_package_data=True,
101+
zip_safe=False,
102+
entry_points={
103+
# define console_scripts here, see setuptools docs for details.
104+
},
105+
106+
author='Simon J.L. Billinge',
107+
author_email='[email protected]',
108+
description='configuration utilities for dpx project',
109+
maintainer='Xiaohao Yang',
110+
maintainer_email='[email protected]',
111+
license='see LICENSENOTICE.txt',
112+
url='',
113+
keywords='dpx configuration utilities',
114+
classifiers=[
87115
# List of possible values at
88116
# http://pypi.python.org/pypi?:action=list_classifiers
89117
'Development Status :: 5 - Production/Stable',
@@ -97,7 +125,7 @@ def getversioncfg():
97125
'Programming Language :: Python :: 2.6',
98126
'Programming Language :: Python :: 2.7',
99127
'Topic :: Scientific/Engineering :: Physics',
100-
],
128+
],
101129
)
102130

103131
if __name__ == '__main__':

0 commit comments

Comments
 (0)