Skip to content

Commit b40cda1

Browse files
committed
- General review of the setup script
- Formally drop support for Python 2
1 parent cab2f65 commit b40cda1

File tree

2 files changed

+76
-72
lines changed

2 files changed

+76
-72
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The latest release version can be found `at PyPI`__.
3131
System requirements
3232
-------------------
3333

34-
+ Python 2.7 or 3.4 and newer.
34+
+ Python 3.4 and newer.
3535
+ `setuptools`_.
3636
+ `pytest`_ 3.7.0 or newer.
3737

setup.py

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
#! /usr/bin/python
21
"""pytest-dependency - Manage dependencies of tests
32
43
This pytest plugin manages dependencies of tests. It allows to mark
54
some tests as dependent from other tests. These tests will then be
65
skipped if any of the dependencies did fail or has been skipped.
76
"""
87

9-
import os
10-
import os.path
11-
import re
12-
import stat
13-
import string
148
import setuptools
15-
from distutils.cmd import Command as du_cmd
16-
import distutils.command.sdist
17-
import distutils.log
189
from setuptools import setup
1910
import setuptools.command.build_py
11+
import distutils.command.sdist
12+
import distutils.file_util
13+
from distutils import log
14+
import os
15+
from pathlib import Path
16+
from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE
17+
import string
2018
try:
2119
import setuptools_scm
2220
version = setuptools_scm.get_version()
@@ -27,10 +25,10 @@
2725
with open(".version", "rt") as f:
2826
version = f.read()
2927
except (OSError, IOError):
30-
distutils.log.warn("warning: cannot determine version number")
28+
log.warn("warning: cannot determine version number")
3129
version = "UNKNOWN"
3230

33-
doc_string = __doc__
31+
docstring = __doc__
3432

3533
class copy_file_mixin:
3634
"""Distutils copy_file() mixin.
@@ -40,81 +38,87 @@ class copy_file_mixin:
4038
hierarchy.
4139
"""
4240
Subst_srcs = {"src/pytest_dependency.py"}
43-
Subst = {'DOC': doc_string, 'VERSION': version}
44-
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
45-
link=None, level=1):
41+
Subst = {'DOC': docstring, 'VERSION': version}
42+
def copy_file(self, infile, outfile,
43+
preserve_mode=1, preserve_times=1, link=None, level=1):
4644
if infile in self.Subst_srcs:
47-
fstat = os.stat(infile)
48-
if os.path.basename(outfile) == os.path.basename(infile):
49-
distutils.log.info("copying (with substitutions) %s -> %s",
50-
infile, os.path.dirname(outfile))
45+
infile = Path(infile)
46+
outfile = Path(outfile)
47+
if outfile.name == infile.name:
48+
log.info("copying (with substitutions) %s -> %s",
49+
infile, outfile.parent)
5150
else:
52-
distutils.log.info("copying (with substitutions) %s -> %s",
53-
infile, outfile)
51+
log.info("copying (with substitutions) %s -> %s",
52+
infile, outfile)
5453
if not self.dry_run:
55-
if os.path.exists(outfile):
56-
os.unlink(outfile)
57-
with open(infile, "rt") as sf, open(outfile, "wt") as df:
54+
st = infile.stat()
55+
try:
56+
outfile.unlink()
57+
except FileNotFoundError:
58+
pass
59+
with infile.open("rt") as sf, outfile.open("wt") as df:
5860
df.write(string.Template(sf.read()).substitute(self.Subst))
61+
if preserve_times:
62+
os.utime(str(outfile), (st[ST_ATIME], st[ST_MTIME]))
5963
if preserve_mode:
60-
os.chmod(outfile, stat.S_IMODE(fstat[stat.ST_MODE]))
61-
return (outfile, 1)
64+
outfile.chmod(S_IMODE(st[ST_MODE]))
65+
return (str(outfile), 1)
6266
else:
63-
# Note: can't use super() with Python 2.
64-
return du_cmd.copy_file(self, infile, outfile,
65-
preserve_mode=preserve_mode,
66-
preserve_times=preserve_times,
67-
link=link, level=level)
68-
69-
class build_py(copy_file_mixin, setuptools.command.build_py.build_py):
70-
pass
67+
return distutils.file_util.copy_file(infile, outfile,
68+
preserve_mode, preserve_times,
69+
not self.force, link,
70+
dry_run=self.dry_run)
7171

7272
# Note: Do not use setuptools for making the source distribution,
7373
# rather use the good old distutils instead.
7474
# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/
7575
class sdist(copy_file_mixin, distutils.command.sdist.sdist):
7676
pass
7777

78+
class build_py(copy_file_mixin, setuptools.command.build_py.build_py):
79+
pass
80+
81+
with Path("README.rst").open("rt", encoding="utf8") as f:
82+
readme = f.read()
83+
7884
setup(
79-
name='pytest-dependency',
80-
version=version,
81-
description='Manage dependencies of tests',
82-
author='Rolf Krahl',
83-
author_email='[email protected]',
84-
maintainer='Rolf Krahl',
85-
maintainer_email='[email protected]',
86-
url='https://github.com/RKrahl/pytest-dependency',
87-
license='Apache Software License 2.0',
88-
long_description=doc_string,
89-
project_urls={
90-
'Documentation': 'https://pytest-dependency.readthedocs.io/',
91-
'Source Code': 'https://github.com/RKrahl/pytest-dependency',
92-
},
93-
package_dir = {'': 'src'},
94-
py_modules=['pytest_dependency'],
95-
install_requires=['pytest >= 3.7.0'],
96-
classifiers=[
97-
'Development Status :: 4 - Beta',
98-
'Framework :: Pytest',
99-
'Intended Audience :: Developers',
100-
'Topic :: Software Development :: Testing',
101-
'Programming Language :: Python',
102-
'Programming Language :: Python :: 2',
103-
'Programming Language :: Python :: 2.7',
104-
'Programming Language :: Python :: 3',
105-
'Programming Language :: Python :: 3.4',
106-
'Programming Language :: Python :: 3.5',
107-
'Programming Language :: Python :: 3.6',
108-
'Programming Language :: Python :: 3.7',
109-
'Programming Language :: Python :: 3.8',
110-
'Programming Language :: Python :: 3.9',
111-
'Programming Language :: Python :: 3.10',
112-
'Operating System :: OS Independent',
113-
'License :: OSI Approved :: Apache Software License',
85+
name = "pytest-dependency",
86+
version = version,
87+
description = "Manage dependencies of tests",
88+
long_description = readme,
89+
long_description_content_type = "text/x-rst",
90+
url = "https://github.com/RKrahl/pytest-dependency",
91+
author = "Rolf Krahl",
92+
author_email = "[email protected]",
93+
license = "Apache-2.0",
94+
classifiers = [
95+
"Development Status :: 4 - Beta",
96+
"Framework :: Pytest",
97+
"Intended Audience :: Developers",
98+
"License :: OSI Approved :: Apache Software License",
99+
"Operating System :: OS Independent",
100+
"Programming Language :: Python",
101+
"Programming Language :: Python :: 3.4",
102+
"Programming Language :: Python :: 3.5",
103+
"Programming Language :: Python :: 3.6",
104+
"Programming Language :: Python :: 3.7",
105+
"Programming Language :: Python :: 3.8",
106+
"Programming Language :: Python :: 3.9",
107+
"Programming Language :: Python :: 3.10",
108+
"Topic :: Software Development :: Testing",
114109
],
115-
entry_points={
116-
'pytest11': [
117-
'dependency = pytest_dependency',
110+
project_urls = dict(
111+
Documentation="https://pytest-dependency.readthedocs.io/",
112+
Source="https://github.com/RKrahl/pytest-dependency",
113+
Download="https://github.com/RKrahl/pytest-dependency/releases/latest",
114+
),
115+
package_dir = {"": "src"},
116+
python_requires = ">=3.4",
117+
py_modules = ["pytest_dependency"],
118+
install_requires = ["setuptools", "pytest >= 3.7.0"],
119+
entry_points = {
120+
"pytest11": [
121+
"dependency = pytest_dependency",
118122
],
119123
},
120124
cmdclass = {'build_py': build_py, 'sdist': sdist},

0 commit comments

Comments
 (0)