Commit 6d9fe7ee authored by Tarek Ziadé's avatar Tarek Ziadé

pep8-fied distutils.command.sdist + more tests

parent 1a7f413d
...@@ -30,7 +30,7 @@ def show_formats(): ...@@ -30,7 +30,7 @@ def show_formats():
FancyGetopt(formats).print_help( FancyGetopt(formats).print_help(
"List of available source distribution formats:") "List of available source distribution formats:")
class sdist (Command): class sdist(Command):
description = "create a source distribution (tarball, zip file, etc.)" description = "create a source distribution (tarball, zip file, etc.)"
...@@ -77,10 +77,10 @@ class sdist (Command): ...@@ -77,10 +77,10 @@ class sdist (Command):
negative_opt = {'no-defaults': 'use-defaults', negative_opt = {'no-defaults': 'use-defaults',
'no-prune': 'prune' } 'no-prune': 'prune' }
default_format = { 'posix': 'gztar', default_format = {'posix': 'gztar',
'nt': 'zip' } 'nt': 'zip' }
def initialize_options (self): def initialize_options(self):
# 'template' and 'manifest' are, respectively, the names of # 'template' and 'manifest' are, respectively, the names of
# the manifest template and manifest file. # the manifest template and manifest file.
self.template = None self.template = None
...@@ -100,8 +100,7 @@ class sdist (Command): ...@@ -100,8 +100,7 @@ class sdist (Command):
self.archive_files = None self.archive_files = None
def finalize_options(self):
def finalize_options (self):
if self.manifest is None: if self.manifest is None:
self.manifest = "MANIFEST" self.manifest = "MANIFEST"
if self.template is None: if self.template is None:
...@@ -124,9 +123,7 @@ class sdist (Command): ...@@ -124,9 +123,7 @@ class sdist (Command):
if self.dist_dir is None: if self.dist_dir is None:
self.dist_dir = "dist" self.dist_dir = "dist"
def run(self):
def run (self):
# 'filelist' contains the list of files that will make up the # 'filelist' contains the list of files that will make up the
# manifest # manifest
self.filelist = FileList() self.filelist = FileList()
...@@ -148,8 +145,7 @@ class sdist (Command): ...@@ -148,8 +145,7 @@ class sdist (Command):
# or zipfile, or whatever. # or zipfile, or whatever.
self.make_distribution() self.make_distribution()
def check_metadata(self):
def check_metadata (self):
"""Ensure that all required elements of meta-data (name, version, """Ensure that all required elements of meta-data (name, version,
URL, (author and author_email) or (maintainer and URL, (author and author_email) or (maintainer and
maintainer_email)) are supplied by the Distribution object; warn if maintainer_email)) are supplied by the Distribution object; warn if
...@@ -179,17 +175,13 @@ class sdist (Command): ...@@ -179,17 +175,13 @@ class sdist (Command):
"or (maintainer and maintainer_email) " + "or (maintainer and maintainer_email) " +
"must be supplied") "must be supplied")
# check_metadata () def get_file_list(self):
def get_file_list (self):
"""Figure out the list of files to include in the source """Figure out the list of files to include in the source
distribution, and put it in 'self.filelist'. This might involve distribution, and put it in 'self.filelist'. This might involve
reading the manifest template (and writing the manifest), or just reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all reading the manifest, or just using the default file set -- it all
depends on the user's options and the state of the filesystem. depends on the user's options and the state of the filesystem.
""" """
# If we have a manifest template, see if it's newer than the # If we have a manifest template, see if it's newer than the
# manifest; if so, we'll regenerate the manifest. # manifest; if so, we'll regenerate the manifest.
template_exists = os.path.isfile(self.template) template_exists = os.path.isfile(self.template)
...@@ -249,10 +241,7 @@ class sdist (Command): ...@@ -249,10 +241,7 @@ class sdist (Command):
else: else:
self.read_manifest() self.read_manifest()
# get_file_list () def add_defaults(self):
def add_defaults (self):
"""Add all the default files to self.filelist: """Add all the default files to self.filelist:
- README or README.txt - README or README.txt
- setup.py - setup.py
...@@ -334,10 +323,7 @@ class sdist (Command): ...@@ -334,10 +323,7 @@ class sdist (Command):
build_scripts = self.get_finalized_command('build_scripts') build_scripts = self.get_finalized_command('build_scripts')
self.filelist.extend(build_scripts.get_source_files()) self.filelist.extend(build_scripts.get_source_files())
# add_defaults () def read_template(self):
def read_template (self):
"""Read and parse manifest template file named by self.template. """Read and parse manifest template file named by self.template.
(usually "MANIFEST.in") The parsing and processing is done by (usually "MANIFEST.in") The parsing and processing is done by
...@@ -364,10 +350,7 @@ class sdist (Command): ...@@ -364,10 +350,7 @@ class sdist (Command):
template.current_line, template.current_line,
msg)) msg))
# read_template () def prune_file_list(self):
def prune_file_list (self):
"""Prune off branches that might slip into the file list as created """Prune off branches that might slip into the file list as created
by 'read_template()', but really don't belong there: by 'read_template()', but really don't belong there:
* the build tree (typically "build") * the build tree (typically "build")
...@@ -393,7 +376,7 @@ class sdist (Command): ...@@ -393,7 +376,7 @@ class sdist (Command):
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps) vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1) self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
def write_manifest (self): def write_manifest(self):
"""Write the file list in 'self.filelist' (presumably as filled in """Write the file list in 'self.filelist' (presumably as filled in
by 'add_defaults()' and 'read_template()') to the manifest file by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'. named by 'self.manifest'.
...@@ -402,10 +385,7 @@ class sdist (Command): ...@@ -402,10 +385,7 @@ class sdist (Command):
(self.manifest, self.filelist.files), (self.manifest, self.filelist.files),
"writing manifest file '%s'" % self.manifest) "writing manifest file '%s'" % self.manifest)
# write_manifest () def read_manifest(self):
def read_manifest (self):
"""Read the manifest file (named by 'self.manifest') and use it to """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 fill in 'self.filelist', the list of files to include in the source
distribution. distribution.
...@@ -421,10 +401,7 @@ class sdist (Command): ...@@ -421,10 +401,7 @@ class sdist (Command):
self.filelist.append(line) self.filelist.append(line)
manifest.close() manifest.close()
# read_manifest () def make_release_tree(self, base_dir, files):
def make_release_tree (self, base_dir, files):
"""Create the directory tree that will become the source """Create the directory tree that will become the source
distribution archive. All directories implied by the filenames in distribution archive. All directories implied by the filenames in
'files' are created under 'base_dir', and then we hard link or copy 'files' are created under 'base_dir', and then we hard link or copy
...@@ -466,9 +443,7 @@ class sdist (Command): ...@@ -466,9 +443,7 @@ class sdist (Command):
self.distribution.metadata.write_pkg_info(base_dir) self.distribution.metadata.write_pkg_info(base_dir)
# make_release_tree () def make_distribution(self):
def make_distribution (self):
"""Create the source distribution(s). First, we create the release """Create the source distribution(s). First, we create the release
tree with 'make_release_tree()'; then, we create all required tree with 'make_release_tree()'; then, we create all required
archive files (according to 'self.formats') from the release tree. archive files (according to 'self.formats') from the release tree.
...@@ -497,10 +472,8 @@ class sdist (Command): ...@@ -497,10 +472,8 @@ class sdist (Command):
if not self.keep_temp: if not self.keep_temp:
dir_util.remove_tree(base_dir, dry_run=self.dry_run) dir_util.remove_tree(base_dir, dry_run=self.dry_run)
def get_archive_files (self): def get_archive_files(self):
"""Return the list of archive files created when the command """Return the list of archive files created when the command
was run, or None if the command hasn't run yet. was run, or None if the command hasn't run yet.
""" """
return self.archive_files return self.archive_files
# class sdist
...@@ -13,7 +13,7 @@ from distutils.command.sdist import sdist ...@@ -13,7 +13,7 @@ from distutils.command.sdist import sdist
from distutils.command.sdist import show_formats from distutils.command.sdist import show_formats
from distutils.core import Distribution from distutils.core import Distribution
from distutils.tests.test_config import PyPIRCCommandTestCase from distutils.tests.test_config import PyPIRCCommandTestCase
from distutils.errors import DistutilsExecError from distutils.errors import DistutilsExecError, DistutilsOptionError
from distutils.spawn import find_executable from distutils.spawn import find_executable
from distutils.tests import support from distutils.tests import support
from distutils.archive_util import ARCHIVE_FORMATS from distutils.archive_util import ARCHIVE_FORMATS
...@@ -224,6 +224,28 @@ class sdistTestCase(PyPIRCCommandTestCase): ...@@ -224,6 +224,28 @@ class sdistTestCase(PyPIRCCommandTestCase):
if line.strip().startswith('--formats=')] if line.strip().startswith('--formats=')]
self.assertEquals(len(output), num_formats) self.assertEquals(len(output), num_formats)
def test_finalize_options(self):
dist, cmd = self.get_cmd()
cmd.finalize_options()
# default options set by finalize
self.assertEquals(cmd.manifest, 'MANIFEST')
self.assertEquals(cmd.template, 'MANIFEST.in')
self.assertEquals(cmd.dist_dir, 'dist')
# formats has to be a string splitable on (' ', ',') or
# a stringlist
cmd.formats = 1
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
cmd.formats = ['zip']
cmd.finalize_options()
# formats has to be known
cmd.formats = 'supazipa'
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
def test_suite(): def test_suite():
return unittest.makeSuite(sdistTestCase) return unittest.makeSuite(sdistTestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment