Browse code

add template for _static_version.py to install-miniver script

This is necessary, as when miniver is installed locally, the
installed _static_version.py has its version string set to the
miniver version.

Closes #4.

Joseph Weston authored on 21/06/2018 22:21:35
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@ except ImportError:
24 24
     _miniver_is_installed = False
25 25
 
26 26
 # When we fetch miniver from local files
27
-_miniver_modules = ('_version', '_static_version')
27
+_miniver_modules = ('_version',)
28 28
 
29 29
 
30 30
 # When we fetch miniver from GitHub
... ...
@@ -53,6 +53,21 @@ _setup_template = '''
53 53
     )
54 54
 '''
55 55
 
56
+_static_version_template = textwrap.dedent('''\
57
+    # -*- coding: utf-8 -*-
58
+    # This file is part of 'miniver': https://github.com/jbweston/miniver
59
+    #
60
+    # This file will be overwritten by setup.py when a source or binary
61
+    # distribution is made.  The magic value "__use_git__" is interpreted by
62
+    # version.py.
63
+
64
+    version = "__use_git__"
65
+
66
+    # These values are only set if the distribution was created with 'git archive'
67
+    refnames = "$Format:%D$"
68
+    git_hash = "$Format:%h$"
69
+''')
70
+
56 71
 _init_template = 'from ._version import __version__'
57 72
 _gitattribute_template = '{package_dir}/_static_version.py export-subst'
58 73
 
... ...
@@ -77,6 +92,11 @@ def _write_line(content, filename):
77 92
             f.write(content)
78 93
 
79 94
 
95
+def _write_content(content, filename):
96
+    with open(filename, 'w') as f:
97
+        f.write(content)
98
+
99
+
80 100
 def _fail(msg):
81 101
     print(msg, file=sys.stderr)
82 102
     print('Miniver was not installed', file=sys.stderr)
... ...
@@ -129,6 +149,8 @@ def main():
129 149
     # Write content to local package directory
130 150
     for path, output_path in zip(miniver_paths, output_paths):
131 151
         shutil.copy(path, output_path)
152
+    _write_content(_static_version_template,
153
+                   os.path.join(package_dir, '_static_version.py'))
132 154
     _write_line(_gitattribute_template.format(package_dir=package_dir),
133 155
                 '.gitattributes')
134 156
     _write_line(_init_template.format(package_dir=package_dir),