15
15
# as nice as it'd be to versioneer ourselves, that sounds messy.
16
16
VERSION = "0.10+"
17
17
18
- def get (fn ):
18
+
19
+ def ver (s ):
20
+ return s .replace ("@VERSIONEER-VERSION@" , VERSION )
21
+
22
+ def get (fn , add_ver = False , unquote = False , do_strip = False , do_readme = False ):
19
23
with open (fn ) as f :
20
24
text = f .read ()
21
25
@@ -24,20 +28,24 @@ def get(fn):
24
28
try :
25
29
__builtins__ .unicode
26
30
except AttributeError :
27
- return text
31
+ pass
28
32
else :
29
- return text .decode ('ASCII' )
33
+ text = text .decode ('ASCII' )
34
+ if add_ver :
35
+ text = ver (text )
36
+ if unquote :
37
+ text = text .replace ("%" , "%%" )
38
+ if do_strip :
39
+ lines = [line for line in text .split ("\n " )
40
+ if not line .endswith ("# --STRIP DURING BUILD" )]
41
+ text = "\n " .join (lines )
42
+ if do_readme :
43
+ text = text .replace ("@README@" , get ("README.md" ))
44
+ return text
30
45
31
46
def u (s ): # so u("foo") yields unicode on all of py2.6/py2.7/py3.2/py3.3
32
47
return s .encode ("ascii" ).decode ("ascii" )
33
48
34
- def unquote (s ):
35
- return s .replace ("%" , "%%" )
36
- def ver (s ):
37
- return s .replace ("@VERSIONEER-VERSION@" , VERSION )
38
- def readme (s ):
39
- return s .replace ("@README@" , get ("README.md" ))
40
-
41
49
def get_vcs_list ():
42
50
project_path = path .join (path .abspath (path .dirname (__file__ )), 'src' )
43
51
return [filename
@@ -47,28 +55,30 @@ def get_vcs_list():
47
55
48
56
def generate_versioneer ():
49
57
s = io .StringIO ()
50
- s .write (readme ( ver ( get ("src/header.py" )) ))
51
- s .write (get ("src/subprocess_helper.py" ))
58
+ s .write (get ("src/header.py" , add_ver = True , do_readme = True ))
59
+ s .write (get ("src/subprocess_helper.py" , do_strip = True ))
52
60
53
61
for VCS in get_vcs_list ():
54
62
s .write (u ("LONG_VERSION_PY['%s'] = '''\n " % VCS ))
55
- s .write (ver (get ("src/%s/long_header.py" % VCS )))
56
- s .write (unquote (get ("src/subprocess_helper.py" )))
57
- s .write (unquote (get ("src/from_parentdir.py" )))
58
- s .write (unquote (get ("src/%s/from_keywords.py" % VCS )))
59
- s .write (unquote (get ("src/%s/from_vcs.py" % VCS )))
60
- s .write (unquote (get ("src/%s/long_get_versions.py" % VCS )))
63
+ s .write (get ("src/%s/long_header.py" % VCS , add_ver = True , do_strip = True ))
64
+ s .write (get ("src/subprocess_helper.py" , unquote = True , do_strip = True ))
65
+ s .write (get ("src/from_parentdir.py" , unquote = True , do_strip = True ))
66
+ s .write (get ("src/%s/from_keywords.py" % VCS ,
67
+ unquote = True , do_strip = True ))
68
+ s .write (get ("src/%s/from_vcs.py" % VCS , unquote = True , do_strip = True ))
69
+ s .write (get ("src/%s/long_get_versions.py" % VCS ,
70
+ unquote = True , do_strip = True ))
61
71
s .write (u ("'''\n " ))
62
72
63
- s .write (get ("src/%s/from_keywords.py" % VCS ))
64
- s .write (get ("src/%s/from_vcs.py" % VCS ))
73
+ s .write (get ("src/%s/from_keywords.py" % VCS , do_strip = True ))
74
+ s .write (get ("src/%s/from_vcs.py" % VCS , do_strip = True ))
65
75
66
- s .write (get ("src/%s/install.py" % VCS ))
76
+ s .write (get ("src/%s/install.py" % VCS , do_strip = True ))
67
77
68
- s .write (get ("src/from_parentdir.py" ))
69
- s .write (ver ( get ("src/from_file.py" ) ))
70
- s .write (ver ( get ("src/get_versions.py" ) ))
71
- s .write (ver ( get ("src/cmdclass.py" ) ))
78
+ s .write (get ("src/from_parentdir.py" , do_strip = True ))
79
+ s .write (get ("src/from_file.py" , add_ver = True , do_strip = True ))
80
+ s .write (get ("src/get_versions.py" , add_ver = True , do_strip = True ))
81
+ s .write (get ("src/cmdclass.py" , add_ver = True , do_strip = True ))
72
82
73
83
return s .getvalue ().encode ("utf-8" )
74
84
0 commit comments