diff options
| author | Erik Bray <embray@stsci.edu> | 2012-09-11 07:48:59 -0400 |
|---|---|---|
| committer | Erik Bray <embray@stsci.edu> | 2012-09-11 07:48:59 -0400 |
| commit | 751bf7fe620330ecfa68ae015ba92088c21f1707 (patch) | |
| tree | 79b42c31d67bb213048a0bc8cecf94996756d706 | |
| parent | d847dbfeee2b2c85d7bc0a66813c33836a9850fa (diff) | |
| parent | 06959116eed7effdbf3af575946f619cdb7fcd71 (diff) | |
| download | python-setuptools-git-751bf7fe620330ecfa68ae015ba92088c21f1707.tar.gz | |
merge
--HG--
branch : distribute
extra : rebase_source : 97f4cdbb2d0c9367836c8675e58b99699cfb50a7
| -rw-r--r-- | CHANGES.txt | 5 | ||||
| -rw-r--r-- | distribute_setup.py | 43 | ||||
| -rw-r--r-- | docs/setuptools.txt | 18 | ||||
| -rwxr-xr-x | setuptools/command/sdist.py | 8 | ||||
| -rw-r--r-- | setuptools/tests/test_sdist.py | 79 |
5 files changed, 134 insertions, 19 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 3eea84eb..b59a0b00 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,11 @@ CHANGES * Issue #313: Support for sdist subcommands (Python 2.7) * Issue #314: test_local_index() would fail an OS X. * Issue #310: Non-ascii characters in a namespace __init__.py causes errors. +* Issue #218: Improved documentation on behavior of `package_data` and + `include_package_data`. Files indicated by `package_data` are now included + in the manifest. +* `distribute_setup.py` now allows a `--download-base` argument for retrieving + distribute from a specified location. ------ 0.6.28 diff --git a/distribute_setup.py b/distribute_setup.py index f3199d12..95ba23c5 100644 --- a/distribute_setup.py +++ b/distribute_setup.py @@ -19,6 +19,8 @@ import time import fnmatch import tempfile import tarfile +import optparse + from distutils import log try: @@ -495,22 +497,39 @@ def _extractall(self, path=".", members=None): self._dbg(1, "tarfile: %s" % e) -def _build_install_args(argv): +def _build_install_args(options): + """ + Build the arguments to 'python setup.py install' on the distribute package + """ install_args = [] - user_install = '--user' in argv - if user_install and sys.version_info < (2, 6): - log.warn("--user requires Python 2.6 or later") - raise SystemExit(1) - if user_install: + if options.user_install: + if sys.version_info < (2, 6): + log.warn("--user requires Python 2.6 or later") + raise SystemExit(1) install_args.append('--user') return install_args - -def main(argv, version=DEFAULT_VERSION): +def _parse_args(): + """ + Parse the command line for options + """ + parser = optparse.OptionParser() + parser.add_option( + '--user', dest='user_install', action='store_true', default=False, + help='install in user site package (requires Python 2.6 or later)') + parser.add_option( + '--download-base', dest='download_base', metavar="URL", + default=DEFAULT_URL, + help='alternative URL from where to download the distribute package') + options, args = parser.parse_args() + # positional arguments are ignored + return options + +def main(version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" - tarball = download_setuptools() - _install(tarball, _build_install_args(argv)) - + options = _parse_args() + tarball = download_setuptools(download_base=options.download_base) + _install(tarball, _build_install_args(options)) if __name__ == '__main__': - main(sys.argv[1:]) + main() diff --git a/docs/setuptools.txt b/docs/setuptools.txt index d04973e7..31eedcb1 100644 --- a/docs/setuptools.txt +++ b/docs/setuptools.txt @@ -756,17 +756,18 @@ e.g.:: include_package_data = True ) -This tells setuptools to install any data files it finds in your packages. The -data files must be under CVS or Subversion control, or else they must be +This tells setuptools to install any data files it finds in your packages. +The data files must be under CVS or Subversion control, or else they must be specified via the distutils' ``MANIFEST.in`` file. (They can also be tracked by another revision control system, using an appropriate plugin. See the section below on `Adding Support for Other Revision Control Systems`_ for information on how to write such plugins.) -If you want finer-grained control over what files are included (for example, if -you have documentation files in your package directories and want to exclude -them from installation), then you can also use the ``package_data`` keyword, -e.g.:: +If the data files are not under version control, or are not in a supported +version control system, or if you want finer-grained control over what files +are included (for example, if you have documentation files in your package +directories and want to exclude them from installation), then you can also use +the ``package_data`` keyword, e.g.:: from setuptools import setup, find_packages setup( @@ -822,7 +823,10 @@ converts slashes to appropriate platform-specific separators at build time. (Note: although the ``package_data`` argument was previously only available in ``setuptools``, it was also added to the Python ``distutils`` package as of Python 2.4; there is `some documentation for the feature`__ available on the -python.org website.) +python.org website. If using the setuptools-specific ``include_package_data`` +argument, files specified by ``package_data`` will *not* be automatically +added to the manifest unless they are tracked by a supported version control +system, or are listed in the MANIFEST.in file.) __ http://docs.python.org/dist/node11.html diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 91c4fd1b..a176f635 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -198,6 +198,14 @@ class sdist(_sdist): if self.distribution.has_pure_modules(): build_py = self.get_finalized_command('build_py') self.filelist.extend(build_py.get_source_files()) + # This functionality is incompatible with include_package_data, and + # will in fact create an infinite recursion if include_package_data + # is True. Use of include_package_data will imply that + # distutils-style automatic handling of package_data is disabled + if not self.distribution.include_package_data: + for _, src_dir, _, filenames in build_py.data_files: + self.filelist.extend([os.path.join(src_dir, filename) + for filename in filenames]) if self.distribution.has_ext_modules(): build_ext = self.get_finalized_command('build_ext') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py new file mode 100644 index 00000000..8d9ed922 --- /dev/null +++ b/setuptools/tests/test_sdist.py @@ -0,0 +1,79 @@ +"""sdist tests""" + + +import os +import shutil +import sys +import tempfile +import unittest +from StringIO import StringIO + + +from setuptools.command.sdist import sdist +from setuptools.dist import Distribution + + +SETUP_ATTRS = { + 'name': 'sdist_test', + 'version': '0.0', + 'packages': ['sdist_test'], + 'package_data': {'sdist_test': ['*.txt']} +} + + +SETUP_PY = """\ +from setuptools import setup + +setup(**%r) +""" % SETUP_ATTRS + + +class TestSdistTest(unittest.TestCase): + def setUp(self): + self.temp_dir = tempfile.mkdtemp() + f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') + f.write(SETUP_PY) + f.close() + # Set up the rest of the test package + test_pkg = os.path.join(self.temp_dir, 'sdist_test') + os.mkdir(test_pkg) + # *.rst was not included in package_data, so c.rst should not be + # automatically added to the manifest when not under version control + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + # Just touch the files; their contents are irrelevant + open(os.path.join(test_pkg, fname), 'w').close() + + self.old_cwd = os.getcwd() + os.chdir(self.temp_dir) + + def tearDown(self): + os.chdir(self.old_cwd) + shutil.rmtree(self.temp_dir) + + def test_package_data_in_sdist(self): + """Regression test for pull request #4: ensures that files listed in + package_data are included in the manifest even if they're not added to + version control. + """ + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # squelch output + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = StringIO() + sys.stderr = StringIO() + try: + cmd.run() + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr + + manifest = cmd.filelist.files + + self.assert_(os.path.join('sdist_test', 'a.txt') in manifest) + self.assert_(os.path.join('sdist_test', 'b.txt') in manifest) + self.assert_(os.path.join('sdist_test', 'c.rst') not in manifest) |
