Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] No way to specify tool.setuptools.packages.find in a non-fragile way for flat layouts #4739

Open
vanschelven opened this issue Nov 8, 2024 · 1 comment
Labels
Needs Repro Issues that need a reproducible example. Waiting User Feedback

Comments

@vanschelven
Copy link

setuptools version

setuptools==75.3.0

Python version

Python 3.11

OS

Ubuntu

Additional environment information

No response

Description

When using a flat (non-src-based) layout, it is not possible to configure using pyproject.toml in a way that doesn't immediately break when a new package is added to the project layout.

i.e. I configure using

[tool.setuptools.packages.find]
where = ["."]
include = [
    # ... long, and fragile, list
]

exclude = [
    # This, or similar syntaxes, don't seem to actually work.
    # https://stackoverflow.com/q/75091671/339144
]  # exclude packages matching these glob patterns (empty by default)

but if I add a new directory to my project, I must remember to add it to pyproject.toml.

As here: https://stackoverflow.com/questions/79169280/pyproject-toml-config-using-setuptools-with-correct-packages-automatically

Expected behavior

I expect to have a way that will "just work forever".

How to Reproduce

.

Output

.

@vanschelven vanschelven added bug Needs Triage Issues that need to be evaluated for severity and status. labels Nov 8, 2024
@abravalheri
Copy link
Contributor

abravalheri commented Nov 8, 2024

Hi @vanschelven please provide a minimal and complete reproducer regarding the BUG you want to report, otherwise we will not be able to consider this issue.

Regarding the given example, please note that values for the patterns used in https://stackoverflow.com/questions/75091671/pyproject-toml-exclude-some-python-sources-py-from-data-directory are conceptually wrong, for the reason that setuptools.packages deals with Python package names (i.e. "dotted" strings) not file paths, so that is the reason why your expression does not match. See details in https://setuptools.pypa.io/en/latest/userguide/package_discovery.html.

If you want to exclude the mypackage/data folder and anything under it, you should provide the following exclude pattern exclude = ["mypackage.data", "mypackage.data.*"]1.

The pattern mypackage*data*py is implying that you have py as part of the package name, which does not seem to be the case. Also note that packages in Python are collections of modules (i.e. they map into directories, while modules map into files), so you cannot use exclude for files specifically... The original pattern would match something like mypackage/data/py/file.py.


Now regarding the criticism about the methodology not being convenient for your use case, that is a fair comment. But setuptools understands that it is simply impossible to foresee and accommodate ALL the possible scenarios. Instead it offers the ultimate flexibility for all users that have a particular scenario in mind: you can implement your own discovery algorithm by using setup.py (note that you can keep most of your configuration in pyproject.toml and only define setup(packages=[...]) in setup.py.

So, ultimately, you have tree choices

  • You can choose convention over configuration and adequate your source layout to work with setuptools built-in automatic discovery.
  • You can use some lightweight configuration in pyproject.toml using include/exclude.
  • If that still don't work for you then, you can implement your own algorithm in setup.py.

Footnotes

  1. Please also set include-package-data = false for now to avoid problems (see https://github.com/pypa/setuptools/issues/3260).

@abravalheri abravalheri added Needs Repro Issues that need a reproducible example. Waiting User Feedback and removed bug Needs Triage Issues that need to be evaluated for severity and status. labels Nov 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Needs Repro Issues that need a reproducible example. Waiting User Feedback
Projects
None yet
Development

No branches or pull requests

2 participants