Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/setuptools/command/sdist.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
1 from distutils import log | |
2 import distutils.command.sdist as orig | |
3 import os | |
4 import sys | |
5 import io | |
6 import contextlib | |
7 | |
8 from setuptools.extern import six, ordered_set | |
9 | |
10 from .py36compat import sdist_add_defaults | |
11 | |
12 import pkg_resources | |
13 | |
14 _default_revctrl = list | |
15 | |
16 | |
17 def walk_revctrl(dirname=''): | |
18 """Find all files under revision control""" | |
19 for ep in pkg_resources.iter_entry_points('setuptools.file_finders'): | |
20 for item in ep.load()(dirname): | |
21 yield item | |
22 | |
23 | |
24 class sdist(sdist_add_defaults, orig.sdist): | |
25 """Smart sdist that finds anything supported by revision control""" | |
26 | |
27 user_options = [ | |
28 ('formats=', None, | |
29 "formats for source distribution (comma-separated list)"), | |
30 ('keep-temp', 'k', | |
31 "keep the distribution tree around after creating " + | |
32 "archive file(s)"), | |
33 ('dist-dir=', 'd', | |
34 "directory to put the source distribution archive(s) in " | |
35 "[default: dist]"), | |
36 ] | |
37 | |
38 negative_opt = {} | |
39 | |
40 README_EXTENSIONS = ['', '.rst', '.txt', '.md'] | |
41 READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS) | |
42 | |
43 def run(self): | |
44 self.run_command('egg_info') | |
45 ei_cmd = self.get_finalized_command('egg_info') | |
46 self.filelist = ei_cmd.filelist | |
47 self.filelist.append(os.path.join(ei_cmd.egg_info, 'SOURCES.txt')) | |
48 self.check_readme() | |
49 | |
50 # Run sub commands | |
51 for cmd_name in self.get_sub_commands(): | |
52 self.run_command(cmd_name) | |
53 | |
54 self.make_distribution() | |
55 | |
56 dist_files = getattr(self.distribution, 'dist_files', []) | |
57 for file in self.archive_files: | |
58 data = ('sdist', '', file) | |
59 if data not in dist_files: | |
60 dist_files.append(data) | |
61 | |
62 def initialize_options(self): | |
63 orig.sdist.initialize_options(self) | |
64 | |
65 self._default_to_gztar() | |
66 | |
67 def _default_to_gztar(self): | |
68 # only needed on Python prior to 3.6. | |
69 if sys.version_info >= (3, 6, 0, 'beta', 1): | |
70 return | |
71 self.formats = ['gztar'] | |
72 | |
73 def make_distribution(self): | |
74 """ | |
75 Workaround for #516 | |
76 """ | |
77 with self._remove_os_link(): | |
78 orig.sdist.make_distribution(self) | |
79 | |
80 @staticmethod | |
81 @contextlib.contextmanager | |
82 def _remove_os_link(): | |
83 """ | |
84 In a context, remove and restore os.link if it exists | |
85 """ | |
86 | |
87 class NoValue: | |
88 pass | |
89 | |
90 orig_val = getattr(os, 'link', NoValue) | |
91 try: | |
92 del os.link | |
93 except Exception: | |
94 pass | |
95 try: | |
96 yield | |
97 finally: | |
98 if orig_val is not NoValue: | |
99 setattr(os, 'link', orig_val) | |
100 | |
101 def __read_template_hack(self): | |
102 # This grody hack closes the template file (MANIFEST.in) if an | |
103 # exception occurs during read_template. | |
104 # Doing so prevents an error when easy_install attempts to delete the | |
105 # file. | |
106 try: | |
107 orig.sdist.read_template(self) | |
108 except Exception: | |
109 _, _, tb = sys.exc_info() | |
110 tb.tb_next.tb_frame.f_locals['template'].close() | |
111 raise | |
112 | |
113 # Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle | |
114 # has been fixed, so only override the method if we're using an earlier | |
115 # Python. | |
116 has_leaky_handle = ( | |
117 sys.version_info < (2, 7, 2) | |
118 or (3, 0) <= sys.version_info < (3, 1, 4) | |
119 or (3, 2) <= sys.version_info < (3, 2, 1) | |
120 ) | |
121 if has_leaky_handle: | |
122 read_template = __read_template_hack | |
123 | |
124 def _add_defaults_optional(self): | |
125 if six.PY2: | |
126 sdist_add_defaults._add_defaults_optional(self) | |
127 else: | |
128 super()._add_defaults_optional() | |
129 if os.path.isfile('pyproject.toml'): | |
130 self.filelist.append('pyproject.toml') | |
131 | |
132 def _add_defaults_python(self): | |
133 """getting python files""" | |
134 if self.distribution.has_pure_modules(): | |
135 build_py = self.get_finalized_command('build_py') | |
136 self.filelist.extend(build_py.get_source_files()) | |
137 self._add_data_files(self._safe_data_files(build_py)) | |
138 | |
139 def _safe_data_files(self, build_py): | |
140 """ | |
141 Extracting data_files from build_py is known to cause | |
142 infinite recursion errors when `include_package_data` | |
143 is enabled, so suppress it in that case. | |
144 """ | |
145 if self.distribution.include_package_data: | |
146 return () | |
147 return build_py.data_files | |
148 | |
149 def _add_data_files(self, data_files): | |
150 """ | |
151 Add data files as found in build_py.data_files. | |
152 """ | |
153 self.filelist.extend( | |
154 os.path.join(src_dir, name) | |
155 for _, src_dir, _, filenames in data_files | |
156 for name in filenames | |
157 ) | |
158 | |
159 def _add_defaults_data_files(self): | |
160 try: | |
161 if six.PY2: | |
162 sdist_add_defaults._add_defaults_data_files(self) | |
163 else: | |
164 super()._add_defaults_data_files() | |
165 except TypeError: | |
166 log.warn("data_files contains unexpected objects") | |
167 | |
168 def check_readme(self): | |
169 for f in self.READMES: | |
170 if os.path.exists(f): | |
171 return | |
172 else: | |
173 self.warn( | |
174 "standard file not found: should have one of " + | |
175 ', '.join(self.READMES) | |
176 ) | |
177 | |
178 def make_release_tree(self, base_dir, files): | |
179 orig.sdist.make_release_tree(self, base_dir, files) | |
180 | |
181 # Save any egg_info command line options used to create this sdist | |
182 dest = os.path.join(base_dir, 'setup.cfg') | |
183 if hasattr(os, 'link') and os.path.exists(dest): | |
184 # unlink and re-copy, since it might be hard-linked, and | |
185 # we don't want to change the source version | |
186 os.unlink(dest) | |
187 self.copy_file('setup.cfg', dest) | |
188 | |
189 self.get_finalized_command('egg_info').save_version_info(dest) | |
190 | |
191 def _manifest_is_not_generated(self): | |
192 # check for special comment used in 2.7.1 and higher | |
193 if not os.path.isfile(self.manifest): | |
194 return False | |
195 | |
196 with io.open(self.manifest, 'rb') as fp: | |
197 first_line = fp.readline() | |
198 return (first_line != | |
199 '# file GENERATED by distutils, do NOT edit\n'.encode()) | |
200 | |
201 def read_manifest(self): | |
202 """Read the manifest file (named by 'self.manifest') and use it to | |
203 fill in 'self.filelist', the list of files to include in the source | |
204 distribution. | |
205 """ | |
206 log.info("reading manifest file '%s'", self.manifest) | |
207 manifest = open(self.manifest, 'rb') | |
208 for line in manifest: | |
209 # The manifest must contain UTF-8. See #303. | |
210 if not six.PY2: | |
211 try: | |
212 line = line.decode('UTF-8') | |
213 except UnicodeDecodeError: | |
214 log.warn("%r not UTF-8 decodable -- skipping" % line) | |
215 continue | |
216 # ignore comments and blank lines | |
217 line = line.strip() | |
218 if line.startswith('#') or not line: | |
219 continue | |
220 self.filelist.append(line) | |
221 manifest.close() | |
222 | |
223 def check_license(self): | |
224 """Checks if license_file' or 'license_files' is configured and adds any | |
225 valid paths to 'self.filelist'. | |
226 """ | |
227 | |
228 files = ordered_set.OrderedSet() | |
229 | |
230 opts = self.distribution.get_option_dict('metadata') | |
231 | |
232 # ignore the source of the value | |
233 _, license_file = opts.get('license_file', (None, None)) | |
234 | |
235 if license_file is None: | |
236 log.debug("'license_file' option was not specified") | |
237 else: | |
238 files.add(license_file) | |
239 | |
240 try: | |
241 files.update(self.distribution.metadata.license_files) | |
242 except TypeError: | |
243 log.warn("warning: 'license_files' option is malformed") | |
244 | |
245 for f in files: | |
246 if not os.path.exists(f): | |
247 log.warn( | |
248 "warning: Failed to find the configured license file '%s'", | |
249 f) | |
250 files.remove(f) | |
251 | |
252 self.filelist.extend(files) |