1 | n/a | """distutils.command.sdist |
---|
2 | n/a | |
---|
3 | n/a | Implements the Distutils 'sdist' command (create a source distribution).""" |
---|
4 | n/a | |
---|
5 | n/a | import os |
---|
6 | n/a | import sys |
---|
7 | n/a | from glob import glob |
---|
8 | n/a | from warnings import warn |
---|
9 | n/a | |
---|
10 | n/a | from distutils.core import Command |
---|
11 | n/a | from distutils import dir_util |
---|
12 | n/a | from distutils import file_util |
---|
13 | n/a | from distutils import archive_util |
---|
14 | n/a | from distutils.text_file import TextFile |
---|
15 | n/a | from distutils.filelist import FileList |
---|
16 | n/a | from distutils import log |
---|
17 | n/a | from distutils.util import convert_path |
---|
18 | n/a | from distutils.errors import DistutilsTemplateError, DistutilsOptionError |
---|
19 | n/a | |
---|
20 | n/a | |
---|
21 | n/a | def show_formats(): |
---|
22 | n/a | """Print all possible values for the 'formats' option (used by |
---|
23 | n/a | the "--help-formats" command-line option). |
---|
24 | n/a | """ |
---|
25 | n/a | from distutils.fancy_getopt import FancyGetopt |
---|
26 | n/a | from distutils.archive_util import ARCHIVE_FORMATS |
---|
27 | n/a | formats = [] |
---|
28 | n/a | for format in ARCHIVE_FORMATS.keys(): |
---|
29 | n/a | formats.append(("formats=" + format, None, |
---|
30 | n/a | ARCHIVE_FORMATS[format][2])) |
---|
31 | n/a | formats.sort() |
---|
32 | n/a | FancyGetopt(formats).print_help( |
---|
33 | n/a | "List of available source distribution formats:") |
---|
34 | n/a | |
---|
35 | n/a | |
---|
36 | n/a | class sdist(Command): |
---|
37 | n/a | |
---|
38 | n/a | description = "create a source distribution (tarball, zip file, etc.)" |
---|
39 | n/a | |
---|
40 | n/a | def checking_metadata(self): |
---|
41 | n/a | """Callable used for the check sub-command. |
---|
42 | n/a | |
---|
43 | n/a | Placed here so user_options can view it""" |
---|
44 | n/a | return self.metadata_check |
---|
45 | n/a | |
---|
46 | n/a | user_options = [ |
---|
47 | n/a | ('template=', 't', |
---|
48 | n/a | "name of manifest template file [default: MANIFEST.in]"), |
---|
49 | n/a | ('manifest=', 'm', |
---|
50 | n/a | "name of manifest file [default: MANIFEST]"), |
---|
51 | n/a | ('use-defaults', None, |
---|
52 | n/a | "include the default file set in the manifest " |
---|
53 | n/a | "[default; disable with --no-defaults]"), |
---|
54 | n/a | ('no-defaults', None, |
---|
55 | n/a | "don't include the default file set"), |
---|
56 | n/a | ('prune', None, |
---|
57 | n/a | "specifically exclude files/directories that should not be " |
---|
58 | n/a | "distributed (build tree, RCS/CVS dirs, etc.) " |
---|
59 | n/a | "[default; disable with --no-prune]"), |
---|
60 | n/a | ('no-prune', None, |
---|
61 | n/a | "don't automatically exclude anything"), |
---|
62 | n/a | ('manifest-only', 'o', |
---|
63 | n/a | "just regenerate the manifest and then stop " |
---|
64 | n/a | "(implies --force-manifest)"), |
---|
65 | n/a | ('force-manifest', 'f', |
---|
66 | n/a | "forcibly regenerate the manifest and carry on as usual. " |
---|
67 | n/a | "Deprecated: now the manifest is always regenerated."), |
---|
68 | n/a | ('formats=', None, |
---|
69 | n/a | "formats for source distribution (comma-separated list)"), |
---|
70 | n/a | ('keep-temp', 'k', |
---|
71 | n/a | "keep the distribution tree around after creating " + |
---|
72 | n/a | "archive file(s)"), |
---|
73 | n/a | ('dist-dir=', 'd', |
---|
74 | n/a | "directory to put the source distribution archive(s) in " |
---|
75 | n/a | "[default: dist]"), |
---|
76 | n/a | ('metadata-check', None, |
---|
77 | n/a | "Ensure that all required elements of meta-data " |
---|
78 | n/a | "are supplied. Warn if any missing. [default]"), |
---|
79 | n/a | ('owner=', 'u', |
---|
80 | n/a | "Owner name used when creating a tar file [default: current user]"), |
---|
81 | n/a | ('group=', 'g', |
---|
82 | n/a | "Group name used when creating a tar file [default: current group]"), |
---|
83 | n/a | ] |
---|
84 | n/a | |
---|
85 | n/a | boolean_options = ['use-defaults', 'prune', |
---|
86 | n/a | 'manifest-only', 'force-manifest', |
---|
87 | n/a | 'keep-temp', 'metadata-check'] |
---|
88 | n/a | |
---|
89 | n/a | help_options = [ |
---|
90 | n/a | ('help-formats', None, |
---|
91 | n/a | "list available distribution formats", show_formats), |
---|
92 | n/a | ] |
---|
93 | n/a | |
---|
94 | n/a | negative_opt = {'no-defaults': 'use-defaults', |
---|
95 | n/a | 'no-prune': 'prune' } |
---|
96 | n/a | |
---|
97 | n/a | sub_commands = [('check', checking_metadata)] |
---|
98 | n/a | |
---|
99 | n/a | READMES = 'README', 'README.txt' |
---|
100 | n/a | |
---|
101 | n/a | def initialize_options(self): |
---|
102 | n/a | # 'template' and 'manifest' are, respectively, the names of |
---|
103 | n/a | # the manifest template and manifest file. |
---|
104 | n/a | self.template = None |
---|
105 | n/a | self.manifest = None |
---|
106 | n/a | |
---|
107 | n/a | # 'use_defaults': if true, we will include the default file set |
---|
108 | n/a | # in the manifest |
---|
109 | n/a | self.use_defaults = 1 |
---|
110 | n/a | self.prune = 1 |
---|
111 | n/a | |
---|
112 | n/a | self.manifest_only = 0 |
---|
113 | n/a | self.force_manifest = 0 |
---|
114 | n/a | |
---|
115 | n/a | self.formats = ['gztar'] |
---|
116 | n/a | self.keep_temp = 0 |
---|
117 | n/a | self.dist_dir = None |
---|
118 | n/a | |
---|
119 | n/a | self.archive_files = None |
---|
120 | n/a | self.metadata_check = 1 |
---|
121 | n/a | self.owner = None |
---|
122 | n/a | self.group = None |
---|
123 | n/a | |
---|
124 | n/a | def finalize_options(self): |
---|
125 | n/a | if self.manifest is None: |
---|
126 | n/a | self.manifest = "MANIFEST" |
---|
127 | n/a | if self.template is None: |
---|
128 | n/a | self.template = "MANIFEST.in" |
---|
129 | n/a | |
---|
130 | n/a | self.ensure_string_list('formats') |
---|
131 | n/a | |
---|
132 | n/a | bad_format = archive_util.check_archive_formats(self.formats) |
---|
133 | n/a | if bad_format: |
---|
134 | n/a | raise DistutilsOptionError( |
---|
135 | n/a | "unknown archive format '%s'" % bad_format) |
---|
136 | n/a | |
---|
137 | n/a | if self.dist_dir is None: |
---|
138 | n/a | self.dist_dir = "dist" |
---|
139 | n/a | |
---|
140 | n/a | def run(self): |
---|
141 | n/a | # 'filelist' contains the list of files that will make up the |
---|
142 | n/a | # manifest |
---|
143 | n/a | self.filelist = FileList() |
---|
144 | n/a | |
---|
145 | n/a | # Run sub commands |
---|
146 | n/a | for cmd_name in self.get_sub_commands(): |
---|
147 | n/a | self.run_command(cmd_name) |
---|
148 | n/a | |
---|
149 | n/a | # Do whatever it takes to get the list of files to process |
---|
150 | n/a | # (process the manifest template, read an existing manifest, |
---|
151 | n/a | # whatever). File list is accumulated in 'self.filelist'. |
---|
152 | n/a | self.get_file_list() |
---|
153 | n/a | |
---|
154 | n/a | # If user just wanted us to regenerate the manifest, stop now. |
---|
155 | n/a | if self.manifest_only: |
---|
156 | n/a | return |
---|
157 | n/a | |
---|
158 | n/a | # Otherwise, go ahead and create the source distribution tarball, |
---|
159 | n/a | # or zipfile, or whatever. |
---|
160 | n/a | self.make_distribution() |
---|
161 | n/a | |
---|
162 | n/a | def check_metadata(self): |
---|
163 | n/a | """Deprecated API.""" |
---|
164 | n/a | warn("distutils.command.sdist.check_metadata is deprecated, \ |
---|
165 | n/a | use the check command instead", PendingDeprecationWarning) |
---|
166 | n/a | check = self.distribution.get_command_obj('check') |
---|
167 | n/a | check.ensure_finalized() |
---|
168 | n/a | check.run() |
---|
169 | n/a | |
---|
170 | n/a | def get_file_list(self): |
---|
171 | n/a | """Figure out the list of files to include in the source |
---|
172 | n/a | distribution, and put it in 'self.filelist'. This might involve |
---|
173 | n/a | reading the manifest template (and writing the manifest), or just |
---|
174 | n/a | reading the manifest, or just using the default file set -- it all |
---|
175 | n/a | depends on the user's options. |
---|
176 | n/a | """ |
---|
177 | n/a | # new behavior when using a template: |
---|
178 | n/a | # the file list is recalculated every time because |
---|
179 | n/a | # even if MANIFEST.in or setup.py are not changed |
---|
180 | n/a | # the user might have added some files in the tree that |
---|
181 | n/a | # need to be included. |
---|
182 | n/a | # |
---|
183 | n/a | # This makes --force the default and only behavior with templates. |
---|
184 | n/a | template_exists = os.path.isfile(self.template) |
---|
185 | n/a | if not template_exists and self._manifest_is_not_generated(): |
---|
186 | n/a | self.read_manifest() |
---|
187 | n/a | self.filelist.sort() |
---|
188 | n/a | self.filelist.remove_duplicates() |
---|
189 | n/a | return |
---|
190 | n/a | |
---|
191 | n/a | if not template_exists: |
---|
192 | n/a | self.warn(("manifest template '%s' does not exist " + |
---|
193 | n/a | "(using default file list)") % |
---|
194 | n/a | self.template) |
---|
195 | n/a | self.filelist.findall() |
---|
196 | n/a | |
---|
197 | n/a | if self.use_defaults: |
---|
198 | n/a | self.add_defaults() |
---|
199 | n/a | |
---|
200 | n/a | if template_exists: |
---|
201 | n/a | self.read_template() |
---|
202 | n/a | |
---|
203 | n/a | if self.prune: |
---|
204 | n/a | self.prune_file_list() |
---|
205 | n/a | |
---|
206 | n/a | self.filelist.sort() |
---|
207 | n/a | self.filelist.remove_duplicates() |
---|
208 | n/a | self.write_manifest() |
---|
209 | n/a | |
---|
210 | n/a | def add_defaults(self): |
---|
211 | n/a | """Add all the default files to self.filelist: |
---|
212 | n/a | - README or README.txt |
---|
213 | n/a | - setup.py |
---|
214 | n/a | - test/test*.py |
---|
215 | n/a | - all pure Python modules mentioned in setup script |
---|
216 | n/a | - all files pointed by package_data (build_py) |
---|
217 | n/a | - all files defined in data_files. |
---|
218 | n/a | - all files defined as scripts. |
---|
219 | n/a | - all C sources listed as part of extensions or C libraries |
---|
220 | n/a | in the setup script (doesn't catch C headers!) |
---|
221 | n/a | Warns if (README or README.txt) or setup.py are missing; everything |
---|
222 | n/a | else is optional. |
---|
223 | n/a | """ |
---|
224 | n/a | self._add_defaults_standards() |
---|
225 | n/a | self._add_defaults_optional() |
---|
226 | n/a | self._add_defaults_python() |
---|
227 | n/a | self._add_defaults_data_files() |
---|
228 | n/a | self._add_defaults_ext() |
---|
229 | n/a | self._add_defaults_c_libs() |
---|
230 | n/a | self._add_defaults_scripts() |
---|
231 | n/a | |
---|
232 | n/a | @staticmethod |
---|
233 | n/a | def _cs_path_exists(fspath): |
---|
234 | n/a | """ |
---|
235 | n/a | Case-sensitive path existence check |
---|
236 | n/a | |
---|
237 | n/a | >>> sdist._cs_path_exists(__file__) |
---|
238 | n/a | True |
---|
239 | n/a | >>> sdist._cs_path_exists(__file__.upper()) |
---|
240 | n/a | False |
---|
241 | n/a | """ |
---|
242 | n/a | if not os.path.exists(fspath): |
---|
243 | n/a | return False |
---|
244 | n/a | # make absolute so we always have a directory |
---|
245 | n/a | abspath = os.path.abspath(fspath) |
---|
246 | n/a | directory, filename = os.path.split(abspath) |
---|
247 | n/a | return filename in os.listdir(directory) |
---|
248 | n/a | |
---|
249 | n/a | def _add_defaults_standards(self): |
---|
250 | n/a | standards = [self.READMES, self.distribution.script_name] |
---|
251 | n/a | for fn in standards: |
---|
252 | n/a | if isinstance(fn, tuple): |
---|
253 | n/a | alts = fn |
---|
254 | n/a | got_it = False |
---|
255 | n/a | for fn in alts: |
---|
256 | n/a | if self._cs_path_exists(fn): |
---|
257 | n/a | got_it = True |
---|
258 | n/a | self.filelist.append(fn) |
---|
259 | n/a | break |
---|
260 | n/a | |
---|
261 | n/a | if not got_it: |
---|
262 | n/a | self.warn("standard file not found: should have one of " + |
---|
263 | n/a | ', '.join(alts)) |
---|
264 | n/a | else: |
---|
265 | n/a | if self._cs_path_exists(fn): |
---|
266 | n/a | self.filelist.append(fn) |
---|
267 | n/a | else: |
---|
268 | n/a | self.warn("standard file '%s' not found" % fn) |
---|
269 | n/a | |
---|
270 | n/a | def _add_defaults_optional(self): |
---|
271 | n/a | optional = ['test/test*.py', 'setup.cfg'] |
---|
272 | n/a | for pattern in optional: |
---|
273 | n/a | files = filter(os.path.isfile, glob(pattern)) |
---|
274 | n/a | self.filelist.extend(files) |
---|
275 | n/a | |
---|
276 | n/a | def _add_defaults_python(self): |
---|
277 | n/a | # build_py is used to get: |
---|
278 | n/a | # - python modules |
---|
279 | n/a | # - files defined in package_data |
---|
280 | n/a | build_py = self.get_finalized_command('build_py') |
---|
281 | n/a | |
---|
282 | n/a | # getting python files |
---|
283 | n/a | if self.distribution.has_pure_modules(): |
---|
284 | n/a | self.filelist.extend(build_py.get_source_files()) |
---|
285 | n/a | |
---|
286 | n/a | # getting package_data files |
---|
287 | n/a | # (computed in build_py.data_files by build_py.finalize_options) |
---|
288 | n/a | for pkg, src_dir, build_dir, filenames in build_py.data_files: |
---|
289 | n/a | for filename in filenames: |
---|
290 | n/a | self.filelist.append(os.path.join(src_dir, filename)) |
---|
291 | n/a | |
---|
292 | n/a | def _add_defaults_data_files(self): |
---|
293 | n/a | # getting distribution.data_files |
---|
294 | n/a | if self.distribution.has_data_files(): |
---|
295 | n/a | for item in self.distribution.data_files: |
---|
296 | n/a | if isinstance(item, str): |
---|
297 | n/a | # plain file |
---|
298 | n/a | item = convert_path(item) |
---|
299 | n/a | if os.path.isfile(item): |
---|
300 | n/a | self.filelist.append(item) |
---|
301 | n/a | else: |
---|
302 | n/a | # a (dirname, filenames) tuple |
---|
303 | n/a | dirname, filenames = item |
---|
304 | n/a | for f in filenames: |
---|
305 | n/a | f = convert_path(f) |
---|
306 | n/a | if os.path.isfile(f): |
---|
307 | n/a | self.filelist.append(f) |
---|
308 | n/a | |
---|
309 | n/a | def _add_defaults_ext(self): |
---|
310 | n/a | if self.distribution.has_ext_modules(): |
---|
311 | n/a | build_ext = self.get_finalized_command('build_ext') |
---|
312 | n/a | self.filelist.extend(build_ext.get_source_files()) |
---|
313 | n/a | |
---|
314 | n/a | def _add_defaults_c_libs(self): |
---|
315 | n/a | if self.distribution.has_c_libraries(): |
---|
316 | n/a | build_clib = self.get_finalized_command('build_clib') |
---|
317 | n/a | self.filelist.extend(build_clib.get_source_files()) |
---|
318 | n/a | |
---|
319 | n/a | def _add_defaults_scripts(self): |
---|
320 | n/a | if self.distribution.has_scripts(): |
---|
321 | n/a | build_scripts = self.get_finalized_command('build_scripts') |
---|
322 | n/a | self.filelist.extend(build_scripts.get_source_files()) |
---|
323 | n/a | |
---|
324 | n/a | def read_template(self): |
---|
325 | n/a | """Read and parse manifest template file named by self.template. |
---|
326 | n/a | |
---|
327 | n/a | (usually "MANIFEST.in") The parsing and processing is done by |
---|
328 | n/a | 'self.filelist', which updates itself accordingly. |
---|
329 | n/a | """ |
---|
330 | n/a | log.info("reading manifest template '%s'", self.template) |
---|
331 | n/a | template = TextFile(self.template, strip_comments=1, skip_blanks=1, |
---|
332 | n/a | join_lines=1, lstrip_ws=1, rstrip_ws=1, |
---|
333 | n/a | collapse_join=1) |
---|
334 | n/a | |
---|
335 | n/a | try: |
---|
336 | n/a | while True: |
---|
337 | n/a | line = template.readline() |
---|
338 | n/a | if line is None: # end of file |
---|
339 | n/a | break |
---|
340 | n/a | |
---|
341 | n/a | try: |
---|
342 | n/a | self.filelist.process_template_line(line) |
---|
343 | n/a | # the call above can raise a DistutilsTemplateError for |
---|
344 | n/a | # malformed lines, or a ValueError from the lower-level |
---|
345 | n/a | # convert_path function |
---|
346 | n/a | except (DistutilsTemplateError, ValueError) as msg: |
---|
347 | n/a | self.warn("%s, line %d: %s" % (template.filename, |
---|
348 | n/a | template.current_line, |
---|
349 | n/a | msg)) |
---|
350 | n/a | finally: |
---|
351 | n/a | template.close() |
---|
352 | n/a | |
---|
353 | n/a | def prune_file_list(self): |
---|
354 | n/a | """Prune off branches that might slip into the file list as created |
---|
355 | n/a | by 'read_template()', but really don't belong there: |
---|
356 | n/a | * the build tree (typically "build") |
---|
357 | n/a | * the release tree itself (only an issue if we ran "sdist" |
---|
358 | n/a | previously with --keep-temp, or it aborted) |
---|
359 | n/a | * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories |
---|
360 | n/a | """ |
---|
361 | n/a | build = self.get_finalized_command('build') |
---|
362 | n/a | base_dir = self.distribution.get_fullname() |
---|
363 | n/a | |
---|
364 | n/a | self.filelist.exclude_pattern(None, prefix=build.build_base) |
---|
365 | n/a | self.filelist.exclude_pattern(None, prefix=base_dir) |
---|
366 | n/a | |
---|
367 | n/a | if sys.platform == 'win32': |
---|
368 | n/a | seps = r'/|\\' |
---|
369 | n/a | else: |
---|
370 | n/a | seps = '/' |
---|
371 | n/a | |
---|
372 | n/a | vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr', |
---|
373 | n/a | '_darcs'] |
---|
374 | n/a | vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps) |
---|
375 | n/a | self.filelist.exclude_pattern(vcs_ptrn, is_regex=1) |
---|
376 | n/a | |
---|
377 | n/a | def write_manifest(self): |
---|
378 | n/a | """Write the file list in 'self.filelist' (presumably as filled in |
---|
379 | n/a | by 'add_defaults()' and 'read_template()') to the manifest file |
---|
380 | n/a | named by 'self.manifest'. |
---|
381 | n/a | """ |
---|
382 | n/a | if self._manifest_is_not_generated(): |
---|
383 | n/a | log.info("not writing to manually maintained " |
---|
384 | n/a | "manifest file '%s'" % self.manifest) |
---|
385 | n/a | return |
---|
386 | n/a | |
---|
387 | n/a | content = self.filelist.files[:] |
---|
388 | n/a | content.insert(0, '# file GENERATED by distutils, do NOT edit') |
---|
389 | n/a | self.execute(file_util.write_file, (self.manifest, content), |
---|
390 | n/a | "writing manifest file '%s'" % self.manifest) |
---|
391 | n/a | |
---|
392 | n/a | def _manifest_is_not_generated(self): |
---|
393 | n/a | # check for special comment used in 3.1.3 and higher |
---|
394 | n/a | if not os.path.isfile(self.manifest): |
---|
395 | n/a | return False |
---|
396 | n/a | |
---|
397 | n/a | fp = open(self.manifest) |
---|
398 | n/a | try: |
---|
399 | n/a | first_line = fp.readline() |
---|
400 | n/a | finally: |
---|
401 | n/a | fp.close() |
---|
402 | n/a | return first_line != '# file GENERATED by distutils, do NOT edit\n' |
---|
403 | n/a | |
---|
404 | n/a | def read_manifest(self): |
---|
405 | n/a | """Read the manifest file (named by 'self.manifest') and use it to |
---|
406 | n/a | fill in 'self.filelist', the list of files to include in the source |
---|
407 | n/a | distribution. |
---|
408 | n/a | """ |
---|
409 | n/a | log.info("reading manifest file '%s'", self.manifest) |
---|
410 | n/a | manifest = open(self.manifest) |
---|
411 | n/a | for line in manifest: |
---|
412 | n/a | # ignore comments and blank lines |
---|
413 | n/a | line = line.strip() |
---|
414 | n/a | if line.startswith('#') or not line: |
---|
415 | n/a | continue |
---|
416 | n/a | self.filelist.append(line) |
---|
417 | n/a | manifest.close() |
---|
418 | n/a | |
---|
419 | n/a | def make_release_tree(self, base_dir, files): |
---|
420 | n/a | """Create the directory tree that will become the source |
---|
421 | n/a | distribution archive. All directories implied by the filenames in |
---|
422 | n/a | 'files' are created under 'base_dir', and then we hard link or copy |
---|
423 | n/a | (if hard linking is unavailable) those files into place. |
---|
424 | n/a | Essentially, this duplicates the developer's source tree, but in a |
---|
425 | n/a | directory named after the distribution, containing only the files |
---|
426 | n/a | to be distributed. |
---|
427 | n/a | """ |
---|
428 | n/a | # Create all the directories under 'base_dir' necessary to |
---|
429 | n/a | # put 'files' there; the 'mkpath()' is just so we don't die |
---|
430 | n/a | # if the manifest happens to be empty. |
---|
431 | n/a | self.mkpath(base_dir) |
---|
432 | n/a | dir_util.create_tree(base_dir, files, dry_run=self.dry_run) |
---|
433 | n/a | |
---|
434 | n/a | # And walk over the list of files, either making a hard link (if |
---|
435 | n/a | # os.link exists) to each one that doesn't already exist in its |
---|
436 | n/a | # corresponding location under 'base_dir', or copying each file |
---|
437 | n/a | # that's out-of-date in 'base_dir'. (Usually, all files will be |
---|
438 | n/a | # out-of-date, because by default we blow away 'base_dir' when |
---|
439 | n/a | # we're done making the distribution archives.) |
---|
440 | n/a | |
---|
441 | n/a | if hasattr(os, 'link'): # can make hard links on this system |
---|
442 | n/a | link = 'hard' |
---|
443 | n/a | msg = "making hard links in %s..." % base_dir |
---|
444 | n/a | else: # nope, have to copy |
---|
445 | n/a | link = None |
---|
446 | n/a | msg = "copying files to %s..." % base_dir |
---|
447 | n/a | |
---|
448 | n/a | if not files: |
---|
449 | n/a | log.warn("no files to distribute -- empty manifest?") |
---|
450 | n/a | else: |
---|
451 | n/a | log.info(msg) |
---|
452 | n/a | for file in files: |
---|
453 | n/a | if not os.path.isfile(file): |
---|
454 | n/a | log.warn("'%s' not a regular file -- skipping", file) |
---|
455 | n/a | else: |
---|
456 | n/a | dest = os.path.join(base_dir, file) |
---|
457 | n/a | self.copy_file(file, dest, link=link) |
---|
458 | n/a | |
---|
459 | n/a | self.distribution.metadata.write_pkg_info(base_dir) |
---|
460 | n/a | |
---|
461 | n/a | def make_distribution(self): |
---|
462 | n/a | """Create the source distribution(s). First, we create the release |
---|
463 | n/a | tree with 'make_release_tree()'; then, we create all required |
---|
464 | n/a | archive files (according to 'self.formats') from the release tree. |
---|
465 | n/a | Finally, we clean up by blowing away the release tree (unless |
---|
466 | n/a | 'self.keep_temp' is true). The list of archive files created is |
---|
467 | n/a | stored so it can be retrieved later by 'get_archive_files()'. |
---|
468 | n/a | """ |
---|
469 | n/a | # Don't warn about missing meta-data here -- should be (and is!) |
---|
470 | n/a | # done elsewhere. |
---|
471 | n/a | base_dir = self.distribution.get_fullname() |
---|
472 | n/a | base_name = os.path.join(self.dist_dir, base_dir) |
---|
473 | n/a | |
---|
474 | n/a | self.make_release_tree(base_dir, self.filelist.files) |
---|
475 | n/a | archive_files = [] # remember names of files we create |
---|
476 | n/a | # tar archive must be created last to avoid overwrite and remove |
---|
477 | n/a | if 'tar' in self.formats: |
---|
478 | n/a | self.formats.append(self.formats.pop(self.formats.index('tar'))) |
---|
479 | n/a | |
---|
480 | n/a | for fmt in self.formats: |
---|
481 | n/a | file = self.make_archive(base_name, fmt, base_dir=base_dir, |
---|
482 | n/a | owner=self.owner, group=self.group) |
---|
483 | n/a | archive_files.append(file) |
---|
484 | n/a | self.distribution.dist_files.append(('sdist', '', file)) |
---|
485 | n/a | |
---|
486 | n/a | self.archive_files = archive_files |
---|
487 | n/a | |
---|
488 | n/a | if not self.keep_temp: |
---|
489 | n/a | dir_util.remove_tree(base_dir, dry_run=self.dry_run) |
---|
490 | n/a | |
---|
491 | n/a | def get_archive_files(self): |
---|
492 | n/a | """Return the list of archive files created when the command |
---|
493 | n/a | was run, or None if the command hasn't run yet. |
---|
494 | n/a | """ |
---|
495 | n/a | return self.archive_files |
---|