Skip to content

Commit c30df22

Browse files
committed
Merge branch 'feature/version-number' into develop
2 parents 9f11015 + 8dc90ff commit c30df22

File tree

8 files changed

+45
-40
lines changed

8 files changed

+45
-40
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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ build:
88
test: build
99
PYTHONPATH=$(BUILDDIR)/lib $(PYTHON) -m pytest tests
1010

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

14-
doc-html:
14+
doc-html: .version
1515
$(MAKE) -C doc html
1616

1717
clean:
@@ -23,13 +23,12 @@ 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
31+
.version:
32+
$(PYTHON) setup.py check
3333

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

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ System requirements
2424
+ `setuptools`_.
2525
+ `pytest`_ 3.6.0 or newer.
2626

27+
Optional library packages:
28+
29+
+ `setuptools_scm`_
30+
31+
The version number is managed using this package. All source
32+
distributions add a static text file with the version number and
33+
fall back using that if `setuptools_scm` is not available. So this
34+
package is only needed to build out of the plain development source
35+
tree as cloned from GitHub.
36+
2737

2838
Installation
2939
------------
@@ -79,3 +89,4 @@ permissions and limitations under the License.
7989

8090
.. _setuptools: http://pypi.python.org/pypi/setuptools/
8191
.. _pytest: http://pytest.org/
92+
.. _setuptools_scm: https://github.com/pypa/setuptools_scm/

doc/src/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dev (not yet released)
77

88
Bug fixes and minor changes
99
+ Issue #34: failing test with pytest 4.2.0 and newer.
10+
+ Use setuptools_scm to manage the version number.
1011

1112
0.4 (2018-12-02)
1213
Incompatible changes

doc/src/conf.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import sys, os
1313
import os.path
1414

15-
# Add the top source directory to the module path. This file is
16-
# exec'ed with its directory as cwd. This is "doc/src" relativ to the
17-
# top source directory. So we need to go 2 dirs up.
18-
sys.path.insert(0,os.path.dirname(os.path.dirname(os.getcwd())))
15+
# The top source directory. This file is exec'ed with its directory
16+
# as cwd. This is "doc/src" relativ to the top source directory. So
17+
# we need to go 2 dirs up.
18+
topdir = os.path.dirname(os.path.dirname(os.getcwd()))
1919

2020
# If extensions (or modules to document with autodoc) are in another directory,
2121
# add these directories to sys.path here. If the directory is relative to the
@@ -50,11 +50,9 @@
5050
# The version info for the project you're documenting, acts as replacement for
5151
# |version| and |release|, also used in various other places throughout the
5252
# built documents.
53-
#
54-
# The short X.Y version.
55-
version = '0.4'
56-
# The full version, including alpha/beta/rc tags.
57-
release = '0.4.0'
53+
with open(os.path.join(topdir, ".version"), "rt") as f:
54+
release = f.read()
55+
version = ".".join(release.split(".")[0:2])
5856

5957
# The language for content autogenerated by Sphinx. Refer to documentation
6058
# for a list of supported languages.

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)