annotate Lib/distutils/command/sdist.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents d514a8b7ae78
children c2c90d1f3c33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.command.sdist
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
2
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
3 Implements the Distutils 'sdist' command (create a source distribution)."""
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
4
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11844
diff changeset
5 __revision__ = "$Id$"
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
6
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 45411
diff changeset
7 import os, string
50567
7ac1f6be8ad5 Merged revisions 68276 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 45680
diff changeset
8 import sys
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
9 from types import *
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
10 from glob import glob
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
11 from warnings import warn
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
12
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
13 from distutils.core import Command
13871
8307446bc6aa Fixed imports from '*util' modules to not just import everything from util.
Greg Ward <gward@python.net>
parents: 13755
diff changeset
14 from distutils import dir_util, dep_util, file_util, archive_util
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
15 from distutils.text_file import TextFile
13755
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
16 from distutils.errors import *
13752
8d10757a575b The other half of Rene Liebscher's patch to add the Template class,
Greg Ward <gward@python.net>
parents: 13724
diff changeset
17 from distutils.filelist import FileList
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
18 from distutils import log
51684
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
19 from distutils.util import convert_path
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
20
54053
bf699026458e more test coverage for distutils sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51696
diff changeset
21 def show_formats():
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
22 """Print all possible values for the 'formats' option (used by
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
23 the "--help-formats" command-line option).
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
24 """
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
25 from distutils.fancy_getopt import FancyGetopt
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
26 from distutils.archive_util import ARCHIVE_FORMATS
54053
bf699026458e more test coverage for distutils sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51696
diff changeset
27 formats = []
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
28 for format in ARCHIVE_FORMATS.keys():
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
29 formats.append(("formats=" + format, None,
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
30 ARCHIVE_FORMATS[format][2]))
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
31 formats.sort()
54053
bf699026458e more test coverage for distutils sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51696
diff changeset
32 FancyGetopt(formats).print_help(
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
33 "List of available source distribution formats:")
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
34
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
35 class sdist(Command):
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
36
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
37 description = "create a source distribution (tarball, zip file, etc.)"
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
38
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
39 def checking_metadata(self):
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
40 """Callable used for the check sub-command.
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
41
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
42 Placed here so user_options can view it"""
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
43 return self.metadata_check
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
44
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
45 user_options = [
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
46 ('template=', 't',
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
47 "name of manifest template file [default: MANIFEST.in]"),
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
48 ('manifest=', 'm',
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
49 "name of manifest file [default: MANIFEST]"),
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
50 ('use-defaults', None,
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
51 "include the default file set in the manifest "
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
52 "[default; disable with --no-defaults]"),
13111
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
53 ('no-defaults', None,
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
54 "don't include the default file set"),
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
55 ('prune', None,
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
56 "specifically exclude files/directories that should not be "
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
57 "distributed (build tree, RCS/CVS dirs, etc.) "
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
58 "[default; disable with --no-prune]"),
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
59 ('no-prune', None,
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
60 "don't automatically exclude anything"),
12495
bef24d48afc8 Supply short form for --manifest-only (-o) and --force-manifest (-f)
Greg Ward <gward@python.net>
parents: 12494
diff changeset
61 ('manifest-only', 'o',
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
62 "just regenerate the manifest and then stop "
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
63 "(implies --force-manifest)"),
12495
bef24d48afc8 Supply short form for --manifest-only (-o) and --force-manifest (-f)
Greg Ward <gward@python.net>
parents: 12494
diff changeset
64 ('force-manifest', 'f',
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
65 "forcibly regenerate the manifest and carry on as usual"),
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
66 ('formats=', None,
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12983
diff changeset
67 "formats for source distribution (comma-separated list)"),
14830
07288d2db596 Renamed '--keep-tree' option to '--keep-temp', for consistency
Greg Ward <gward@python.net>
parents: 14829
diff changeset
68 ('keep-temp', 'k',
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
69 "keep the distribution tree around after creating " +
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
70 "archive file(s)"),
13347
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
71 ('dist-dir=', 'd',
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
72 "directory to put the source distribution archive(s) in "
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
73 "[default: dist]"),
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
74 ('medata-check', None,
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
75 "Ensure that all required elements of meta-data "
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
76 "are supplied. Warn if any missing. [default]"),
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
77 ]
12888
b5752de0cfa4 Cosmetic tweaks to imports, the 'show_formats()' function, and the
Greg Ward <gward@python.net>
parents: 12887
diff changeset
78
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14656
diff changeset
79 boolean_options = ['use-defaults', 'prune',
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14656
diff changeset
80 'manifest-only', 'force-manifest',
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
81 'keep-temp', 'metadata-check']
12888
b5752de0cfa4 Cosmetic tweaks to imports, the 'show_formats()' function, and the
Greg Ward <gward@python.net>
parents: 12887
diff changeset
82
12869
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12851
diff changeset
83 help_options = [
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12851
diff changeset
84 ('help-formats', None,
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12983
diff changeset
85 "list available distribution formats", show_formats),
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
86 ]
12869
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12851
diff changeset
87
13111
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
88 negative_opt = {'no-defaults': 'use-defaults',
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
89 'no-prune': 'prune' }
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
90
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
91 default_format = {'posix': 'gztar',
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
92 'nt': 'zip' }
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
93
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
94 sub_commands = [('check', checking_metadata)]
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
95
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
96 def initialize_options(self):
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
97 # 'template' and 'manifest' are, respectively, the names of
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
98 # the manifest template and manifest file.
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
99 self.template = None
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
100 self.manifest = None
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
101
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
102 # 'use_defaults': if true, we will include the default file set
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
103 # in the manifest
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
104 self.use_defaults = 1
13111
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
105 self.prune = 1
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
106
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
107 self.manifest_only = 0
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
108 self.force_manifest = 0
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
109
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
110 self.formats = None
14830
07288d2db596 Renamed '--keep-tree' option to '--keep-temp', for consistency
Greg Ward <gward@python.net>
parents: 14829
diff changeset
111 self.keep_temp = 0
13347
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
112 self.dist_dir = None
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
113
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
114 self.archive_files = None
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
115 self.metadata_check = 1
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
116
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
117 def finalize_options(self):
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
118 if self.manifest is None:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
119 self.manifest = "MANIFEST"
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
120 if self.template is None:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
121 self.template = "MANIFEST.in"
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
122
12851
e787f6641afb Use 'ensure_string_list()' for 'formats' option, so that it can be
Greg Ward <gward@python.net>
parents: 12812
diff changeset
123 self.ensure_string_list('formats')
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
124 if self.formats is None:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
125 try:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
126 self.formats = [self.default_format[os.name]]
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
127 except KeyError:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
128 raise DistutilsPlatformError, \
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
129 "don't know how to create source distributions " + \
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
130 "on platform %s" % os.name
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
131
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
132 bad_format = archive_util.check_archive_formats(self.formats)
12451
33ba0626ef72 Check that 'self.formats' is good early on.
Greg Ward <gward@python.net>
parents: 12447
diff changeset
133 if bad_format:
33ba0626ef72 Check that 'self.formats' is good early on.
Greg Ward <gward@python.net>
parents: 12447
diff changeset
134 raise DistutilsOptionError, \
33ba0626ef72 Check that 'self.formats' is good early on.
Greg Ward <gward@python.net>
parents: 12447
diff changeset
135 "unknown archive format '%s'" % bad_format
33ba0626ef72 Check that 'self.formats' is good early on.
Greg Ward <gward@python.net>
parents: 12447
diff changeset
136
13347
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
137 if self.dist_dir is None:
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
138 self.dist_dir = "dist"
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
139
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
140 def run(self):
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
141 # 'filelist' contains the list of files that will make up the
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
142 # manifest
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
143 self.filelist = FileList()
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17128
diff changeset
144
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
145 # Run sub commands
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
146 for cmd_name in self.get_sub_commands():
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
147 self.run_command(cmd_name)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
148
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
149 # Do whatever it takes to get the list of files to process
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
150 # (process the manifest template, read an existing manifest,
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
151 # whatever). File list is accumulated in 'self.filelist'.
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
152 self.get_file_list()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
153
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
154 # If user just wanted us to regenerate the manifest, stop now.
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
155 if self.manifest_only:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
156 return
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
157
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
158 # Otherwise, go ahead and create the source distribution tarball,
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
159 # or zipfile, or whatever.
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
160 self.make_distribution()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
161
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
162 def check_metadata(self):
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
163 """Deprecated API."""
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
164 warn("distutils.command.sdist.check_metadata is deprecated, \
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
165 use the check command instead", PendingDeprecationWarning)
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
166 check = self.distribution.get_command_obj('check')
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
167 check.ensure_finalized()
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54059
diff changeset
168 check.run()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
169
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
170 def get_file_list(self):
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
171 """Figure out the list of files to include in the source
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
172 distribution, and put it in 'self.filelist'. This might involve
12889
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
173 reading the manifest template (and writing the manifest), or just
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
174 reading the manifest, or just using the default file set -- it all
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
175 depends on the user's options and the state of the filesystem.
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
176 """
12983
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
177 # If we have a manifest template, see if it's newer than the
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
178 # manifest; if so, we'll regenerate the manifest.
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
179 template_exists = os.path.isfile(self.template)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
180 if template_exists:
13871
8307446bc6aa Fixed imports from '*util' modules to not just import everything from util.
Greg Ward <gward@python.net>
parents: 13755
diff changeset
181 template_newer = dep_util.newer(self.template, self.manifest)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
182
12983
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
183 # The contents of the manifest file almost certainly depend on the
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
184 # setup script as well as the manifest template -- so if the setup
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
185 # script is newer than the manifest, we'll regenerate the manifest
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
186 # from the template. (Well, not quite: if we already have a
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
187 # manifest, but there's no template -- which will happen if the
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
188 # developer elects to generate a manifest some other way -- then we
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
189 # can't regenerate the manifest, so we don't.)
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 14115
diff changeset
190 self.debug_print("checking if %s newer than %s" %
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 14115
diff changeset
191 (self.distribution.script_name, self.manifest))
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 14115
diff changeset
192 setup_newer = dep_util.newer(self.distribution.script_name,
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 14115
diff changeset
193 self.manifest)
12983
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
194
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
195 # cases:
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
196 # 1) no manifest, template exists: generate manifest
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
197 # (covered by 2a: no manifest == template newer)
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
198 # 2) manifest & template exist:
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
199 # 2a) template or setup script newer than manifest:
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
200 # regenerate manifest
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
201 # 2b) manifest newer than both:
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
202 # do nothing (unless --force or --manifest-only)
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
203 # 3) manifest exists, no template:
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
204 # do nothing (unless --force or --manifest-only)
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
205 # 4) no manifest, no template: generate w/ warning ("defaults only")
b544299e68c5 Fix inspired by Rene Liebscher: if setup script is newer than the
Greg Ward <gward@python.net>
parents: 12894
diff changeset
206
14435
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
207 manifest_outofdate = (template_exists and
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
208 (template_newer or setup_newer))
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
209 force_regen = self.force_manifest or self.manifest_only
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
210 manifest_exists = os.path.isfile(self.manifest)
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
211 neither_exists = (not template_exists and not manifest_exists)
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
212
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
213 # Regenerate the manifest if necessary (or if explicitly told to)
14435
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
214 if manifest_outofdate or neither_exists or force_regen:
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
215 if not template_exists:
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
216 self.warn(("manifest template '%s' does not exist " +
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
217 "(using default file list)") %
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
218 self.template)
13755
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
219 self.filelist.findall()
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
220
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
221 if self.use_defaults:
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
222 self.add_defaults()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
223 if template_exists:
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
224 self.read_template()
13111
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
225 if self.prune:
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
226 self.prune_file_list()
12893
fd5881e17427 Moved the code that prunes the file list after reading the manifest
Greg Ward <gward@python.net>
parents: 12892
diff changeset
227
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
228 self.filelist.sort()
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
229 self.filelist.remove_duplicates()
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
230 self.write_manifest()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
231
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
232 # Don't regenerate the manifest, just read it in.
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
233 else:
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
234 self.read_manifest()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
235
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
236 def add_defaults(self):
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
237 """Add all the default files to self.filelist:
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
238 - README or README.txt
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
239 - setup.py
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
240 - test/test*.py
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
241 - all pure Python modules mentioned in setup script
51667
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
242 - all files pointed by package_data (build_py)
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
243 - all files defined in data_files.
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
244 - all files defined as scripts.
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
245 - all C sources listed as part of extensions or C libraries
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
246 in the setup script (doesn't catch C headers!)
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
247 Warns if (README or README.txt) or setup.py are missing; everything
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
248 else is optional.
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
249 """
12894
61f6acc4aa74 Include setup.cfg in the list of default files to distribute.
Greg Ward <gward@python.net>
parents: 12893
diff changeset
250
14435
9fa3c571daff Reorganized logic in 'get_file_list()' so it's easier to read, and fixed a
Greg Ward <gward@python.net>
parents: 14237
diff changeset
251 standards = [('README', 'README.txt'), self.distribution.script_name]
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
252 for fn in standards:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
253 if type(fn) is TupleType:
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
254 alts = fn
11844
253ec95f391e Fix from est@hyperreal.org: missing initialize in 'find_defaults()'.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
255 got_it = 0
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
256 for fn in alts:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
257 if os.path.exists(fn):
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
258 got_it = 1
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
259 self.filelist.append(fn)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
260 break
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
261
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
262 if not got_it:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
263 self.warn("standard file not found: should have one of " +
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
264 string.join(alts, ', '))
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
265 else:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
266 if os.path.exists(fn):
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
267 self.filelist.append(fn)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
268 else:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
269 self.warn("standard file '%s' not found" % fn)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
270
12894
61f6acc4aa74 Include setup.cfg in the list of default files to distribute.
Greg Ward <gward@python.net>
parents: 12893
diff changeset
271 optional = ['test/test*.py', 'setup.cfg']
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
272 for pattern in optional:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
273 files = filter(os.path.isfile, glob(pattern))
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
274 if files:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
275 self.filelist.extend(files)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
276
51667
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
277 # build_py is used to get:
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
278 # - python modules
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
279 # - files defined in package_data
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
280 build_py = self.get_finalized_command('build_py')
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
281
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
282 # getting python files
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
283 if self.distribution.has_pure_modules():
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
284 self.filelist.extend(build_py.get_source_files())
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
285
51667
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
286 # getting package_data files
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
287 # (computed in build_py.data_files by build_py.finalize_options)
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
288 for pkg, src_dir, build_dir, filenames in build_py.data_files:
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
289 for filename in filenames:
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
290 self.filelist.append(os.path.join(src_dir, filename))
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
291
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
292 # getting distribution.data_files
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
293 if self.distribution.has_data_files():
51684
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
294 for item in self.distribution.data_files:
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
295 if isinstance(item, str): # plain file
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
296 item = convert_path(item)
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
297 if os.path.isfile(item):
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
298 self.filelist.append(item)
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
299 else: # a (dirname, filenames) tuple
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
300 dirname, filenames = item
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
301 for f in filenames:
51696
92e42b1b0a6e fixed the data_files inclusion behavior
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51684
diff changeset
302 f = convert_path(f)
51684
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
303 if os.path.isfile(f):
27268ef04708 #2279 added the plain path case for data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51667
diff changeset
304 self.filelist.append(f)
51667
982f9e2925a4 Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51054
diff changeset
305
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
306 if self.distribution.has_ext_modules():
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
307 build_ext = self.get_finalized_command('build_ext')
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
308 self.filelist.extend(build_ext.get_source_files())
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
309
12298
d640e7d4aec4 Ditched the unused 'list_only' option.
Greg Ward <gward@python.net>
parents: 12152
diff changeset
310 if self.distribution.has_c_libraries():
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
311 build_clib = self.get_finalized_command('build_clib')
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
312 self.filelist.extend(build_clib.get_source_files())
12298
d640e7d4aec4 Ditched the unused 'list_only' option.
Greg Ward <gward@python.net>
parents: 12152
diff changeset
313
31852
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
314 if self.distribution.has_scripts():
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
315 build_scripts = self.get_finalized_command('build_scripts')
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
316 self.filelist.extend(build_scripts.get_source_files())
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
317
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
318 def read_template(self):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
319 """Read and parse manifest template file named by self.template.
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
320
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
321 (usually "MANIFEST.in") The parsing and processing is done by
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
322 'self.filelist', which updates itself accordingly.
12889
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
323 """
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
324 log.info("reading manifest template '%s'", self.template)
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
325 template = TextFile(self.template,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
326 strip_comments=1,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
327 skip_blanks=1,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
328 join_lines=1,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
329 lstrip_ws=1,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
330 rstrip_ws=1,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
331 collapse_join=1)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
332
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
333 while 1:
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
334 line = template.readline()
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
335 if line is None: # end of file
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
336 break
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
337
13755
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
338 try:
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
339 self.filelist.process_template_line(line)
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
340 except DistutilsTemplateError, msg:
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
341 self.warn("%s, line %d: %s" % (template.filename,
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
342 template.current_line,
632be99cc2cb Catch syntax errors from processing template lines and turn them into
Greg Ward <gward@python.net>
parents: 13753
diff changeset
343 msg))
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
344
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
345 def prune_file_list(self):
12893
fd5881e17427 Moved the code that prunes the file list after reading the manifest
Greg Ward <gward@python.net>
parents: 12892
diff changeset
346 """Prune off branches that might slip into the file list as created
13111
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
347 by 'read_template()', but really don't belong there:
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
348 * the build tree (typically "build")
52d5fb471e17 Fixed 'findall()' so it only returns regular files -- no directories.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
349 * the release tree itself (only an issue if we ran "sdist"
14830
07288d2db596 Renamed '--keep-tree' option to '--keep-temp', for consistency
Greg Ward <gward@python.net>
parents: 14829
diff changeset
350 previously with --keep-temp, or it aborted)
45680
ef893390487b #1725737: ignore other VC directories other than CVS and SVN's too.
Georg Brandl <georg@python.org>
parents: 45468
diff changeset
351 * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
12893
fd5881e17427 Moved the code that prunes the file list after reading the manifest
Greg Ward <gward@python.net>
parents: 12892
diff changeset
352 """
fd5881e17427 Moved the code that prunes the file list after reading the manifest
Greg Ward <gward@python.net>
parents: 12892
diff changeset
353 build = self.get_finalized_command('build')
12781
936efdc01d52 Patch from Andrew Kuchling: prune out the build and source distribution
Greg Ward <gward@python.net>
parents: 12743
diff changeset
354 base_dir = self.distribution.get_fullname()
936efdc01d52 Patch from Andrew Kuchling: prune out the build and source distribution
Greg Ward <gward@python.net>
parents: 12743
diff changeset
355
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
356 self.filelist.exclude_pattern(None, prefix=build.build_base)
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
357 self.filelist.exclude_pattern(None, prefix=base_dir)
12887
11d10e9b508d Made all debug output go through the 'debug_print()' method instead of
Greg Ward <gward@python.net>
parents: 12869
diff changeset
358
50567
7ac1f6be8ad5 Merged revisions 68276 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 45680
diff changeset
359 # pruning out vcs directories
7ac1f6be8ad5 Merged revisions 68276 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 45680
diff changeset
360 # both separators are used under win32
50582
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
361 if sys.platform == 'win32':
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
362 seps = r'/|\\'
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
363 else:
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
364 seps = '/'
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
365
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
366 vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
057cb46ddaad Merged revisions 68293 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50567
diff changeset
367 '_darcs']
50567
7ac1f6be8ad5 Merged revisions 68276 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 45680
diff changeset
368 vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
7ac1f6be8ad5 Merged revisions 68276 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 45680
diff changeset
369 self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
12887
11d10e9b508d Made all debug output go through the 'debug_print()' method instead of
Greg Ward <gward@python.net>
parents: 12869
diff changeset
370
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
371 def write_manifest(self):
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
372 """Write the file list in 'self.filelist' (presumably as filled in
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
373 by 'add_defaults()' and 'read_template()') to the manifest file
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
374 named by 'self.manifest'.
12889
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
375 """
13871
8307446bc6aa Fixed imports from '*util' modules to not just import everything from util.
Greg Ward <gward@python.net>
parents: 13755
diff changeset
376 self.execute(file_util.write_file,
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
377 (self.manifest, self.filelist.files),
12887
11d10e9b508d Made all debug output go through the 'debug_print()' method instead of
Greg Ward <gward@python.net>
parents: 12869
diff changeset
378 "writing manifest file '%s'" % self.manifest)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
379
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
380 def read_manifest(self):
12889
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
381 """Read the manifest file (named by 'self.manifest') and use it to
13753
84f8579a079c Replaced 'self.files' with 'self.filelist': now we carry around a FileList
Greg Ward <gward@python.net>
parents: 13752
diff changeset
382 fill in 'self.filelist', the list of files to include in the source
12889
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
383 distribution.
f54c3677bae7 Docstring reformatting binge.
Greg Ward <gward@python.net>
parents: 12888
diff changeset
384 """
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
385 log.info("reading manifest file '%s'", self.manifest)
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
386 manifest = open(self.manifest)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
387 while 1:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
388 line = manifest.readline()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
389 if line == '': # end of file
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
390 break
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
391 if line[-1] == '\n':
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
392 line = line[0:-1]
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
393 self.filelist.append(line)
45411
80ecf67347e9 Close manifest file.
Andrew M. Kuchling <amk@amk.ca>
parents: 34805
diff changeset
394 manifest.close()
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
395
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
396 def make_release_tree(self, base_dir, files):
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
397 """Create the directory tree that will become the source
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
398 distribution archive. All directories implied by the filenames in
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
399 'files' are created under 'base_dir', and then we hard link or copy
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
400 (if hard linking is unavailable) those files into place.
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
401 Essentially, this duplicates the developer's source tree, but in a
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
402 directory named after the distribution, containing only the files
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
403 to be distributed.
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
404 """
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
405 # Create all the directories under 'base_dir' necessary to
14436
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
406 # put 'files' there; the 'mkpath()' is just so we don't die
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
407 # if the manifest happens to be empty.
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
408 self.mkpath(base_dir)
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
409 dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
410
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
411 # And walk over the list of files, either making a hard link (if
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
412 # os.link exists) to each one that doesn't already exist in its
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
413 # corresponding location under 'base_dir', or copying each file
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
414 # that's out-of-date in 'base_dir'. (Usually, all files will be
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
415 # out-of-date, because by default we blow away 'base_dir' when
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
416 # we're done making the distribution archives.)
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17128
diff changeset
417
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
418 if hasattr(os, 'link'): # can make hard links on this system
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
419 link = 'hard'
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
420 msg = "making hard links in %s..." % base_dir
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
421 else: # nope, have to copy
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
422 link = None
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
423 msg = "copying files to %s..." % base_dir
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
424
14436
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
425 if not files:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
426 log.warn("no files to distribute -- empty manifest?")
14436
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
427 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
428 log.info(msg)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
429 for file in files:
14436
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
430 if not os.path.isfile(file):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
431 log.warn("'%s' not a regular file -- skipping" % file)
14436
c0509989405e Bullet-proofing of 'make_release_tree()':
Greg Ward <gward@python.net>
parents: 14435
diff changeset
432 else:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
433 dest = os.path.join(base_dir, file)
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
434 self.copy_file(file, dest, link=link)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
435
17128
1146070f47ec Call the write_pkg_info method
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
436 self.distribution.metadata.write_pkg_info(base_dir)
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17128
diff changeset
437
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
438 def make_distribution(self):
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
439 """Create the source distribution(s). First, we create the release
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
440 tree with 'make_release_tree()'; then, we create all required
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
441 archive files (according to 'self.formats') from the release tree.
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
442 Finally, we clean up by blowing away the release tree (unless
14830
07288d2db596 Renamed '--keep-tree' option to '--keep-temp', for consistency
Greg Ward <gward@python.net>
parents: 14829
diff changeset
443 'self.keep_temp' is true). The list of archive files created is
12891
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
444 stored so it can be retrieved later by 'get_archive_files()'.
0c8b9f96b26a Docstring addition binge.
Greg Ward <gward@python.net>
parents: 12889
diff changeset
445 """
12152
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
446 # Don't warn about missing meta-data here -- should be (and is!)
21a9bbb572d7 Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
Greg Ward <gward@python.net>
parents: 12101
diff changeset
447 # done elsewhere.
12447
951d84e1d54b Changed to call 'get_fullname()', not 'get_full_name()', on Distribution object.
Greg Ward <gward@python.net>
parents: 12433
diff changeset
448 base_dir = self.distribution.get_fullname()
13347
384835ea0a5a Added the --dist-dir option to control where the archive(s) are put;
Greg Ward <gward@python.net>
parents: 13111
diff changeset
449 base_name = os.path.join(self.dist_dir, base_dir)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
450
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
451 self.make_release_tree(base_dir, self.filelist.files)
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
452 archive_files = [] # remember names of files we create
51054
21fb1014294c Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
453 # tar archive must be created last to avoid overwrite and remove
21fb1014294c Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
454 if 'tar' in self.formats:
21fb1014294c Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
455 self.formats.append(self.formats.pop(self.formats.index('tar')))
21fb1014294c Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
456
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
457 for fmt in self.formats:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14830
diff changeset
458 file = self.make_archive(base_name, fmt, base_dir=base_dir)
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
459 archive_files.append(file)
34805
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
460 self.distribution.dist_files.append(('sdist', '', file))
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
461
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
462 self.archive_files = archive_files
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
463
14830
07288d2db596 Renamed '--keep-tree' option to '--keep-temp', for consistency
Greg Ward <gward@python.net>
parents: 14829
diff changeset
464 if not self.keep_temp:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
465 dir_util.remove_tree(base_dir, dry_run=self.dry_run)
11811
20ca7230ae3f The 'sdist' command to create a source distribution. This is derived from the
Greg Ward <gward@python.net>
parents:
diff changeset
466
54059
67baf2c17369 pep8-fied distutils.command.sdist + more tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54053
diff changeset
467 def get_archive_files(self):
12812
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
468 """Return the list of archive files created when the command
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
469 was run, or None if the command hasn't run yet.
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
470 """
0c217e5f055b Remember the list of archive files created in 'make_distribution()'.
Greg Ward <gward@python.net>
parents: 12804
diff changeset
471 return self.archive_files