6
6
skipped if any of the dependencies did fail or has been skipped.
7
7
"""
8
8
9
+ from distutils .cmd import Command as du_cmd
9
10
import distutils .log
10
11
import os
11
12
import os .path
12
13
import re
14
+ import stat
13
15
import string
14
16
from setuptools import setup
15
- import setuptools .command .sdist as st_sdist
17
+ import setuptools .command .build_py
18
+ import setuptools .command .sdist
16
19
try :
17
20
import setuptools_scm
18
21
version = setuptools_scm .get_version ()
26
29
distutils .log .warn ("warning: cannot determine version number" )
27
30
version = "UNKNOWN"
28
31
32
+ doc_string = __doc__
29
33
30
- class sdist (st_sdist .sdist ):
31
- def make_release_tree (self , base_dir , files ):
32
- st_sdist .sdist .make_release_tree (self , base_dir , files )
33
- if not self .dry_run :
34
- src = "pytest_dependency.py"
35
- dest = os .path .join (base_dir , src )
36
- if hasattr (os , 'link' ) and os .path .exists (dest ):
37
- os .unlink (dest )
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 ))
34
+ class copy_file_mixin :
35
+ """Distutils copy_file() mixin.
41
36
37
+ Inject a custom version version of the copy_file() method that
38
+ does some substitutions on the fly into distutils command class
39
+ hierarchy.
40
+ """
41
+ Subst_srcs = {"pytest_dependency.py" }
42
+ Subst = {'DOC' : doc_string , 'VERSION' : version }
43
+ def copy_file (self , infile , outfile , preserve_mode = 1 , preserve_times = 1 ,
44
+ link = None , level = 1 ):
45
+ if infile in self .Subst_srcs :
46
+ fstat = os .stat (infile )
47
+ if os .path .basename (outfile ) == os .path .basename (infile ):
48
+ distutils .log .info ("copying (with substitutions) %s -> %s" ,
49
+ infile , os .path .dirname (outfile ))
50
+ else :
51
+ distutils .log .info ("copying (with substitutions) %s -> %s" ,
52
+ infile , outfile )
53
+ if not self .dry_run :
54
+ if os .path .exists (outfile ):
55
+ os .unlink (outfile )
56
+ with open (infile , "rt" ) as sf , open (outfile , "wt" ) as df :
57
+ df .write (string .Template (sf .read ()).substitute (self .Subst ))
58
+ if preserve_mode :
59
+ os .chmod (outfile , stat .S_IMODE (fstat [stat .ST_MODE ]))
60
+ return (outfile , 1 )
61
+ else :
62
+ # Note: can't use super() with Python 2.
63
+ return du_cmd .copy_file (self , infile , outfile ,
64
+ preserve_mode = preserve_mode ,
65
+ preserve_times = preserve_times ,
66
+ link = link , level = level )
67
+
68
+ class build_py (copy_file_mixin , setuptools .command .build_py .build_py ):
69
+ pass
70
+
71
+ class sdist (copy_file_mixin , setuptools .command .sdist .sdist ):
72
+ pass
42
73
43
74
setup (
44
75
name = 'pytest-dependency' ,
@@ -50,7 +81,7 @@ def make_release_tree(self, base_dir, files):
50
81
maintainer_email = '[email protected] ' ,
51
82
url = 'https://github.com/RKrahl/pytest-dependency' ,
52
83
license = 'Apache Software License 2.0' ,
53
- long_description = __doc__ ,
84
+ long_description = doc_string ,
54
85
project_urls = {
55
86
'Documentation' : 'https://pytest-dependency.readthedocs.io/' ,
56
87
'Source Code' : 'https://github.com/RKrahl/pytest-dependency' ,
@@ -79,5 +110,5 @@ def make_release_tree(self, base_dir, files):
79
110
'dependency = pytest_dependency' ,
80
111
],
81
112
},
82
- cmdclass = {'sdist' : sdist },
113
+ cmdclass = {'build_py' : build_py , ' sdist' : sdist },
83
114
)
0 commit comments