Skip to content

Commit 8f54062

Browse files
committed
Manage the version number with setuptools_scm.
1 parent 9f11015 commit 8f54062

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*~
33
.cache/
44
__pycache__/
5-
/.gitrevision
5+
/.version
66
/MANIFEST
77
/build/
88
/dist/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include .version
12
include LICENSE.txt
23
include MANIFEST.in
34
include README.rst

Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build:
88
test: build
99
PYTHONPATH=$(BUILDDIR)/lib $(PYTHON) -m pytest tests
1010

11-
sdist: .gitrevision
11+
sdist:
1212
$(PYTHON) setup.py sdist
1313

1414
doc-html:
@@ -23,13 +23,10 @@ distclean: clean
2323
rm -rf .cache tests/.cache .pytest_cache tests/.pytest_cache
2424
rm -f *.pyc tests/*.pyc
2525
rm -rf __pycache__ tests/__pycache__
26-
rm -f MANIFEST
26+
rm -f MANIFEST .version
2727
rm -rf dist
2828
rm -rf pytest_dependency.egg-info
2929
$(MAKE) -C doc distclean
3030

31-
.gitrevision:
32-
git describe --always --dirty > .gitrevision
3331

34-
35-
.PHONY: build test sdist doc-html clean distclean .gitrevision
32+
.PHONY: build test sdist doc-html clean distclean

pytest_dependency.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""$DOC"""
22

33
__version__ = "$VERSION"
4-
__revision__ = "$REVISION"
54

65
import pytest
76

setup.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,43 @@
66
skipped if any of the dependencies did fail or has been skipped.
77
"""
88

9-
__version__ = "0.4.0"
10-
9+
import distutils.log
1110
import os
1211
import os.path
1312
import re
13+
import string
1414
from setuptools import setup
1515
import setuptools.command.sdist as st_sdist
16+
try:
17+
import setuptools_scm
18+
version = setuptools_scm.get_version()
19+
with open(".version", "wt") as f:
20+
f.write(version)
21+
except (ImportError, LookupError):
22+
try:
23+
with open(".version", "rt") as f:
24+
version = f.read()
25+
except (OSError, IOError):
26+
distutils.log.warn("warning: cannot determine version number")
27+
version = "UNKNOWN"
1628

1729

18-
def _filter_file(src, dest, subst):
19-
"""Copy src to dest doing substitutions on the fly.
20-
"""
21-
substre = re.compile(r'\$(%s)' % '|'.join(subst.keys()))
22-
def repl(m):
23-
return subst[m.group(1)]
24-
with open(src, "rt") as sf, open(dest, "wt") as df:
25-
while True:
26-
l = sf.readline()
27-
if not l:
28-
break
29-
df.write(re.sub(substre, repl, l))
30-
3130
class sdist(st_sdist.sdist):
3231
def make_release_tree(self, base_dir, files):
3332
st_sdist.sdist.make_release_tree(self, base_dir, files)
3433
if not self.dry_run:
3534
src = "pytest_dependency.py"
3635
dest = os.path.join(base_dir, src)
37-
gitrevfile = ".gitrevision"
3836
if hasattr(os, 'link') and os.path.exists(dest):
3937
os.unlink(dest)
40-
subst = {'DOC': __doc__, 'VERSION': __version__}
41-
if os.path.exists(gitrevfile):
42-
with open(gitrevfile, "rt") as f:
43-
subst['REVISION'] = f.readline().strip()
44-
_filter_file(src, dest, subst)
38+
subst = {'DOC': __doc__, 'VERSION': version}
39+
with open(src, "rt") as sf, open(dest, "wt") as df:
40+
df.write(string.Template(sf.read()).substitute(subst))
4541

4642

4743
setup(
4844
name='pytest-dependency',
49-
version=__version__,
45+
version=version,
5046
description='Manage dependencies of tests',
5147
author='Rolf Krahl',
5248
author_email='[email protected]',

0 commit comments

Comments
 (0)