summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-07 21:38:29 +0000
committerpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-07 21:38:29 +0000
commitf4838c7996e6281401cb6325ab3628f518ac712a (patch)
treee0c86ce85a78adcafdaf2d476aa12e7ef6275ee3
parentda3d6a1248fdf536a620cfd6ef3a15e99919c0be (diff)
downloadwsgiref-f4838c7996e6281401cb6325ab3628f518ac712a.tar.gz
Added "features", allowing a distribution to be broken down into pieces
that can be optionally installed or not, controlled by '--with-X' and '--without-X' options. Features can depend on one another, and add or remove packages, extensions, libraries, etc. from the base distribution. Added tons of docstrings for the new stuff, and the existing package data and tests support. Added lots of tests. This version is finally ready, I think, for people to actually look at. git-svn-id: svn://svn.eby-sarna.com/svnroot/wsgiref@235 571e12c6-e1fa-0310-aee7-ff1267fa46bd
-rw-r--r--setuptools/__init__.py22
-rw-r--r--setuptools/command/build_py.py101
-rw-r--r--setuptools/command/test.py16
-rw-r--r--setuptools/dist.py445
-rw-r--r--setuptools/tests/__init__.py217
5 files changed, 739 insertions, 62 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index f477a6e..6baf6e5 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -1,12 +1,24 @@
-import distutils.core, setuptools.command
+"""Extensions to the 'distutils' for large or complex distributions"""
-# XXX from deps import Dependency, Distro
+import distutils.core, setuptools.command
+from setuptools.dist import Distribution, Feature
+from distutils.core import Command, Extension
-__all__ = ['setup', ] # XXX Dependency, Distro
+__all__ = [
+ 'setup', 'Distribution', 'Feature', 'Command', 'Extension'
+]
def setup(**attrs):
- from setuptools.dist import Distribution
- attrs.setdefault("distclass",Distribution)
+
+ """Do package setup
+
+ This function takes the same arguments as 'distutils.core.setup()', except
+ that the default distribution class is 'setuptools.dist.Distribution'. See
+ that class' documentation for details on the new keyword arguments that it
+ makes available via this function.
+ """
+
+ attrs.setdefault("distclass",Distribution)
return distutils.core.setup(**attrs)
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
index cff9bcb..f9dfa43 100644
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -5,11 +5,25 @@ import os.path
class build_py(_build_py):
- def initialize_options(self):
- _build_py.initialize_options(self)
+ """Enhanced 'build_py' command that includes data files with packages
+
+ The data files are specified via a 'package_data' argument to 'setup()'.
+ See 'setuptools.dist.Distribution' for more details.
+
+ 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.data_files = self.get_data_files()
+
def run(self):
+
+ """Build modules, packages, and copy data files to build directory"""
+
if not self.py_modules and not self.packages:
return
@@ -20,68 +34,81 @@ class build_py(_build_py):
self.build_packages()
self.build_package_data()
+ # Only compile actual .py files, using our base class' idea of what our
+ # output files are.
self.byte_compile(_build_py.get_outputs(self,include_bytecode=0))
- def build_package_data(self):
- lastdir = None
- for package, package_dir, outdir, files in self.get_package_data():
- for file in files:
- outfile = os.path.join(outdir,file)
- self.mkpath(os.path.dirname(outfile))
- self.copy_file(
- os.path.join(package_dir,file), outfile
- )
- def get_outputs(self, include_bytecode=1):
- return _build_py.get_outputs(include_bytecode) + [
- os.path.join(outdir,file)
- for package,package_dir,outdir,files in self.get_package_data()
- for file in files
- ]
+ def get_data_files(self):
+
+ """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
- def get_package_data(self):
data = []
+
for package in self.packages:
- package_dir = self.get_package_dir(package)
- outdir = os.path.join(
- *([self.build_lib]+package.split('.'))
- )
- plen = len(package_dir)+1
- files = [
- file[plen:] for file in self.find_package_files(
- package, package_dir
- )
+ # Locate package source directory
+ src_dir = self.get_package_dir(package)
+
+ # Compute package build directory
+ build_dir = os.path.join(*([self.build_lib]+package.split('.')))
+
+ # Length of path to strip from found files
+ plen = len(src_dir)+1
+
+ # Strip directory from globbed filenames
+ filenames = [
+ file[plen:] for file in self.find_data_files(package, src_dir)
]
- data.append( (package, package_dir, outdir, files) )
- return data
- def find_package_files(self, package, package_dir):
+ data.append( (package, src_dir, build_dir, filenames) )
- globs = self.package_data.get('',[])+self.package_data.get(package,[])
+ return data
- files = []
- for pattern in globs:
- files.extend(
- glob(os.path.join(package_dir, convert_path(pattern)))
- )
+ def find_data_files(self, package, src_dir):
- return files
+ """Return filenames for package's data files in 'src_dir'"""
+ globs = self.package_data.get('',[])+self.package_data.get(package,[])
+ files = []
+ 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
+ def build_package_data(self):
+ """Copy data files into build directory"""
+ lastdir = None
+ for package, src_dir, build_dir, filenames in self.data_files:
+ for filename in filenames:
+ target = os.path.join(build_dir,filename)
+ self.mkpath(os.path.dirname(target))
+ self.copy_file(os.path.join(src_dir,filename), target)
+ def get_outputs(self, include_bytecode=1):
+ """Return complete list of files copied to the build directory
+ This includes both '.py' files and data files, as well as '.pyc' and
+ '.pyo' files if 'include_bytecode' is true. (This method is needed for
+ the 'install_lib' command to do its job properly, and to generate a
+ correct installation manifest.)
+ """
+ return _build_py.get_outputs(include_bytecode) + [
+ os.path.join(build_dir,filename)
+ for package,src_dir,build_dir,filenames in self.data_files
+ for filename in filenames
+ ]
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 2509554..4a6cd25 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -44,15 +44,15 @@ class test(Command):
# Install before testing
self.run_command('install')
- if self.test_suite and not self.dry_run:
- import unittest
- unittest.main(None, None, [unittest.__file__]+self.test_args)
-
-
-
-
-
+ if self.test_suite:
+ cmd = ' '.join(self.test_args)
+ if self.dry_run:
+ self.announce('skipping "unittest %s" (dry run)' % cmd)
+ else:
+ self.announce('running "unittest %s"' % cmd)
+ import unittest
+ unittest.main(None, None, [unittest.__file__]+self.test_args)
diff --git a/setuptools/dist.py b/setuptools/dist.py
index e742780..d2e48f1 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -1,18 +1,451 @@
-from distutils.core import Distribution as _Distribution
+__all__ = ['Distribution', 'Feature']
+from distutils.core import Distribution as _Distribution
+from distutils.core import Extension
from setuptools.command.build_py import build_py
+from distutils.errors import DistutilsOptionError, DistutilsPlatformError
+from distutils.errors import DistutilsSetupError
+sequence = tuple, list
class Distribution(_Distribution):
- # 'get_dependencies' command
- requires = ()
+ """Distribution with support for features, tests, and package data
+
+ This is an enhanced version of 'distutils.dist.Distribution' that
+ effectively adds the following new optional keyword arguments to 'setup()':
+
+ 'features' -- a dictionary mapping option names to 'setuptools.Feature'
+ objects. Features are a portion of the distribution that can be
+ included or excluded based on user options, inter-feature dependencies,
+ and availability on the current system. Excluded features are omitted
+ from all setup commands, including source and binary distributions, so
+ you can create multiple distributions from the same source tree.
- # 'test' command
- test_suite = None
+ Feature names should be valid Python identifiers, except that they may
+ contain the '-' (minus) sign. Features can be included or excluded
+ via the command line options '--with-X' and '--without-X', where 'X' is
+ the name of the feature. Whether a feature is included by default, and
+ whether you are allowed to control this from the command line, is
+ determined by the Feature object. See the 'Feature' class for more
+ information.
+
+ 'test_suite' -- the name of a test suite to run for the 'test' command.
+ If the user runs 'python setup.py test', the package will be installed,
+ and the named test suite will be run. The format is the same as
+ would be used on a 'unittest.py' command line. That is, it is the
+ dotted name of an object to import and call to generate a test suite.
+
+ 'package_data' -- a dictionary mapping package names to lists of filenames
+ or globs to use to find data files contained in the named packages.
+ If the dictionary has filenames or globs listed under '""' (the empty
+ string), those names will be searched for in every package, in addition
+ to any names for the specific package. Data files found using these
+ names/globs will be installed along with the package, in the same
+ location as the package. Note that globs are allowed to reference
+ the contents of non-package subdirectories, as long as you use '/' as
+ a path separator. (Globs are automatically converted to
+ platform-specific paths at runtime.)
+
+ In addition to these new keywords, this class also has several new methods
+ for manipulating the distribution's contents. For example, the 'include()'
+ and 'exclude()' methods can be thought of as in-place add and subtract
+ commands that add or remove packages, modules, extensions, and so on from
+ the distribution. They are used by the feature subsystem to configure the
+ distribution for the included and excluded features.
+ """
def __init__ (self, attrs=None):
+ self.features = {}
self.package_data = {}
+ self.test_suite = None
+
_Distribution.__init__(self,attrs)
+
self.cmdclass.setdefault('build_py',build_py)
- # XXX self.cmdclass.setdefault('build',build)
+
+ if self.features:
+ self._set_global_opts_from_features()
+
+
+ def parse_command_line(self):
+ """Process features after parsing command line options"""
+ result = _Distribution.parse_command_line(self)
+ if self.features:
+ self._finalize_features()
+ return result
+
+
+ def _feature_attrname(self,name):
+ """Convert feature name to corresponding option attribute name"""
+ return 'with_'+name.replace('-','_')
+
+
+ def _set_global_opts_from_features(self):
+ """Add --with-X/--without-X options based on optional features"""
+
+ go = []
+ no = self.negative_opt.copy()
+
+ for name,feature in self.features.items():
+ self._set_feature(name,None)
+ feature.validate(self)
+
+ if feature.optional:
+ descr = feature.description
+ incdef = ' (default)'
+ excdef=''
+ if not feature.include_by_default():
+ excdef, incdef = incdef, excdef
+
+ go.append(('with-'+name, None, 'include '+descr+incdef))
+ go.append(('without-'+name, None, 'exclude '+descr+excdef))
+ no['without-'+name] = 'with-'+name
+
+ self.global_options = go + self.global_options
+ self.negative_opt = no
+
+ def _finalize_features(self):
+ """Add/remove features and resolve dependencies between them"""
+
+ # First, flag all the enabled items (and thus their dependencies)
+ for name,feature in self.features.items():
+ enabled = self.feature_is_included(name)
+ if enabled or (enabled is None and feature.include_by_default()):
+ feature.include_in(self)
+ self._set_feature(name,1)
+
+ # Then disable the rest, so that off-by-default features don't
+ # get flagged as errors when they're required by an enabled feature
+ for name,feature in self.features.items():
+ if not self.feature_is_included(name):
+ feature.exclude_from(self)
+ self._set_feature(name,0)
+
+ def _set_feature(self,name,status):
+ """Set feature's inclusion status"""
+ setattr(self,self._feature_attrname(name),status)
+
+ def feature_is_included(self,name):
+ """Return 1 if feature is included, 0 if excluded, 'None' if unknown"""
+ return getattr(self,self._feature_attrname(name))
+
+ def include_feature(self,name):
+ """Request inclusion of feature named 'name'"""
+
+ if self.feature_is_included(name)==0:
+ descr = self.features[name].description
+ raise DistutilsOptionError(
+ descr + " is required, but was excluded or is not available"
+ )
+ self.features[name].include_in(self)
+ self._set_feature(name,1)
+
+ def include(self,**attrs):
+ """Add items to distribution that are named in keyword arguments
+
+ For example, 'dist.exclude(py_modules=["x"])' would add 'x' to
+ the distribution's 'py_modules' attribute, if it was not already
+ there.
+
+ Currently, this method only supports inclusion for attributes that are
+ lists or tuples. If you need to add support for adding to other
+ attributes in this or a subclass, you can add an '_include_X' method,
+ where 'X' is the name of the attribute. The method will be called with
+ the value passed to 'include()'. So, 'dist.include(foo={"bar":"baz"})'
+ will try to call 'dist._include_foo({"bar":"baz"})', which can then
+ handle whatever special inclusion logic is needed.
+ """
+ for k,v in attrs.items():
+ include = getattr(self, '_include_'+k, None)
+ if include:
+ include(v)
+ else:
+ self._include_misc(k,v)
+
+ def exclude_package(self,package):
+ """Remove packages, modules, and extensions in named package"""
+
+ pfx = package+'.'
+ if self.packages:
+ self.packages = [
+ p for p in self.packages
+ if p<>package and not p.startswith(pfx)
+ ]
+
+ if self.py_modules:
+ self.py_modules = [
+ p for p in self.py_modules
+ if p<>package and not p.startswith(pfx)
+ ]
+
+ if self.ext_modules:
+ self.ext_modules = [
+ p for p in self.ext_modules
+ if p.name<>package and not p.name.startswith(pfx)
+ ]
+
+
+ def has_contents_for(self,package):
+ """Return true if 'exclude_package(package)' would do something"""
+
+ pfx = package+'.'
+
+ for p in self.packages or ():
+ if p==package or p.startswith(pfx):
+ return True
+
+ for p in self.py_modules or ():
+ if p==package or p.startswith(pfx):
+ return True
+
+ for p in self.ext_modules or ():
+ if p.name==package or p.name.startswith(pfx):
+ return True
+
+
+ def _exclude_misc(self,name,value):
+ """Handle 'exclude()' for list/tuple attrs without a special handler"""
+ if not isinstance(value,sequence):
+ raise DistutilsSetupError(
+ "%s: setting must be a list or tuple (%r)" % (name, value)
+ )
+ try:
+ old = getattr(self,name)
+ except AttributeError:
+ raise DistutilsSetupError(
+ "%s: No such distribution setting" % name
+ )
+ if old is not None and not isinstance(old,sequence):
+ raise DistutilsSetupError(
+ name+": this setting cannot be changed via include/exclude"
+ )
+ elif old:
+ setattr(self,name,[item for item in old if item not in value])
+
+ def _include_misc(self,name,value):
+ """Handle 'include()' for list/tuple attrs without a special handler"""
+
+ if not isinstance(value,sequence):
+ raise DistutilsSetupError(
+ "%s: setting must be a list (%r)" % (name, value)
+ )
+ try:
+ old = getattr(self,name)
+ except AttributeError:
+ raise DistutilsSetupError(
+ "%s: No such distribution setting" % name
+ )
+ if old is None:
+ setattr(self,name,value)
+ elif not isinstance(old,sequence):
+ raise DistutilsSetupError(
+ name+": this setting cannot be changed via include/exclude"
+ )
+ else:
+ setattr(self,name,old+[item for item in value if item not in old])
+
+ def exclude(self,**attrs):
+ """Remove items from distribution that are named in keyword arguments
+
+ For example, 'dist.exclude(py_modules=["x"])' would remove 'x' from
+ the distribution's 'py_modules' attribute. Excluding packages uses
+ the 'exclude_package()' method, so all of the package's contained
+ packages, modules, and extensions are also excluded.
+
+ Currently, this method only supports exclusion from attributes that are
+ lists or tuples. If you need to add support for excluding from other
+ attributes in this or a subclass, you can add an '_exclude_X' method,
+ where 'X' is the name of the attribute. The method will be called with
+ the value passed to 'exclude()'. So, 'dist.exclude(foo={"bar":"baz"})'
+ will try to call 'dist._exclude_foo({"bar":"baz"})', which can then
+ handle whatever special exclusion logic is needed.
+ """
+ for k,v in attrs.items():
+ exclude = getattr(self, '_exclude_'+k, None)
+ if exclude:
+ exclude(v)
+ else:
+ self._exclude_misc(k,v)
+
+
+ def _exclude_packages(self,packages):
+ if not isinstance(packages,sequence):
+ raise DistutilsSetupError(
+ "packages: setting must be a list or tuple (%r)" % (packages,)
+ )
+ map(self.exclude_package, packages)
+
+
+
+
+
+
+
+
+
+
+
+class Feature:
+
+ """A subset of the distribution that can be excluded if unneeded/wanted
+
+ Features are created using these keyword arguments:
+
+ 'description' -- a short, human readable description of the feature, to
+ be used in error messages, and option help messages.
+
+ 'standard' -- if true, the feature is included by default if it is
+ available on the current system. Otherwise, the feature is only
+ included if requested via a command line '--with-X' option, or if
+ another included feature requires it. The default setting is 'False'.
+
+ 'available' -- if true, the feature is available for installation on the
+ current system. The default setting is 'True'.
+
+ 'optional' -- if true, the feature's inclusion can be controlled from the
+ command line, using the '--with-X' or '--without-X' options. If
+ false, the feature's inclusion status is determined automatically,
+ based on 'availabile', 'standard', and whether any other feature
+ requires it. The default setting is 'True'.
+
+ 'requires' -- a string or sequence of strings naming features that should
+ also be included if this feature is included. Defaults to empty list.
+
+ 'remove' -- a string or list of strings naming packages to be removed
+ from the distribution if this feature is *not* included. If the
+ feature *is* included, this argument is ignored. This argument exists
+ to support removing features that "crosscut" a distribution, such as
+ defining a 'tests' feature that removes all the 'tests' subpackages
+ provided by other features. The default for this argument is an empty
+ list. (Note: the named package(s) or modules must exist in the base
+ distribution when the 'setup()' function is initially called.)
+
+ other keywords -- any other keyword arguments are saved, and passed to
+ the distribution's 'include()' and 'exclude()' methods when the
+ feature is included or excluded, respectively. So, for example, you
+ could pass 'packages=["a","b"]' to cause packages 'a' and 'b' to be
+ added or removed from the distribution as appropriate.
+
+ A feature must include at least one 'requires', 'remove', or other
+ keyword argument. Otherwise, it can't affect the distribution in any way.
+ Note also that you can subclass 'Feature' to create your own specialized
+ feature types that modify the distribution in other ways when included or
+ excluded. See the docstrings for the various methods here for more detail.
+ Aside from the methods, the only feature attributes that distributions look
+ at are 'description' and 'optional'.
+ """
+
+ def __init__(self, description, standard=False, available=True,
+ optional=True, requires=(), remove=(), **extras
+ ):
+
+ self.description = description
+ self.standard = standard
+ self.available = available
+ self.optional = optional
+
+ if isinstance(requires,str):
+ requires = requires,
+
+ self.requires = requires
+
+ if isinstance(remove,str):
+ remove = remove,
+
+ self.remove = remove
+ self.extras = extras
+
+ if not remove and not requires and not extras:
+ raise DistutilsSetupError(
+ "Feature %s: must define 'requires', 'remove', or at least one"
+ " of 'packages', 'py_modules', etc."
+ )
+
+
+ def include_by_default(self):
+ """Should this feature be included by default?"""
+ return self.available and self.standard
+
+
+ def include_in(self,dist):
+
+ """Ensure feature and its requirements are included in distribution
+
+ You may override this in a subclass to perform additional operations on
+ the distribution. Note that this method may be called more than once
+ per feature, and so should be idempotent.
+
+ """
+
+ if not self.available:
+ raise DistutilsPlatformError(
+ self.description+" is required,"
+ "but is not available on this platform"
+ )
+
+ dist.include(**self.extras)
+
+ for f in self.requires:
+ dist.include_feature(f)
+
+
+
+ def exclude_from(self,dist):
+
+ """Ensure feature is excluded from distribution
+
+ You may override this in a subclass to perform additional operations on
+ the distribution. This method will be called at most once per
+ feature, and only after all included features have been asked to
+ include themselves.
+ """
+
+ dist.exclude(**self.extras)
+
+ if self.remove:
+ for item in self.remove:
+ dist.exclude_package(item)
+
+
+
+ def validate(self,dist):
+
+ """Verify that feature makes sense in context of distribution
+
+ This method is called by the distribution just before it parses its
+ command line. It checks to ensure that the 'remove' attribute, if any,
+ contains only valid package/module names that are present in the base
+ distribution when 'setup()' is called. You may override it in a
+ subclass to perform any other required validation of the feature
+ against a target distribution.
+ """
+
+ for item in self.remove:
+ if not dist.has_contents_for(item):
+ raise DistutilsSetupError(
+ "%s wants to be able to remove %s, but the distribution"
+ " doesn't contain any packages or modules under %s"
+ % (self.description, item, item)
+ )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 40c5b18..7a5534f 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -1,7 +1,13 @@
+"""Tests for the 'setuptools' package"""
+
from unittest import TestSuite, TestCase, makeSuite
import distutils.core, distutils.cmd
-from distutils.errors import DistutilsOptionError
+from distutils.errors import DistutilsOptionError, DistutilsPlatformError
+from distutils.errors import DistutilsSetupError
import setuptools, setuptools.dist
+from setuptools import Feature
+from distutils.core import Extension
+
def makeSetup(**args):
"""Return distribution from 'setup(**args)', without executing commands"""
@@ -12,17 +18,61 @@ def makeSetup(**args):
distutils.core_setup_stop_after = None
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
class DistroTests(TestCase):
- def testDistro(self):
- self.failUnless(isinstance(makeSetup(),setuptools.dist.Distribution))
+ def setUp(self):
+ self.e1 = Extension('bar.ext',['bar.c'])
+ self.e2 = Extension('c.y', ['y.c'])
+
+ self.dist = makeSetup(
+ packages=['a', 'a.b', 'a.b.c', 'b', 'c'],
+ py_modules=['b.d','x'],
+ ext_modules = (self.e1, self.e2),
+ package_dir = {},
+ )
+ def testDistroType(self):
+ self.failUnless(isinstance(self.dist,setuptools.dist.Distribution))
+ def testExcludePackage(self):
+ self.dist.exclude_package('a')
+ self.assertEqual(self.dist.packages, ['b','c'])
+ self.dist.exclude_package('b')
+ self.assertEqual(self.dist.packages, ['c'])
+ self.assertEqual(self.dist.py_modules, ['x'])
+ self.assertEqual(self.dist.ext_modules, [self.e1, self.e2])
+ self.dist.exclude_package('c')
+ self.assertEqual(self.dist.packages, [])
+ self.assertEqual(self.dist.py_modules, ['x'])
+ self.assertEqual(self.dist.ext_modules, [self.e1])
+ # test removals from unspecified options
+ makeSetup().exclude_package('x')
@@ -30,15 +80,170 @@ class DistroTests(TestCase):
+ def testIncludeExclude(self):
+ # remove an extension
+ self.dist.exclude(ext_modules=[self.e1])
+ self.assertEqual(self.dist.ext_modules, [self.e2])
+ # add it back in
+ self.dist.include(ext_modules=[self.e1])
+ self.assertEqual(self.dist.ext_modules, [self.e2, self.e1])
+ # should not add duplicate
+ self.dist.include(ext_modules=[self.e1])
+ self.assertEqual(self.dist.ext_modules, [self.e2, self.e1])
+ def testExcludePackages(self):
+ self.dist.exclude(packages=['c','b','a'])
+ self.assertEqual(self.dist.packages, [])
+ self.assertEqual(self.dist.py_modules, ['x'])
+ self.assertEqual(self.dist.ext_modules, [self.e1])
+ def testEmpty(self):
+ dist = makeSetup()
+ dist.include(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
+ dist = makeSetup()
+ dist.exclude(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
+ def testContents(self):
+ self.failUnless(self.dist.has_contents_for('a'))
+ self.dist.exclude_package('a')
+ self.failIf(self.dist.has_contents_for('a'))
+ self.failUnless(self.dist.has_contents_for('b'))
+ self.dist.exclude_package('b')
+ self.failIf(self.dist.has_contents_for('b'))
+ self.failUnless(self.dist.has_contents_for('c'))
+ self.dist.exclude_package('c')
+ self.failIf(self.dist.has_contents_for('c'))
+
+
+ def testInvalidIncludeExclude(self):
+ self.assertRaises(DistutilsSetupError,
+ self.dist.include, nonexistent_option='x'
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.exclude, nonexistent_option='x'
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.include, packages={'x':'y'}
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.exclude, packages={'x':'y'}
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.include, ext_modules={'x':'y'}
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.exclude, ext_modules={'x':'y'}
+ )
+
+ self.assertRaises(DistutilsSetupError,
+ self.dist.include, package_dir=['q']
+ )
+ self.assertRaises(DistutilsSetupError,
+ self.dist.exclude, package_dir=['q']
+ )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class FeatureTests(TestCase):
+
+ def setUp(self):
+ self.dist = makeSetup(
+ features={
+ 'foo': Feature("foo",standard=True,requires='baz'),
+ 'bar': Feature("bar", standard=True, packages=['pkg.bar'],
+ py_modules=['bar_et'], remove=['bar.ext'],
+ ),
+ 'baz': Feature(
+ "baz", optional=False, packages=['pkg.baz'],
+ scripts = ['scripts/baz_it'],
+ libraries=[('libfoo','foo/foofoo.c')]
+ ),
+ 'dwim': Feature("DWIM", available=False, remove='bazish'),
+ },
+ script_args=['--without-bar', 'install'],
+ packages = ['pkg.bar', 'pkg.foo'],
+ py_modules = ['bar_et', 'bazish'],
+ ext_modules = [Extension('bar.ext',['bar.c'])]
+ )
+
+ def testDefaults(self):
+ self.failIf(
+ Feature(
+ "test",standard=True,remove='x',available=False
+ ).include_by_default()
+ )
+ self.failUnless(
+ Feature("test",standard=True,remove='x').include_by_default()
+ )
+ # Feature must have either kwargs, removes, or requires
+ self.assertRaises(DistutilsSetupError, Feature, "test")
+
+ def testAvailability(self):
+ self.assertRaises(
+ DistutilsPlatformError,
+ self.dist.features['dwim'].include_in, self.dist
+ )
+
+
+ def testFeatureOptions(self):
+ dist = self.dist
+ self.failUnless(
+ ('with-dwim',None,'include DWIM') in dist.global_options
+ )
+ self.failUnless(
+ ('without-dwim',None,'exclude DWIM (default)') in dist.global_options
+ )
+ self.failUnless(
+ ('with-bar',None,'include bar (default)') in dist.global_options
+ )
+ self.failUnless(
+ ('without-bar',None,'exclude bar') in dist.global_options
+ )
+ self.assertEqual(dist.negative_opt['without-foo'],'with-foo')
+ self.assertEqual(dist.negative_opt['without-bar'],'with-bar')
+ self.assertEqual(dist.negative_opt['without-dwim'],'with-dwim')
+ self.failIf('without-baz' in dist.negative_opt)
+
+ def testUseFeatures(self):
+ dist = self.dist
+ self.assertEqual(dist.with_foo,1)
+ self.assertEqual(dist.with_bar,0)
+ self.assertEqual(dist.with_baz,1)
+
+ self.failIf('bar_et' in dist.py_modules)
+ self.failIf('pkg.bar' in dist.packages)
+ self.failUnless('pkg.baz' in dist.packages)
+ self.failUnless('scripts/baz_it' in dist.scripts)
+ self.failUnless(('libfoo','foo/foofoo.c') in dist.libraries)
+ self.assertEqual(dist.ext_modules,[])
+
+ # If we ask for bar, it should fail because we explicitly disabled
+ # it on the command line
+ self.assertRaises(DistutilsOptionError, dist.include_feature, 'bar')
+
+ def testFeatureWithInvalidRemove(self):
+ self.assertRaises(
+ SystemExit, makeSetup, features = {'x':Feature('x', remove='y')}
+ )
+
class TestCommandTests(TestCase):
def testTestIsCommand(self):
@@ -75,16 +280,16 @@ class TestCommandTests(TestCase):
ts5 = makeSetup().get_command_obj('test')
ts5.ensure_finalized()
self.assertEqual(ts5.test_suite, None)
-
-testClasses = (DistroTests, TestCommandTests)
+
+testClasses = (DistroTests, FeatureTests, TestCommandTests)
def test_suite():
return TestSuite([makeSuite(t,'test') for t in testClasses])
-
+