Skip to content

Commit 8cc61f7

Browse files
committed
Create a _meta.py file rather than .version
1 parent b40cda1 commit 8cc61f7

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
*~
33
.cache/
44
__pycache__/
5-
/.version
65
/MANIFEST
6+
/_meta.py
77
/build/
88
/dist/
99
/doc/doctest/

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
include .version
21
include LICENSE.txt
32
include MANIFEST.in
43
include README.rst
4+
include _meta.py
55
include doc/examples/*.py
66
include tests/conftest.py
77
include tests/pytest.ini

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ clean:
1919
rm -rf build
2020

2121
distclean: clean
22+
rm -f MANIFEST _meta.py
2223
rm -rf .cache tests/.cache .pytest_cache tests/.pytest_cache
2324
rm -f *.pyc tests/*.pyc
2425
rm -rf __pycache__ tests/__pycache__
25-
rm -f MANIFEST .version
2626
rm -rf dist
2727
rm -rf pytest_dependency.egg-info
2828
$(MAKE) -C doc distclean
2929

30-
.PHONY: build test sdist doc-html clean distclean
30+
meta:
31+
$(PYTHON) setup.py meta
32+
33+
34+
.PHONY: build test sdist doc-html clean distclean meta

setup.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
try:
1919
import setuptools_scm
2020
version = setuptools_scm.get_version()
21-
with open(".version", "wt") as f:
22-
f.write(version)
2321
except (ImportError, LookupError):
2422
try:
25-
with open(".version", "rt") as f:
26-
version = f.read()
27-
except (OSError, IOError):
23+
from _meta import version
24+
except ImportError:
2825
log.warn("warning: cannot determine version number")
2926
version = "UNKNOWN"
3027

@@ -69,14 +66,38 @@ def copy_file(self, infile, outfile,
6966
not self.force, link,
7067
dry_run=self.dry_run)
7168

69+
class meta(setuptools.Command):
70+
description = "generate meta files"
71+
user_options = []
72+
meta_template = '''
73+
version = "%(version)s"
74+
'''
75+
def initialize_options(self):
76+
pass
77+
def finalize_options(self):
78+
pass
79+
def run(self):
80+
version = self.distribution.get_version()
81+
log.info("version: %s", version)
82+
values = {
83+
'version': version,
84+
}
85+
with Path("_meta.py").open("wt") as f:
86+
print(self.meta_template % values, file=f)
87+
7288
# Note: Do not use setuptools for making the source distribution,
7389
# rather use the good old distutils instead.
7490
# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/
7591
class sdist(copy_file_mixin, distutils.command.sdist.sdist):
76-
pass
92+
def run(self):
93+
self.run_command('meta')
94+
super().run()
7795

7896
class build_py(copy_file_mixin, setuptools.command.build_py.build_py):
79-
pass
97+
def run(self):
98+
self.run_command('meta')
99+
super().run()
100+
80101

81102
with Path("README.rst").open("rt", encoding="utf8") as f:
82103
readme = f.read()
@@ -121,5 +142,5 @@ class build_py(copy_file_mixin, setuptools.command.build_py.build_py):
121142
"dependency = pytest_dependency",
122143
],
123144
},
124-
cmdclass = {'build_py': build_py, 'sdist': sdist},
145+
cmdclass = dict(build_py=build_py, sdist=sdist, meta=meta),
125146
)

0 commit comments

Comments
 (0)