1010"""
1111
1212import os
13- import glob
1413from setuptools import setup , find_packages
14+ from setuptools .command .build_py import build_py
15+ import py_compile
16+
17+
18+ class custom_build_pyc (build_py ):
19+
20+ def byte_compile (self , files ):
21+ for file in files :
22+ if file .endswith ('.py' ):
23+ py_compile .compile (file )
24+ os .unlink (file )
25+
26+ # Use this version when git data are not available, like in git zip archive.
27+ # Update when tagging a new release.
28+ FALLBACK_VERSION = '1.0'
1529
1630# versioncfgfile holds version data for git commit hash and date.
1731# It must reside in the same directory as version.py.
1832MYDIR = os .path .dirname (os .path .abspath (__file__ ))
1933versioncfgfile = os .path .join (MYDIR , 'dpx' , 'srxplanargui' , 'version.cfg' )
20- defaultversion = '1.0'
34+ gitarchivecfgfile = versioncfgfile .replace ('version.cfg' , 'gitarchive.cfg' )
35+
2136
2237def gitinfo ():
2338 from subprocess import Popen , PIPE
2439 kw = dict (stdout = PIPE , cwd = MYDIR )
25- rv = {}
2640 proc = Popen (['git' , 'describe' , '--match=v[[:digit:]]*' ], ** kw )
2741 desc = proc .stdout .read ()
2842 proc = Popen (['git' , 'log' , '-1' , '--format=%H %at %ai' ], ** kw )
2943 glog = proc .stdout .read ()
30- if desc != '' :
31- rv ['version' ] = desc .strip ().split ('-' )[0 ].lstrip ('v' )
32- else :
33- rv ['version' ] = defaultversion
34- if glog != '' :
35- rv ['commit' ], rv ['timestamp' ], rv ['date' ] = glog .strip ().split (None , 2 )
36- else :
37- rv ['commit' ], rv ['timestamp' ], rv ['date' ] = 'no git' , 'no git' , 'no git'
44+ rv = {}
45+ rv ['version' ] = '.post' .join (desc .strip ().split ('-' )[:2 ]).lstrip ('v' )
46+ rv ['commit' ], rv ['timestamp' ], rv ['date' ] = glog .strip ().split (None , 2 )
3847 return rv
3948
4049
4150def getversioncfg ():
42- from ConfigParser import SafeConfigParser
43- cp = SafeConfigParser ()
44- cp .read (versioncfgfile )
51+ import re
52+ from ConfigParser import RawConfigParser
53+ vd0 = dict (version = FALLBACK_VERSION , commit = '' , date = '' , timestamp = 0 )
54+ # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
55+ g = vd0 .copy ()
56+ cp0 = RawConfigParser (vd0 )
57+ cp0 .read (gitarchivecfgfile )
58+ if '$Format:' not in cp0 .get ('DEFAULT' , 'commit' ):
59+ g = cp0 .defaults ()
60+ mx = re .search (r'\btag: v(\d[^,]*)' , g .pop ('refnames' ))
61+ if mx :
62+ g ['version' ] = mx .group (1 )
63+ # then try to obtain version data from git.
4564 gitdir = os .path .join (MYDIR , '.git' )
46- if not os .path .isdir (gitdir ):
47- # not a git repo
48- cp .set ('DEFAULT' , 'version' , defaultversion )
49- cp .set ('DEFAULT' , 'commit' , 'no git' )
50- cp .set ('DEFAULT' , 'date' , 'no git' )
51- cp .set ('DEFAULT' , 'timestamp' , 'no git' )
52- cp .write (open (versioncfgfile , 'w' ))
53- try :
54- g = gitinfo ()
55- except OSError :
56- return cp
65+ if os .path .exists (gitdir ) or 'GIT_DIR' in os .environ :
66+ try :
67+ g = gitinfo ()
68+ except OSError :
69+ pass
70+ # finally, check and update the active version file
71+ cp = RawConfigParser ()
72+ cp .read (versioncfgfile )
5773 d = cp .defaults ()
58- if g ['version' ] != d .get ('version' ) or g ['commit' ] != d .get ('commit' ):
74+ rewrite = not d or (g ['commit' ] and (
75+ g ['version' ] != d .get ('version' ) or g ['commit' ] != d .get ('commit' )))
76+ if rewrite :
5977 cp .set ('DEFAULT' , 'version' , g ['version' ])
6078 cp .set ('DEFAULT' , 'commit' , g ['commit' ])
6179 cp .set ('DEFAULT' , 'date' , g ['date' ])
@@ -65,29 +83,38 @@ def getversioncfg():
6583
6684versiondata = getversioncfg ()
6785
86+
87+ def dirglob (d , * patterns ):
88+ from glob import glob
89+ rv = []
90+ for p in patterns :
91+ rv += glob (os .path .join (d , p ))
92+ return rv
93+
6894# define distribution
6995setup_args = dict (
70- name = 'dpx.srxplanargui' ,
71- version = versiondata .get ('DEFAULT' , 'version' ),
72- namespace_packages = ['dpx' ],
73- packages = find_packages (),
74- include_package_data = True ,
75- zip_safe = False ,
76- entry_points = {
77- # define console_scripts here, see setuptools docs for details.
78- 'console_scripts' : ['srxgui = dpx.srxplanargui.srxguiapp:main' ,
79- ],
80- },
81-
82- author = 'Simon J.L. Billinge' ,
83- author_email = 'sb2896@columbia.edu' ,
84- description = 'PDFgetXgui, a software for PDF transformation and visualization' ,
85- maintainer = 'Xiaohao Yang' ,
86- maintainer_email = 'xiaohao.yang@outlook.com' ,
87- license = 'see LICENSENOTICE.txt' ,
88- url = '' ,
89- keywords = '2D powder diffraction image integration uncertainty propagation' ,
90- classifiers = [
96+ name = 'dpx.srxplanargui' ,
97+ cmdclass = dict (build_py = custom_build_pyc ),
98+ version = versiondata .get ('DEFAULT' , 'version' ),
99+ namespace_packages = ['dpx' ],
100+ packages = find_packages (),
101+ include_package_data = True ,
102+ zip_safe = False ,
103+ entry_points = {
104+ # define console_scripts here, see setuptools docs for details.
105+ 'console_scripts' : ['srxgui = dpx.srxplanargui.srxguiapp:main' ,
106+ ],
107+ },
108+
109+ author = 'Simon J.L. Billinge' ,
110+ author_email = 'sb2896@columbia.edu' ,
111+ description = 'xPDFsuite, a software for PDF transformation and visualization' ,
112+ maintainer = 'Xiaohao Yang' ,
113+ maintainer_email = 'sodestiny1@gmail.com' ,
114+ license = 'see LICENSENOTICE.txt' ,
115+ url = '' ,
116+ keywords = '2D powder diffraction image integration uncertainty propagation' ,
117+ classifiers = [
91118 # List of possible values at
92119 # http://pypi.python.org/pypi?:action=list_classifiers
93120 'Development Status :: 5 - Production/Stable' ,
@@ -101,7 +128,7 @@ def getversioncfg():
101128 'Programming Language :: Python :: 2.6' ,
102129 'Programming Language :: Python :: 2.7' ,
103130 'Topic :: Scientific/Engineering :: Physics' ,
104- ],
131+ ],
105132)
106133
107134if __name__ == '__main__' :
0 commit comments