question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[options.packages.find_namespace] should be [options.packages.find] in package discovery guide

See original GitHub issue

In https://setuptools.readthedocs.io/en/latest/userguide/package_discovery.html#using-find-namespace-or-find-namespace-packages, the docs say

[options.packages.find_namespace]
where = src

That fails with

distutils.errors.DistutilsOptionError: Unsupported distribution option section: [options.packages.find_namespace]
[options.packages.find]
where = src

actually works.

Filing this as a doc issue, but maybe that option should work the way it’s documented?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jaracocommented, Mar 31, 2021

I’m now using find_namespace in most of my packages (those not supporting Python 2) based on jaraco/skeleton.

1reaction
trharoldsencommented, Oct 28, 2020

The description of options.packages.find_namespace is also found in https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html so at least two locations in documentation are expecting it to work.

Note packages - The find: and find_namespace: directive can be further configured in a dedicated subsection
options.packages.find. This subsection accepts the same keys as the setuptools.find_packages and the
setuptools.find_namespace_packages function: where, include, and exclude.

I did a little searching of the code and found a few things. options.packages.find will work correctly according the the code. Both options.packages.find and options.packages.find_namespace sections are parsed in ConfigOptionsHandler._parse_packages in config.py when the corresponding package value (package = 'find[_namespace]') is parsed.

find_directives = ['find:', 'find_namespace:']
trimmed_value = value.strip()

if trimmed_value not in find_directives:
    return self._parse_list(value)

findns = trimmed_value == find_directives[1]

# Read function arguments from a dedicated section.
find_kwargs = self.parse_section_packages__find(
    self.sections.get('packages.find', {}))

if findns:
    from setuptools import find_namespace_packages as find_packages
else:
    from setuptools import find_packages

return find_packages(**find_kwargs)

So it’s actually expected that the [options.packages.find] form will be used.

The actual error occurs because the options.packages sections are parsed twice; once in the previously mentioned area and again when the the parser reaches the section. At this point the parser does a lookup of the method based on the option name. It finds the corresponding options.packages.find method, _parse_section_find, ignoring the result. However, there is no corresponding _parse_section_find_namespace method for the options.packages.find_namespace section which leads to the error.

I suppose the real question at this time is cosmetic. Should the code be updated to match the documentation or the other way around?

– Update – Updating to use options.packages.find_namespace could lead to a breaking change depending on how it’s implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Package Discovery and Namespace Packages - Setuptools
Setuptools provides powerful tools to handle package discovery, including support for namespace packages. Normally, you would specify the packages to be ...
Read more >
Package Discovery and Namespace Package
Setuptools provide powerful tools to handle package discovery, including support for namespace ... [options] packages = find: #or packages = find_namespace:.
Read more >
python setuptools setup.cfg: Including main- and subpackages ...
Both of these allowed me to import all modules from the src package and src.subpkg . [options] packages=find: and the other doesn't use...
Read more >
Packaging namespace packages
This is recommended for new packages that need to support Python 2 and 3 and installation via both pip and python setup.py install...
Read more >
Frequently Asked Questions - PyScaffold
Can I use PyScaffold ≥ 3 to develop a Python package that is Python 2 & 3 ... PyScaffold strongly recommends all packages...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found