diff options
author | idle sign <idlesign@yandex.ru> | 2016-12-10 13:33:57 +0700 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-12-10 11:23:00 -0500 |
commit | a262947e39e6125ee15d3752a2124acf0c62bda6 (patch) | |
tree | dcd271dbd114a22e19dac3f18b2f3fccb1740bb7 | |
parent | b73891f82d5f1a353a2ad0090b1f5edece921508 (diff) | |
download | external_python_setuptools-a262947e39e6125ee15d3752a2124acf0c62bda6.tar.gz external_python_setuptools-a262947e39e6125ee15d3752a2124acf0c62bda6.tar.bz2 external_python_setuptools-a262947e39e6125ee15d3752a2124acf0c62bda6.zip |
Implemented find() configuration support for `packages`.
-rw-r--r-- | docs/setuptools.txt | 20 | ||||
-rw-r--r-- | setuptools/config.py | 33 | ||||
-rw-r--r-- | setuptools/tests/test_config.py | 38 |
3 files changed, 86 insertions, 5 deletions
diff --git a/docs/setuptools.txt b/docs/setuptools.txt index 1721edaf..2f78b133 100644 --- a/docs/setuptools.txt +++ b/docs/setuptools.txt @@ -2448,6 +2448,11 @@ boilerplate code in some cases. pdf = ReportLab>=1.2; RXP rest = docutils>=0.3; pack ==1.1, ==1.3 + [options.packages.find] + exclude = + src.subpackage1 + src.subpackage2 + Metadata and options could be set in sections with the same names. @@ -2486,13 +2491,13 @@ Type names used below: * ``list-semi`` - dangling list or semicolon-separated values string * ``bool`` - ``True`` is 1, yes, true * ``dict`` - list-comma where keys from values are separated by = +* ``section`` - values could be read from a dedicated (sub)section Special directives: * ``attr:`` - value could be read from module attribute * ``file:`` - value could be read from a file -* ``section:`` - values could be read from a dedicated (sub)section .. note:: @@ -2529,8 +2534,10 @@ requires list-comma obsoletes list-comma ================= ================= ===== -**version** - ``attr:`` supports callables; supports iterables; -unsupported types are casted using ``str()``. +.. note:: + + **version** - ``attr:`` supports callables; supports iterables; + unsupported types are casted using ``str()``. Options @@ -2560,6 +2567,13 @@ exclude_package_data section namespace_packages list-comma ======================= ===== +.. note:: + + **packages** - ``find:`` directive can be further configured + in a dedicated subsection `options.packages.find`. This subsection + accepts the same keys as `setuptools.find` function: + `where`, `include`, `exclude`. + Configuration API ================= diff --git a/setuptools/config.py b/setuptools/config.py index 007d24e2..743575f0 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -361,7 +361,10 @@ class ConfigHandler(object): method_postfix = '_%s' % section_name section_parser_method = getattr( - self, 'parse_section%s' % method_postfix, None) + self, + # Dots in section names are tranlsated into dunderscores. + ('parse_section%s' % method_postfix).replace('.', '__'), + None) if section_parser_method is None: raise DistutilsOptionError( @@ -481,8 +484,34 @@ class ConfigOptionsHandler(ConfigHandler): if not value.startswith(find_directive): return self._parse_list(value) + # Read function arguments from a dedicated section. + find_kwargs = self.parse_section_packages__find( + self.sections.get('packages.find', {})) + from setuptools import find_packages - return find_packages() + + return find_packages(**find_kwargs) + + def parse_section_packages__find(self, section_options): + """Parses `packages.find` configuration file section. + + To be used in conjunction with _parse_packages(). + + :param dict section_options: + """ + section_data = self._parse_section_to_dict( + section_options, self._parse_list) + + valid_keys = ['where', 'include', 'exclude'] + + find_kwargs = dict( + [(k, v) for k, v in section_data.items() if k in valid_keys and v]) + + where = find_kwargs.get('where') + if where is not None: + find_kwargs['where'] = where[0] # cast list to single val + + return find_kwargs def parse_section_entry_points(self, section_options): """Parses `entry_points` configuration file section. diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index 35bdbad1..08e398b3 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -446,6 +446,44 @@ class TestOptions: with get_dist(tmpdir) as dist: assert dist.packages == ['fake_package'] + def test_find_directive(self, tmpdir): + dir_package, config = fake_env( + tmpdir, + '[options]\n' + 'packages = find:\n' + ) + + dir_sub_one, _ = make_package_dir('sub_one', dir_package) + dir_sub_two, _ = make_package_dir('sub_two', dir_package) + + with get_dist(tmpdir) as dist: + assert dist.packages == [ + 'fake_package', 'fake_package.sub_two', 'fake_package.sub_one'] + + config.write( + '[options]\n' + 'packages = find:\n' + '\n' + '[options.packages.find]\n' + 'where = .\n' + 'include =\n' + ' fake_package.sub_one\n' + ' two\n' + ) + with get_dist(tmpdir) as dist: + assert dist.packages == ['fake_package.sub_one'] + + config.write( + '[options]\n' + 'packages = find:\n' + '\n' + '[options.packages.find]\n' + 'exclude =\n' + ' fake_package.sub_one\n' + ) + with get_dist(tmpdir) as dist: + assert dist.packages == ['fake_package', 'fake_package.sub_two'] + def test_extras_require(self, tmpdir): fake_env( tmpdir, |