Skip to content

Commit 3deb25f

Browse files
committed
Substitute docstring and version from setup.py into pytest_dependency.py.
1 parent 7691ce8 commit 3deb25f

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

pytest_dependency.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
"""pytest-dependency - Manage dependencies of tests
1+
"""$DOC"""
22

3-
This pytest plugin manages dependencies of tests. It allows to mark
4-
some tests as dependent from other tests. These tests will then be
5-
skipped if any of the dependencies did fail or has been skipped.
6-
"""
3+
__version__ = "$VERSION"
74

85
import pytest
96

10-
__version__ = "0.2"
11-
127

138
class DependencyItemStatus(object):
149
"""Status of a test item in a dependency manager.

setup.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,48 @@
66
skipped if any of the dependencies did fail or has been skipped.
77
"""
88

9+
__version__ = "0.2"
10+
911
import sys
1012
if sys.version_info < (2, 7):
1113
raise RuntimeError("You are using Python %s.\n"
1214
"Please apply python2_6.patch first."
1315
% sys.version.split()[0])
16+
import os
17+
import os.path
18+
import re
1419
from setuptools import setup
20+
import setuptools.command.sdist as st_sdist
21+
22+
23+
def _filter_file(src, dest, subst):
24+
"""Copy src to dest doing substitutions on the fly.
25+
"""
26+
substre = re.compile(r'\$(%s)' % '|'.join(subst.keys()))
27+
def repl(m):
28+
return subst[m.group(1)]
29+
with open(src, "rt") as sf, open(dest, "wt") as df:
30+
while True:
31+
l = sf.readline()
32+
if not l:
33+
break
34+
df.write(re.sub(substre, repl, l))
35+
36+
class sdist(st_sdist.sdist):
37+
def make_release_tree(self, base_dir, files):
38+
st_sdist.sdist.make_release_tree(self, base_dir, files)
39+
if not self.dry_run:
40+
src = "pytest_dependency.py"
41+
dest = os.path.join(base_dir, src)
42+
if hasattr(os, 'link') and os.path.exists(dest):
43+
os.unlink(dest)
44+
subst = {'DOC': __doc__, 'VERSION': __version__}
45+
_filter_file(src, dest, subst)
1546

1647

1748
setup(
1849
name='pytest-dependency',
19-
version='0.2',
50+
version=__version__,
2051
description='Manage dependencies of tests',
2152
author='Rolf Krahl',
2253
author_email='[email protected]',
@@ -51,4 +82,5 @@
5182
'dependency = pytest_dependency',
5283
],
5384
},
85+
cmdclass = {'sdist': sdist},
5486
)

0 commit comments

Comments
 (0)