88"""
99
1010import os
11+ import re
12+ import sys
1113from setuptools import setup , find_packages
1214
1315# Use this version when git data are not available, like in git zip archive.
1416# Update when tagging a new release.
1517FALLBACK_VERSION = '1.3.post0'
1618
19+ # determine if we run with Python 3.
20+ PY3 = (sys .version_info [0 ] == 3 )
21+
1722# versioncfgfile holds version data for git commit hash and date.
1823# It must reside in the same directory as version.py.
1924MYDIR = os .path .dirname (os .path .abspath (__file__ ))
2227
2328def gitinfo ():
2429 from subprocess import Popen , PIPE
25- kw = dict (stdout = PIPE , cwd = MYDIR )
30+ kw = dict (stdout = PIPE , cwd = MYDIR , universal_newlines = True )
2631 proc = Popen (['git' , 'describe' , '--match=v[[:digit:]]*' ], ** kw )
2732 desc = proc .stdout .read ()
2833 proc = Popen (['git' , 'log' , '-1' , '--format=%H %ct %ci' ], ** kw )
@@ -34,8 +39,10 @@ def gitinfo():
3439
3540
3641def getversioncfg ():
37- import re
38- from ConfigParser import RawConfigParser
42+ if PY3 :
43+ from configparser import RawConfigParser
44+ else :
45+ from ConfigParser import RawConfigParser
3946 vd0 = dict (version = FALLBACK_VERSION , commit = '' , date = '' , timestamp = 0 )
4047 # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
4148 g = vd0 .copy ()
@@ -64,7 +71,8 @@ def getversioncfg():
6471 cp .set ('DEFAULT' , 'commit' , g ['commit' ])
6572 cp .set ('DEFAULT' , 'date' , g ['date' ])
6673 cp .set ('DEFAULT' , 'timestamp' , g ['timestamp' ])
67- cp .write (open (versioncfgfile , 'w' ))
74+ with open (versioncfgfile , 'w' ) as fp :
75+ cp .write (fp )
6876 return cp
6977
7078versiondata = getversioncfg ()
0 commit comments