Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
distutils.command.sdist.sdist Class Reference
Inheritance diagram for distutils.command.sdist.sdist:
Inheritance graph
[legend]
Collaboration diagram for distutils.command.sdist.sdist:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def checking_metadata
def initialize_options
def finalize_options
def run
def check_metadata
def get_file_list
def add_defaults
def read_template
def prune_file_list
def write_manifest
def read_manifest
def make_release_tree
def make_distribution
def get_archive_files

Public Attributes

 template
 manifest
 use_defaults
 prune
 manifest_only
 force_manifest
 formats
 keep_temp
 dist_dir
 archive_files
 metadata_check
 filelist

Static Public Attributes

string description = "create a source distribution (tarball, zip file, etc.)"
list user_options
list boolean_options
list help_options
dictionary negative_opt
dictionary default_format
list sub_commands = [('check', checking_metadata)]

Private Member Functions

def _manifest_is_not_generated

Detailed Description

Definition at line 34 of file sdist.py.


Member Function Documentation

Definition at line 355 of file sdist.py.

00355 
00356     def _manifest_is_not_generated(self):
00357         # check for special comment used in 3.1.3 and higher
00358         if not os.path.isfile(self.manifest):
00359             return False
00360 
00361         fp = open(self.manifest)
00362         try:
00363             first_line = fp.readline()
00364         finally:
00365             fp.close()
00366         return first_line != '# file GENERATED by distutils, do NOT edit\n'

Here is the caller graph for this function:

Add all the default files to self.filelist:
  - README or README.txt
  - setup.py
  - test/test*.py
  - all pure Python modules mentioned in setup script
  - all files pointed by package_data (build_py)
  - all files defined in data_files.
  - all files defined as scripts.
  - all C sources listed as part of extensions or C libraries
    in the setup script (doesn't catch C headers!)
Warns if (README or README.txt) or setup.py are missing; everything
else is optional.

Definition at line 210 of file sdist.py.

00210 
00211     def add_defaults(self):
00212         """Add all the default files to self.filelist:
00213           - README or README.txt
00214           - setup.py
00215           - test/test*.py
00216           - all pure Python modules mentioned in setup script
00217           - all files pointed by package_data (build_py)
00218           - all files defined in data_files.
00219           - all files defined as scripts.
00220           - all C sources listed as part of extensions or C libraries
00221             in the setup script (doesn't catch C headers!)
00222         Warns if (README or README.txt) or setup.py are missing; everything
00223         else is optional.
00224         """
00225         standards = [('README', 'README.txt'), self.distribution.script_name]
00226         for fn in standards:
00227             if isinstance(fn, tuple):
00228                 alts = fn
00229                 got_it = False
00230                 for fn in alts:
00231                     if os.path.exists(fn):
00232                         got_it = True
00233                         self.filelist.append(fn)
00234                         break
00235 
00236                 if not got_it:
00237                     self.warn("standard file not found: should have one of " +
00238                               ', '.join(alts))
00239             else:
00240                 if os.path.exists(fn):
00241                     self.filelist.append(fn)
00242                 else:
00243                     self.warn("standard file '%s' not found" % fn)
00244 
00245         optional = ['test/test*.py', 'setup.cfg']
00246         for pattern in optional:
00247             files = filter(os.path.isfile, glob(pattern))
00248             self.filelist.extend(files)
00249 
00250         # build_py is used to get:
00251         #  - python modules
00252         #  - files defined in package_data
00253         build_py = self.get_finalized_command('build_py')
00254 
00255         # getting python files
00256         if self.distribution.has_pure_modules():
00257             self.filelist.extend(build_py.get_source_files())
00258 
00259         # getting package_data files
00260         # (computed in build_py.data_files by build_py.finalize_options)
00261         for pkg, src_dir, build_dir, filenames in build_py.data_files:
00262             for filename in filenames:
00263                 self.filelist.append(os.path.join(src_dir, filename))
00264 
00265         # getting distribution.data_files
00266         if self.distribution.has_data_files():
00267             for item in self.distribution.data_files:
00268                 if isinstance(item, str): # plain file
00269                     item = convert_path(item)
00270                     if os.path.isfile(item):
00271                         self.filelist.append(item)
00272                 else:    # a (dirname, filenames) tuple
00273                     dirname, filenames = item
00274                     for f in filenames:
00275                         f = convert_path(f)
00276                         if os.path.isfile(f):
00277                             self.filelist.append(f)
00278 
00279         if self.distribution.has_ext_modules():
00280             build_ext = self.get_finalized_command('build_ext')
00281             self.filelist.extend(build_ext.get_source_files())
00282 
00283         if self.distribution.has_c_libraries():
00284             build_clib = self.get_finalized_command('build_clib')
00285             self.filelist.extend(build_clib.get_source_files())
00286 
00287         if self.distribution.has_scripts():
00288             build_scripts = self.get_finalized_command('build_scripts')
00289             self.filelist.extend(build_scripts.get_source_files())

Here is the call graph for this function:

Here is the caller graph for this function:

Deprecated API.

Definition at line 162 of file sdist.py.

00162 
00163     def check_metadata(self):
00164         """Deprecated API."""
00165         warn("distutils.command.sdist.check_metadata is deprecated, \
00166               use the check command instead", PendingDeprecationWarning)
00167         check = self.distribution.get_command_obj('check')
00168         check.ensure_finalized()
00169         check.run()

Callable used for the check sub-command.

Placed here so user_options can view it

Definition at line 38 of file sdist.py.

00038 
00039     def checking_metadata(self):
00040         """Callable used for the check sub-command.
00041 
00042         Placed here so user_options can view it"""
00043         return self.metadata_check

Definition at line 117 of file sdist.py.

00117 
00118     def finalize_options(self):
00119         if self.manifest is None:
00120             self.manifest = "MANIFEST"
00121         if self.template is None:
00122             self.template = "MANIFEST.in"
00123 
00124         self.ensure_string_list('formats')
00125         if self.formats is None:
00126             try:
00127                 self.formats = [self.default_format[os.name]]
00128             except KeyError:
00129                 raise DistutilsPlatformError(
00130                       "don't know how to create source distributions "
00131                       "on platform %s" % os.name)
00132 
00133         bad_format = archive_util.check_archive_formats(self.formats)
00134         if bad_format:
00135             raise DistutilsOptionError(
00136                   "unknown archive format '%s'" % bad_format)
00137 
00138         if self.dist_dir is None:
00139             self.dist_dir = "dist"

Here is the call graph for this function:

Return the list of archive files created when the command
was run, or None if the command hasn't run yet.

Definition at line 453 of file sdist.py.

00453 
00454     def get_archive_files(self):
00455         """Return the list of archive files created when the command
00456         was run, or None if the command hasn't run yet.
00457         """
00458         return self.archive_files
Figure out the list of files to include in the source
distribution, and put it in 'self.filelist'.  This might involve
reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all
depends on the user's options.

Definition at line 170 of file sdist.py.

00170 
00171     def get_file_list(self):
00172         """Figure out the list of files to include in the source
00173         distribution, and put it in 'self.filelist'.  This might involve
00174         reading the manifest template (and writing the manifest), or just
00175         reading the manifest, or just using the default file set -- it all
00176         depends on the user's options.
00177         """
00178         # new behavior when using a template:
00179         # the file list is recalculated everytime because
00180         # even if MANIFEST.in or setup.py are not changed
00181         # the user might have added some files in the tree that
00182         # need to be included.
00183         #
00184         #  This makes --force the default and only behavior with templates.
00185         template_exists = os.path.isfile(self.template)
00186         if not template_exists and self._manifest_is_not_generated():
00187             self.read_manifest()
00188             self.filelist.sort()
00189             self.filelist.remove_duplicates()
00190             return
00191 
00192         if not template_exists:
00193             self.warn(("manifest template '%s' does not exist " +
00194                         "(using default file list)") %
00195                         self.template)
00196         self.filelist.findall()
00197 
00198         if self.use_defaults:
00199             self.add_defaults()
00200 
00201         if template_exists:
00202             self.read_template()
00203 
00204         if self.prune:
00205             self.prune_file_list()
00206 
00207         self.filelist.sort()
00208         self.filelist.remove_duplicates()
00209         self.write_manifest()

Here is the call graph for this function:

Definition at line 96 of file sdist.py.

00096 
00097     def initialize_options(self):
00098         # 'template' and 'manifest' are, respectively, the names of
00099         # the manifest template and manifest file.
00100         self.template = None
00101         self.manifest = None
00102 
00103         # 'use_defaults': if true, we will include the default file set
00104         # in the manifest
00105         self.use_defaults = 1
00106         self.prune = 1
00107 
00108         self.manifest_only = 0
00109         self.force_manifest = 0
00110 
00111         self.formats = None
00112         self.keep_temp = 0
00113         self.dist_dir = None
00114 
00115         self.archive_files = None
00116         self.metadata_check = 1

Create the source distribution(s).  First, we create the release
tree with 'make_release_tree()'; then, we create all required
archive files (according to 'self.formats') from the release tree.
Finally, we clean up by blowing away the release tree (unless
'self.keep_temp' is true).  The list of archive files created is
stored so it can be retrieved later by 'get_archive_files()'.

Definition at line 424 of file sdist.py.

00424 
00425     def make_distribution(self):
00426         """Create the source distribution(s).  First, we create the release
00427         tree with 'make_release_tree()'; then, we create all required
00428         archive files (according to 'self.formats') from the release tree.
00429         Finally, we clean up by blowing away the release tree (unless
00430         'self.keep_temp' is true).  The list of archive files created is
00431         stored so it can be retrieved later by 'get_archive_files()'.
00432         """
00433         # Don't warn about missing meta-data here -- should be (and is!)
00434         # done elsewhere.
00435         base_dir = self.distribution.get_fullname()
00436         base_name = os.path.join(self.dist_dir, base_dir)
00437 
00438         self.make_release_tree(base_dir, self.filelist.files)
00439         archive_files = []              # remember names of files we create
00440         # tar archive must be created last to avoid overwrite and remove
00441         if 'tar' in self.formats:
00442             self.formats.append(self.formats.pop(self.formats.index('tar')))
00443 
00444         for fmt in self.formats:
00445             file = self.make_archive(base_name, fmt, base_dir=base_dir)
00446             archive_files.append(file)
00447             self.distribution.dist_files.append(('sdist', '', file))
00448 
00449         self.archive_files = archive_files
00450 
00451         if not self.keep_temp:
00452             dir_util.remove_tree(base_dir, dry_run=self.dry_run)

Here is the call graph for this function:

def distutils.command.sdist.sdist.make_release_tree (   self,
  base_dir,
  files 
)
Create the directory tree that will become the source
distribution archive.  All directories implied by the filenames in
'files' are created under 'base_dir', and then we hard link or copy
(if hard linking is unavailable) those files into place.
Essentially, this duplicates the developer's source tree, but in a
directory named after the distribution, containing only the files
to be distributed.

Definition at line 382 of file sdist.py.

00382 
00383     def make_release_tree(self, base_dir, files):
00384         """Create the directory tree that will become the source
00385         distribution archive.  All directories implied by the filenames in
00386         'files' are created under 'base_dir', and then we hard link or copy
00387         (if hard linking is unavailable) those files into place.
00388         Essentially, this duplicates the developer's source tree, but in a
00389         directory named after the distribution, containing only the files
00390         to be distributed.
00391         """
00392         # Create all the directories under 'base_dir' necessary to
00393         # put 'files' there; the 'mkpath()' is just so we don't die
00394         # if the manifest happens to be empty.
00395         self.mkpath(base_dir)
00396         dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
00397 
00398         # And walk over the list of files, either making a hard link (if
00399         # os.link exists) to each one that doesn't already exist in its
00400         # corresponding location under 'base_dir', or copying each file
00401         # that's out-of-date in 'base_dir'.  (Usually, all files will be
00402         # out-of-date, because by default we blow away 'base_dir' when
00403         # we're done making the distribution archives.)
00404 
00405         if hasattr(os, 'link'):        # can make hard links on this system
00406             link = 'hard'
00407             msg = "making hard links in %s..." % base_dir
00408         else:                           # nope, have to copy
00409             link = None
00410             msg = "copying files to %s..." % base_dir
00411 
00412         if not files:
00413             log.warn("no files to distribute -- empty manifest?")
00414         else:
00415             log.info(msg)
00416         for file in files:
00417             if not os.path.isfile(file):
00418                 log.warn("'%s' not a regular file -- skipping" % file)
00419             else:
00420                 dest = os.path.join(base_dir, file)
00421                 self.copy_file(file, dest, link=link)
00422 
00423         self.distribution.metadata.write_pkg_info(base_dir)

Here is the call graph for this function:

Here is the caller graph for this function:

Prune off branches that might slip into the file list as created
by 'read_template()', but really don't belong there:
  * the build tree (typically "build")
  * the release tree itself (only an issue if we ran "sdist"
    previously with --keep-temp, or it aborted)
  * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories

Definition at line 316 of file sdist.py.

00316 
00317     def prune_file_list(self):
00318         """Prune off branches that might slip into the file list as created
00319         by 'read_template()', but really don't belong there:
00320           * the build tree (typically "build")
00321           * the release tree itself (only an issue if we ran "sdist"
00322             previously with --keep-temp, or it aborted)
00323           * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
00324         """
00325         build = self.get_finalized_command('build')
00326         base_dir = self.distribution.get_fullname()
00327 
00328         self.filelist.exclude_pattern(None, prefix=build.build_base)
00329         self.filelist.exclude_pattern(None, prefix=base_dir)
00330 
00331         if sys.platform == 'win32':
00332             seps = r'/|\\'
00333         else:
00334             seps = '/'
00335 
00336         vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
00337                     '_darcs']
00338         vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
00339         self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)

Here is the call graph for this function:

Here is the caller graph for this function:

Read the manifest file (named by 'self.manifest') and use it to
fill in 'self.filelist', the list of files to include in the source
distribution.

Definition at line 367 of file sdist.py.

00367 
00368     def read_manifest(self):
00369         """Read the manifest file (named by 'self.manifest') and use it to
00370         fill in 'self.filelist', the list of files to include in the source
00371         distribution.
00372         """
00373         log.info("reading manifest file '%s'", self.manifest)
00374         manifest = open(self.manifest)
00375         for line in manifest:
00376             # ignore comments and blank lines
00377             line = line.strip()
00378             if line.startswith('#') or not line:
00379                 continue
00380             self.filelist.append(line)
00381         manifest.close()

Here is the caller graph for this function:

Read and parse manifest template file named by self.template.

(usually "MANIFEST.in") The parsing and processing is done by
'self.filelist', which updates itself accordingly.

Definition at line 290 of file sdist.py.

00290 
00291     def read_template(self):
00292         """Read and parse manifest template file named by self.template.
00293 
00294         (usually "MANIFEST.in") The parsing and processing is done by
00295         'self.filelist', which updates itself accordingly.
00296         """
00297         log.info("reading manifest template '%s'", self.template)
00298         template = TextFile(self.template, strip_comments=1, skip_blanks=1,
00299                             join_lines=1, lstrip_ws=1, rstrip_ws=1,
00300                             collapse_join=1)
00301 
00302         try:
00303             while True:
00304                 line = template.readline()
00305                 if line is None:            # end of file
00306                     break
00307 
00308                 try:
00309                     self.filelist.process_template_line(line)
00310                 except DistutilsTemplateError as msg:
00311                     self.warn("%s, line %d: %s" % (template.filename,
00312                                                    template.current_line,
00313                                                    msg))
00314         finally:
00315             template.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 140 of file sdist.py.

00140 
00141     def run(self):
00142         # 'filelist' contains the list of files that will make up the
00143         # manifest
00144         self.filelist = FileList()
00145 
00146         # Run sub commands
00147         for cmd_name in self.get_sub_commands():
00148             self.run_command(cmd_name)
00149 
00150         # Do whatever it takes to get the list of files to process
00151         # (process the manifest template, read an existing manifest,
00152         # whatever).  File list is accumulated in 'self.filelist'.
00153         self.get_file_list()
00154 
00155         # If user just wanted us to regenerate the manifest, stop now.
00156         if self.manifest_only:
00157             return
00158 
00159         # Otherwise, go ahead and create the source distribution tarball,
00160         # or zipfile, or whatever.
00161         self.make_distribution()

Here is the caller graph for this function:

Write the file list in 'self.filelist' (presumably as filled in
by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'.

Definition at line 340 of file sdist.py.

00340 
00341     def write_manifest(self):
00342         """Write the file list in 'self.filelist' (presumably as filled in
00343         by 'add_defaults()' and 'read_template()') to the manifest file
00344         named by 'self.manifest'.
00345         """
00346         if self._manifest_is_not_generated():
00347             log.info("not writing to manually maintained "
00348                      "manifest file '%s'" % self.manifest)
00349             return
00350 
00351         content = self.filelist.files[:]
00352         content.insert(0, '# file GENERATED by distutils, do NOT edit')
00353         self.execute(file_util.write_file, (self.manifest, content),
00354                      "writing manifest file '%s'" % self.manifest)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 114 of file sdist.py.

Initial value:
['use-defaults', 'prune',
                       'manifest-only', 'force-manifest',
                       'keep-temp', 'metadata-check']

Definition at line 79 of file sdist.py.

Initial value:
{'posix': 'gztar',
                      'nt': 'zip' }

Definition at line 91 of file sdist.py.

string distutils.command.sdist.sdist.description = "create a source distribution (tarball, zip file, etc.)" [static]

Definition at line 36 of file sdist.py.

Definition at line 112 of file sdist.py.

Definition at line 143 of file sdist.py.

Definition at line 108 of file sdist.py.

Definition at line 110 of file sdist.py.

Initial value:
[
        ('help-formats', None,
         "list available distribution formats", show_formats),
        ]

Definition at line 83 of file sdist.py.

Definition at line 111 of file sdist.py.

Definition at line 100 of file sdist.py.

Definition at line 107 of file sdist.py.

Definition at line 115 of file sdist.py.

Initial value:
{'no-defaults': 'use-defaults',
                    'no-prune': 'prune' }

Definition at line 88 of file sdist.py.

Definition at line 105 of file sdist.py.

Definition at line 94 of file sdist.py.

Definition at line 99 of file sdist.py.

Definition at line 104 of file sdist.py.

Definition at line 44 of file sdist.py.


The documentation for this class was generated from the following file: