aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-12-15 02:45:03 +0000
committerPJ Eby <distutils-sig@python.org>2005-12-15 02:45:03 +0000
commitd989230127c6e16c505096f6150db977e61478b3 (patch)
treeed87402243ca1a75876e7a640bd983666ac2025c
parent1b77dd8e7845b5ac38fc7367796290dd65b8c531 (diff)
downloadexternal_python_setuptools-d989230127c6e16c505096f6150db977e61478b3.tar.gz
external_python_setuptools-d989230127c6e16c505096f6150db977e61478b3.tar.bz2
external_python_setuptools-d989230127c6e16c505096f6150db977e61478b3.zip
Added the ``exclude_package_data`` keyword to ``setup()``, allowing you
to trim back files included via the ``package_data`` and ``include_package_data`` options. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041693
-rwxr-xr-xsetup.py4
-rwxr-xr-xsetuptools.egg-info/entry_points.txt2
-rwxr-xr-xsetuptools.txt109
-rw-r--r--setuptools/command/build_py.py47
-rw-r--r--setuptools/dist.py28
5 files changed, 148 insertions, 42 deletions
diff --git a/setup.py b/setup.py
index 3073f546..2ccf260e 100755
--- a/setup.py
+++ b/setup.py
@@ -55,6 +55,8 @@ setup(
"entry_points = setuptools.dist:check_entry_points",
"test_suite = setuptools.dist:check_test_suite",
"zip_safe = setuptools.dist:assert_bool",
+ "package_data = setuptools.dist:check_package_data",
+ "exclude_package_data = setuptools.dist:check_package_data",
"include_package_data = setuptools.dist:assert_bool",
],
"egg_info.writers": [
@@ -78,8 +80,6 @@ setup(
-
-
classifiers = [f.strip() for f in """
Development Status :: 3 - Alpha
Intended Audience :: Developers
diff --git a/setuptools.egg-info/entry_points.txt b/setuptools.egg-info/entry_points.txt
index 08ab2ab4..7696452d 100755
--- a/setuptools.egg-info/entry_points.txt
+++ b/setuptools.egg-info/entry_points.txt
@@ -1,8 +1,10 @@
[distutils.setup_keywords]
entry_points = setuptools.dist:check_entry_points
extras_require = setuptools.dist:check_extras
+package_data = setuptools.dist:check_package_data
install_requires = setuptools.dist:check_requirements
include_package_data = setuptools.dist:assert_bool
+exclude_package_data = setuptools.dist:check_package_data
namespace_packages = setuptools.dist:check_nsp
test_suite = setuptools.dist:check_test_suite
eager_resources = setuptools.dist:assert_string_list
diff --git a/setuptools.txt b/setuptools.txt
index 811eb8b8..56047527 100755
--- a/setuptools.txt
+++ b/setuptools.txt
@@ -26,8 +26,8 @@ Feature Highlights:
the closest thing to CPAN currently available for Python.)
* Create `Python Eggs <http://peak.telecommunity.com/DevCenter/PythonEggs>`_ -
- a single-file importable distribution format
-
+ a single-file importable distribution format
+
* Include data files inside your package directories, where your code can
actually use them. (Python 2.4 distutils also supports this feature, but
setuptools provides the feature for Python 2.3 packages also, and supports
@@ -147,7 +147,7 @@ Of course, before you release your project to PyPI, you'll want to add a bit
more information to your setup script to help people find or learn about your
project. And maybe your project will have grown by then to include a few
dependencies, and perhaps some data files and scripts::
-
+
from setuptools import setup, find_packages
setup(
name = "HelloWorld",
@@ -206,7 +206,7 @@ they are appended to. So, revision ``2.4`` is *newer* than revision ``2.4c1``,
which in turn is newer than ``2.4b1`` or ``2.4a1``. Postrelease tags make
a version be considered *newer* than the version they are appended to. So,
revisions like ``2.4-1`` and ``2.4pl3`` are newer than ``2.4``, but are *older*
-than ``2.4.1`` (which has a higher release number).
+than ``2.4.1`` (which has a higher release number).
A pre-release tag is a series of letters that are alphabetically before
"final". Some examples of prerelease tags would include ``alpha``, ``beta``,
@@ -288,11 +288,21 @@ unless you need the associated ``setuptools`` feature.
CVS or Subversion control, or which are specified by your ``MANIFEST.in``
file. For more information, see the section below on `Including Data
Files`_.
-
+
+``exclude_package_data``
+ A dictionary mapping package names to lists of glob patterns that should
+ be *excluded* from your package directories. You can use this to trim back
+ any excess files included by ``include_package_data``. For a complete
+ description and examples, see the section below on `Including Data Files`_.
+
``package_data``
A dictionary mapping package names to lists of glob patterns. For a
complete description and examples, see the section below on `Including
- Data Files`_.
+ Data Files`_. You do not need to use this option if you are using
+ ``include_package_data``, unless you need to add e.g. files that are
+ generated by your setup script and build process. (And are therefore not
+ in source control or are files that you don't want to include in your
+ source distribution.)
``zip_safe``
A boolean (True or False) flag specifying whether the project can be
@@ -357,7 +367,7 @@ unless you need the associated ``setuptools`` feature.
``tests_require``
If your project's tests need one or more additional packages besides those
- needed to install it, you can use this option to specify them. It should
+ needed to install it, you can use this option to specify them. It should
be a string or list of strings specifying what other distributions need to
be present for the package's tests to run. When you run the ``test``
command, ``setuptools`` will attempt to obtain these (even going
@@ -401,7 +411,7 @@ such projects also need something like ``package_dir = {'':'src'}`` in their
Anyway, ``find_packages()`` walks the target directory, and finds Python
packages by looking for ``__init__.py`` files. It then filters the list of
-packages using the exclusion patterns.
+packages using the exclusion patterns.
Exclusion patterns are package names, optionally including wildcards. For
example, ``find_packages(exclude=["*.tests"])`` will exclude all packages whose
@@ -627,7 +637,7 @@ are placed in a platform-specific location. However, the most common use case
for data files distributed with a package is for use *by* the package, usually
by including the data files in the package directory.
-Setuptools offers two ways to specify data files to be included in your
+Setuptools offers three ways to specify data files to be included in your
packages. First, you can simply use the ``include_package_data`` keyword,
e.g.::
@@ -643,7 +653,7 @@ specified via the distutils' ``MANIFEST.in`` file.
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 use the ``package_data`` keyword instead,
+them from installation), then you can also use the ``package_data`` keyword,
e.g.::
from setuptools import setup, find_packages
@@ -678,7 +688,7 @@ The setuptools setup file might look like this::
...
packages = find_packages('src'), # include all packages under src
package_dir = {'':'src'}, # tell distutils packages are under src
-
+
package_data = {
# If any package contains *.txt files, include them:
'': ['*.txt'],
@@ -702,7 +712,56 @@ converts slashes to appropriate platform-specific separators at build time.
Python 2.4; there is `some documentation for the feature`__ available on the
python.org website.)
-__ http://docs.python.org/dist/node11.html
+__ http://docs.python.org/dist/node11.html
+
+Sometimes, the ``include_package_data`` or ``package_data`` options alone
+aren't sufficient to precisely define what files you want included. For
+example, you may want to include package README files in your revision control
+system and source distributions, but exclude them from being installed. So,
+setuptools offers an ``exclude_package_data`` option as well, that allows you
+to do things like this::
+
+ from setuptools import setup, find_packages
+ setup(
+ ...
+ packages = find_packages('src'), # include all packages under src
+ package_dir = {'':'src'}, # tell distutils packages are under src
+
+ include_package_data = True, # include everything in source control
+
+ # ...but exclude README.txt from all packages
+ exclude_package_data = { '': ['README.txt'] },
+ )
+
+The ``exclude_package_data`` option is a dictionary mapping package names to
+lists of wildcard patterns, just like the ``package_data`` option. And, just
+as with that option, a key of ``''`` will apply the given pattern(s) to all
+packages. However, any files that match these patterns will be *excluded*
+from installation, even if they were listed in ``package_data`` or were
+included as a result of using ``include_package_data``.
+
+In summary, the three options allow you to:
+
+``include_package_data``
+ Accept all data files and directories matched by ``MANIFEST.in`` or found
+ in source control.
+
+``package_data``
+ Specify additional patterns to match files and directories that may or may
+ not be matched by ``MANIFEST.in`` or found in source control.
+
+``exclude_package_data``
+ Specify patterns for data files and directories that should *not* be
+ included when a package is installed, even if they would otherwise have
+ been included due to the use of the preceding options.
+
+NOTE: Due to the way the distutils build process works, a data file that you
+include in your project and then stop including may be "orphaned" in your
+project's build directories, requiring you to run ``setup.py clean --all`` to
+fully remove them. This may also be important for your users and contributors
+if they track intermediate revisions of your project using Subversion; be sure
+to let them know when you make changes that remove files from inclusion so they
+can run ``setup.py clean --all``.
Accessing Data Files at Runtime
@@ -1149,7 +1208,7 @@ egg distributions by adding one or more of the following to the project's
manually-specified post-release tag, such as a build or revision number
(``--tag-build=STRING, -bSTRING``)
-* A "last-modified revision number" string generated automatically from
+* A "last-modified revision number" string generated automatically from
Subversion's metadata (assuming your project is being built from a Subversion
"working copy") (``--tag-svn-revision, -r``)
@@ -1796,7 +1855,7 @@ only the N most-recently modified files matching a given pattern.
you will use a glob pattern like ``.zip`` or ``.egg`` to match files of
the specified type. Note that each supplied pattern is treated as a
distinct group of files for purposes of selecting files to delete.
-
+
``--keep=COUNT, -k COUNT``
Number of matching distributions to keep. For each group of files
identified by a pattern specified with the ``--match`` option, delete all
@@ -1839,14 +1898,14 @@ command line to the project's local ``setup.cfg`` file, unless you use one of
the `configuration file options`_ to change where the options are saved. For
example, this command does the same as above, but saves the compiler setting
to the site-wide (global) distutils configuration::
-
+
setup.py build --compiler=mingw32 saveopts -g
Note that it doesn't matter where you place the ``saveopts`` command on the
command line; it will still save all the options specified for all commands.
For example, this is another valid way to spell the last example::
- setup.py saveopts -g build --compiler=mingw32
+ setup.py saveopts -g build --compiler=mingw32
Note, however, that all of the commands specified are always run, regardless of
where ``saveopts`` is placed on the command line.
@@ -1863,7 +1922,7 @@ global or per-user configuration files, or to a manually-specified filename.
Save settings to the global ``distutils.cfg`` file inside the ``distutils``
package directory. You must have write access to that directory to use
this option. You also can't combine this option with ``-u`` or ``-f``.
-
+
``--user-config, -u``
Save settings to the current user's ``~/.pydistutils.cfg`` (POSIX) or
``$HOME/pydistutils.cfg`` (Windows) file. You can't combine this option
@@ -1896,7 +1955,7 @@ names)::
**Example 2**. Remove any setting for the distutils default package
installation directory (short option names)::
-
+
setup.py setopt -c install -o install_lib -r
@@ -1982,7 +2041,7 @@ types.) To upload files, you must include the ``upload`` command *after* the
setup.py bdist_egg upload # create an egg and upload it
setup.py sdist upload # create a source distro and upload it
setup.py sdist bdist_egg upload # create and upload both
-
+
Note that to upload files for a project, the corresponding version must already
be registered with PyPI, using the distutils ``register`` command. It's
usually a good idea to include the ``register`` command at the start of the
@@ -2223,7 +2282,11 @@ Release Notes/Change History
* Added the ``include_package_data`` keyword to ``setup()``, allowing you to
automatically include any package data listed in revision control or
- ``MANIFEST.in``.
+ ``MANIFEST.in``
+
+ * Added the ``exclude_package_data`` keyword to ``setup()``, allowing you to
+ trim back files included via the ``package_data`` and
+ ``include_package_data`` options.
* Fixed ``--tag-svn-revision`` not working when run from a source
distribution.
@@ -2286,7 +2349,7 @@ Release Notes/Change History
0.6a5
* Fixed missing gui/cli .exe files in distribution. Fixed bugs in tests.
-
+
0.6a3
* Added ``gui_scripts`` entry point group to allow installing GUI scripts
on Windows and other platforms. (The special handling is only for Windows;
@@ -2301,7 +2364,7 @@ Release Notes/Change History
0.6a1
* Added support for building "old-style" RPMs that don't install an egg for
the target package, using a ``--no-egg`` option.
-
+
* The ``build_ext`` command now works better when using the ``--inplace``
option and multiple Python versions. It now makes sure that all extensions
match the current Python version, even if newer copies were built for a
@@ -2339,7 +2402,7 @@ Release Notes/Change History
* The vestigial ``depends`` command has been removed. It was never finished
or documented, and never would have worked without EasyInstall - which it
pre-dated and was never compatible with.
-
+
0.5a12
* The zip-safety scanner now checks for modules that might be used with
``python -m``, and marks them as unsafe for zipping, since Python 2.4 can't
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
index 35b9c57e..4d779f57 100644
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -1,4 +1,4 @@
-import os.path, sys
+import os.path, sys, fnmatch
from distutils.command.build_py import build_py as _build_py
from distutils.util import convert_path
from glob import glob
@@ -12,10 +12,10 @@ class build_py(_build_py):
Also, this version of the 'build_py' command allows you to specify both
'py_modules' and 'packages' in the same setup operation.
"""
-
def finalize_options(self):
_build_py.finalize_options(self)
self.package_data = self.distribution.package_data
+ self.exclude_package_data = self.distribution.exclude_package_data or {}
if 'data_files' in self.__dict__: del self.__dict__['data_files']
def run(self):
@@ -68,7 +68,7 @@ class build_py(_build_py):
for pattern in globs:
# Each pattern has to be converted to a platform-specific path
files.extend(glob(os.path.join(src_dir, convert_path(pattern))))
- return files
+ return self.exclude_data_files(package, src_dir, files)
def build_package_data(self):
"""Copy data files into build directory"""
@@ -162,3 +162,44 @@ class build_py(_build_py):
+ def exclude_data_files(self, package, src_dir, files):
+ """Filter filenames for package's data files in 'src_dir'"""
+ globs = (self.exclude_package_data.get('', [])
+ + self.exclude_package_data.get(package, []))
+ bad = []
+ for pattern in globs:
+ bad.extend(
+ fnmatch.filter(
+ files, os.path.join(src_dir, convert_path(pattern))
+ )
+ )
+ bad = dict.fromkeys(bad)
+ return [f for f in files if f not in bad]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 17c9f149..fb7df8ce 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -103,24 +103,24 @@ def check_test_suite(dist, attr, value):
raise DistutilsSetupError("test_suite must be a string")
+def check_package_data(dist, attr, value):
+ """Verify that value is a dictionary of package names to glob lists"""
+ if isinstance(value,dict):
+ for k,v in value.items():
+ if not isinstance(k,str): break
+ try: iter(v)
+ except TypeError:
+ break
+ else:
+ return
+ raise DistutilsSetupError(
+ attr+" must be a dictionary mapping package names to lists of "
+ "wildcard patterns"
+ )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
class Distribution(_Distribution):
"""Distribution with support for features, tests, and package data