1
- #! /usr/bin/python
2
1
"""pytest-dependency - Manage dependencies of tests
3
2
4
3
This pytest plugin manages dependencies of tests. It allows to mark
5
4
some tests as dependent from other tests. These tests will then be
6
5
skipped if any of the dependencies did fail or has been skipped.
7
6
"""
8
7
9
- import os
10
- import os .path
11
- import re
12
- import stat
13
- import string
14
8
import setuptools
15
- from distutils .cmd import Command as du_cmd
16
- import distutils .command .sdist
17
- import distutils .log
18
9
from setuptools import setup
19
10
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
20
18
try :
21
19
import setuptools_scm
22
20
version = setuptools_scm .get_version ()
27
25
with open (".version" , "rt" ) as f :
28
26
version = f .read ()
29
27
except (OSError , IOError ):
30
- distutils . log .warn ("warning: cannot determine version number" )
28
+ log .warn ("warning: cannot determine version number" )
31
29
version = "UNKNOWN"
32
30
33
- doc_string = __doc__
31
+ docstring = __doc__
34
32
35
33
class copy_file_mixin :
36
34
"""Distutils copy_file() mixin.
@@ -40,81 +38,87 @@ class copy_file_mixin:
40
38
hierarchy.
41
39
"""
42
40
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 ):
46
44
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 )
51
50
else :
52
- distutils . log .info ("copying (with substitutions) %s -> %s" ,
53
- infile , outfile )
51
+ log .info ("copying (with substitutions) %s -> %s" ,
52
+ infile , outfile )
54
53
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 :
58
60
df .write (string .Template (sf .read ()).substitute (self .Subst ))
61
+ if preserve_times :
62
+ os .utime (str (outfile ), (st [ST_ATIME ], st [ST_MTIME ]))
59
63
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 )
62
66
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 )
71
71
72
72
# Note: Do not use setuptools for making the source distribution,
73
73
# rather use the good old distutils instead.
74
74
# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/
75
75
class sdist (copy_file_mixin , distutils .command .sdist .sdist ):
76
76
pass
77
77
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
+
78
84
setup (
79
- name = 'pytest-dependency' ,
80
- version = version ,
81
- description = 'Manage dependencies of tests' ,
82
- author = 'Rolf Krahl' ,
83
-
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" ,
114
109
],
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" ,
118
122
],
119
123
},
120
124
cmdclass = {'build_py' : build_py , 'sdist' : sdist },
0 commit comments