Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] #3197

Closed
aragilar opened this issue Mar 25, 2022 · 42 comments · Fixed by #3211
Closed

[BUG] #3197

aragilar opened this issue Mar 25, 2022 · 42 comments · Fixed by #3211
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@aragilar
Copy link

setuptools version

61.0.0

Python version

3.9

OS

Debian Unstable

Additional environment information

No response

Description

kiwisolver 1.4.0 (I haven't checked earlier versions, but kiwisolver 1.4.0 did modernise their build, so issues with earlier versions will likely be to different code) can no build from source. I filed nucleic/kiwi#130 with the kiwisolver developers, but it appears that setuptools 60.10.0 does work. Based on looking at v60.10.0...v61.0.0 and the error message that appears (see output), I think this is related to the new(?) package discovery mechanism. I'm not a kiwisolver developer, so I can't answer questions about their build system (other than link you to the repository), but I'm filing this as it appears to be a regression (give setuptools 61 came out 10 hours ago when I wrote this).

Expected behavior

I expect pip install kiwisolver would build a wheel and install it.

How to Reproduce

  1. Run pip install kiwisolver (given kiwisolver has wheels, you may need to disable using wheels to not download a pre-built wheel).

Output

      /tmp/pip-build-env-nwrt4o9m/overlay/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py:100: _ExperimentalProjectMetadata: Support for project metadata in `pyproject.toml` is still experimental and may be removed (or change) in future releases.
        warnings.warn(msg, _ExperimentalProjectMetadata)
      Install ``trove-classifiers`` to ensure proper validation. Meanwhile a list of classifiers will be downloaded from PyPI.
      error: Multiple top-level packages discovered in a flat-layout: ['py', 'kiwi'].
      
      To avoid accidental inclusion of unwanted files or directories,
      setuptools will not proceed with this build.
      
      If you are trying to create a single distribution with multiple packages
      on purpose, you should not rely on automatic discovery.
      Instead, consider the following options:
      
      1. set up custom discovery (`find` directive with `include` or `exclude`)
      2. use a `src-layout`
      3. explicitly set `py_modules` or `packages` with a list of names
      
      To find more information, look for "package discovery" on setuptools docs.
@aragilar aragilar added bug Needs Triage Issues that need to be evaluated for severity and status. labels Mar 25, 2022
@MatthieuDartiailh
Copy link

I am a maintainer of kiwisolver. I guess that setuptools is confused because kiwisolver is a pure C extensions without any python source. Currently it does not specify a value for py_modules nor for packages. I would appreciate any advice on how to keep things working with the latest setuptools.

@abravalheri
Copy link
Contributor

Thank you very much for reporting this.

My understanding is that unfortunately there is a clash of 2 behaviours:

To make these changes as backwards compatible as possible, I added a condition that only works for packages not using pyproject.toml that will check if ext_modules is given and then skip auto-discovery.

But, going forward my assumption was that it is very common for packages to mix both regular Python code with extensions. So if a project is using pyproject.toml for metadata, auto-discovery is always on.

I did not foresee that kiwisolver was providing metadata in both pyproject.toml and setup.py already before the latest change. Sorry for that.

@MatthieuDartiailh, one way to disable auto discovery is to explicitly set py_modules=[] in setup.py or py-modules = [] in pyproject.toml [tool.setuptools]. Would that work for you?

If that is a viable alternative, it would help a lot! I was hopping to keep the auto-discovery always on for packages using pyproject.toml...

@MatthieuDartiailh
Copy link

MatthieuDartiailh commented Mar 25, 2022

It would work, but actually my setup is broken since in its current state it does not distribute type annotations which I recently added. So I will need to rework the overall structure.

I had hoped to get rid of everything but the C extension building in setup.py however this _ExperimentalProjectMetadata warning is a bit frightening. Do you really think you may roll back support for PEP 621 ?

@abravalheri
Copy link
Contributor

abravalheri commented Mar 25, 2022

Do you really think you may roll back support for PEP 621?

I hope not, but it is very early to say. It was just released yesterday, and if it break too many projects I might have to roll back before re-working on it again.

Given that we are not forced to roll back, usage the [project] table should not change, after all it is defined in a PEP, but the shape of [tool.setuptools] might differ a bit in the future...


my setup is broken since in its current state it does not distribute type annotations which I recently added.

Is this also caused by the latest release?

@MatthieuDartiailh
Copy link

No I added those in the last release and apparently I did not properly test apparently.

@MatthieuDartiailh
Copy link

Do you really think you may roll back support for PEP 621?

I hope not, but it is very early to say. It was just released yesterday, and if it break too many projects I might have to roll back before re-working on it again.

Given that we are not forced to roll back, usage the [project] table should change, after all it is defined in a PEP, but the shape of [tool.setuptools] might differ a bit in the future...

Here you mean "[project] table should not change", right ?

my setup is broken since in its current state it does not distribute type annotations which I recently added.

Is this also caused by the latest release?

@tobni
Copy link

tobni commented Mar 25, 2022

We observe a similar error (but with different warnings) with scikit-fmm==2022.02.02 on python 3.10.2:

Collecting scikit-fmm==2022.02.02
  Downloading scikit-fmm-2022.2.2.tar.gz (434 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 434.5/434.5 KB 87.6 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [18 lines of output]
      /tmp/pip-build-env-qhobckeh/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py:275: UserWarning: Unknown distribution option: 'configuration'
        warnings.warn(msg)
      /tmp/pip-build-env-qhobckeh/overlay/lib/python3.10/site-packages/setuptools/dist.py:511: UserWarning: Normalizing '2022.02.02' to '2022.2.2'
        warnings.warn(tmpl.format(**locals()))
      error: Multiple top-level packages discovered in a flat-layout: ['skfmm', 'profile'].
      
      To avoid accidental inclusion of unwanted files or directories,
      setuptools will not proceed with this build.
      
      If you are trying to create a single distribution with multiple packages
      on purpose, you should not rely on automatic discovery.
      Instead, consider the following options:
      
      1. set up custom discovery (`find` directive with `include` or `exclude`)
      2. use a `src-layout`
      3. explicitly set `py_modules` or `packages` with a list of names
      
      To find more information, look for "package discovery" on setuptools docs.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

@abravalheri
Copy link
Contributor

Hi @tobni, thank you very much for reporting this.
Am I correct in assume that scikit-fmm does not specify any of py_modules, packages or ext_modules keywords?

@abravalheri
Copy link
Contributor

Here you mean "[project] table should not change", right ?

Yes sorry @MatthieuDartiailh, I typed that too fast without checking 😅

@tobni
Copy link

tobni commented Mar 25, 2022

@abravalheri Not in the pyproject.toml, no. I don't know exactly where to look in the setup.py file, the scikit-fmm package uses numpy.distutils.misc_util.Configuration which is hard to grok.

@abravalheri
Copy link
Contributor

My question was more in the direction of setup.py. I will have a look on the numpy.distutils.misc_util.Configuration. Thank you very much @tobni.

@MatthieuDartiailh
Copy link

Experiment a bit I found another undesirable behavior.

Kiwisolver uses setuptools-scm and after modifying the setup.py to include the following directives (which silences the previously reported error for setuptools 61) the installed package in site-packages includes all the C source files and the tests even though they are not requested. With Setuptools <= 60, the install contains just an __init__.py (added to allow accessing the C extension content), a .pyi file, py.typed and the built extension package.

    package_dir={"kiwisolver": "py"},
    packages=["kiwisolver"],
    install_requires=["typing_extensions;python_version<'3.8'"],
    ext_modules=ext_modules,
    cmdclass={"build_ext": CppyBuildExt},
    package_data={"kiwisolver": ["py.typed", "*.pyi"]},

@abravalheri
Copy link
Contributor

Thanks @MatthieuDartiailh, I will have a look on that too.

This is likely related to the fact that the presence of [project] in pyproject.toml will automatically flip the default value of include_package_data (in setup.cfg/setup.py-only projects it defaults to False, while with pyproject.toml [project] it defaults to True.

This should have been added to the CHANGELOG. Sorry I forgot that.

@MatthieuDartiailh
Copy link

I tried setting include_package_data to False but it does not help. The setup I use for testing can be found at nucleic/kiwi#131

@MatthieuDartiailh
Copy link

It appears that through some re-organization of kiwi I managed to circumvent the issue (see the PR). But it may not apply to other packages out there.

@TimoRoth
Copy link

Not sure if this is the same issue, but building scipy with --no-build-isolation fails as well since the setuptools 61.0 update.
With build isolation their pin to setuptools<60 in pyproject.toml saves the day.

@MatthieuDartiailh
Copy link

MatthieuDartiailh commented Mar 25, 2022

Note that even though it does not break the build the issue of unwanted files being included can also be seen with https://github.com/nucleic/atom

@abravalheri
Copy link
Contributor

Hi @TimoRoth and @MatthieuDartiailh, thank you for reporting that. I will add those to my list today.

@MatthieuDartiailh, can you give some examples of those unwanted files so I can have a look?

Is this related to the fact that the default value of include_package_data is flipped to True for when pyproject.toml has a [project] table?

@MatthieuDartiailh
Copy link

Basically all C source files found under atom/src end being installed. What I find confusing with the include_package_data explanation is that even if I set it to False manually in setup.py I still see the same weird behavior. Do you expect that ?

@abravalheri
Copy link
Contributor

if I set it to False manually in setup.py I still see the same weird behavior. Do you expect that ?

I will work on that. The current code expects include-package-data to be set to false in pyproject.toml [tool.setuptools], but I completely agree it should work also when it is set in setup.py.

@MatthieuDartiailh
Copy link

I can confirm that settings include-package-data in pyproject.toml does indeed work.

@sanderr
Copy link

sanderr commented Mar 25, 2022

I'm encountering this issue on packages that act solely as a meta package for distributing a collection of related packages via dependencies. The package does not have any source packages or modules. I can confirm that explicitly setting packages=[] resolves the issue.

I do still find it strange that what you call an experimental feature in the docs is enabled by default.

@sanderr
Copy link

sanderr commented Mar 25, 2022

To be fair, I see this behavior is mentioned in your changelog under "breaking changes". That's my bad for not checking there in the first place.

@abravalheri
Copy link
Contributor

Hi @sanderr, I am terribly sorry for the trouble and thank you very much for the understanding.

openstack-mirroring pushed a commit to openstack/tripleo-ci that referenced this issue Mar 25, 2022
https://opendev.org/openstack/tripleo-ci/src/branch/master/zuul.d/base-upstream.yaml#L92
adds  ^setup.*$ under irrelevant-files and content-provider is parent
from tripleo-ci-base-standalone-standard and which parents from
tripleo-ci-base-standard.

Since setup.* files under irrelevant files so content provider will
not run and undercloud, upgrade and standalone job depends on that.

It leads to job freeze issue. Putting setup files under
irrelevant files fixes the issue.

Disable auto discovery as a workaround to fix
setuptools 61.0 issue[1]

[1]. pypa/setuptools#3197
Related-Bug: #1966382


Signed-off-by: Chandan Kumar (raukadah) <[email protected]>
Change-Id: I43b88e356e1f6823f9febe47e9753cf3e5b176c6
openstack-mirroring pushed a commit to openstack/ironic-python-agent that referenced this issue Jan 3, 2023
- Disable auto discovery in setuptools
This is to avoid issues with latest setuptools after version 61.0
For more info see [1]
- add bash script to allowlist in tox.ini
- use default size for vm memory

[1] pypa/setuptools#3197

Change-Id: Iae24917add1aae6b1ed46dba0d2c270b39c5698c
TomWinder added a commit to TomWinder/QuakeMigrate that referenced this issue Mar 2, 2023
Sheeba-Samuel added a commit to fusion-jena/computational-reproducibility-pmc that referenced this issue Apr 28, 2023
Added fix for 'Multiple top-level modules discovered in a flat-layout' error.
Error of Multiple top-level packages occur due to the recent compatibility issue in setuptools.
Detailed bug is reported here: pypa/setuptools#3197
The issue also provides a fix.
Added py_modules=[], to the setup() argument in setup.py file.
letam added a commit to letam/python-django-app-starter that referenced this issue May 12, 2023
- Use pip-tools' pip-compile command via '.venv/bin/pip-compile'
- Note: For pip-compile to work for this project we have to add:
```
[tool.setuptools]
py-modules = []
```
  Details here:
  - jazzband/pip-tools#1711 (comment)
  - pypa/setuptools#3197 (comment)
letam added a commit to letam/python-django-app-starter that referenced this issue May 13, 2023
- Use pip-tools' pip-compile command via '.venv/bin/pip-compile'
- Note: For pip-compile to work for this project we have to add:
```
[tool.setuptools]
py-modules = []
```
  Details here:
  - jazzband/pip-tools#1711 (comment)
  - pypa/setuptools#3197 (comment)
letam added a commit to letam/python-django-app-starter that referenced this issue May 16, 2023
- Use pip-tools' pip-compile command via '.venv/bin/pip-compile'
- Note: For pip-compile to work for this project we have to add:
```
[tool.setuptools]
py-modules = []
```
  Details here:
  - jazzband/pip-tools#1711 (comment)
  - pypa/setuptools#3197 (comment)
sshnaidm added a commit to sshnaidm/ansible-podman-collections that referenced this issue May 30, 2023
pypa/setuptools#3197
latest release of setuptools 61.0 broke pip install
sshnaidm added a commit to sshnaidm/ansible-podman-collections that referenced this issue May 30, 2023
pypa/setuptools#3197
latest release of setuptools 61.0 broke pip install

Signed-off-by: Sagi Shnaidman <[email protected]>
sshnaidm added a commit to containers/ansible-podman-collections that referenced this issue May 30, 2023
pypa/setuptools#3197
latest release of setuptools 61.0 broke pip install

Signed-off-by: Sagi Shnaidman <[email protected]>
openstack-mirroring pushed a commit to openstack/ansible-role-atos-hsm that referenced this issue Sep 25, 2023
With the latest setuptools release (61.0.0) ansible-role-atos-hsm's
package build command (python3 setup.py sdist bdist_wheel) started to
fail:

error: Multiple top-level packages discovered in a flat-layout:
['defaults', 'handlers', 'templates', 'releasenotes'].

This issue is mentioned in setuptools bug 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: I3f827b3ed855ff46292dee7b21b74a622adc472d
(cherry picked from commit f5c86df)
openstack-mirroring pushed a commit to openstack/ansible-role-thales-hsm that referenced this issue Sep 25, 2023
With setuptools release 61.0.0 ansible-role-thales-hsm's package build
command (python3 setup.py sdist bdist_wheel) started to fail:

error: Multiple top-level packages discovered in a flat-layout:
['files', 'defaults', 'handlers', 'templates', 'releasenotes'].

This bug is mentioned in setuptools issue 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: Idb765d09f9498bc13f952c055026e29a46cab8d3
(cherry picked from commit 49970b3)
openstack-mirroring pushed a commit to openstack/ansible-role-atos-hsm that referenced this issue Sep 25, 2023
With the latest setuptools release (61.0.0) ansible-role-atos-hsm's
package build command (python3 setup.py sdist bdist_wheel) started to
fail:

error: Multiple top-level packages discovered in a flat-layout:
['defaults', 'handlers', 'templates', 'releasenotes'].

This issue is mentioned in setuptools bug 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: I3f827b3ed855ff46292dee7b21b74a622adc472d
(cherry picked from commit f5c86df)
(cherry picked from commit 6a02873)
openstack-mirroring pushed a commit to openstack/ansible-role-thales-hsm that referenced this issue Sep 26, 2023
With setuptools release 61.0.0 ansible-role-thales-hsm's package build
command (python3 setup.py sdist bdist_wheel) started to fail:

error: Multiple top-level packages discovered in a flat-layout:
['files', 'defaults', 'handlers', 'templates', 'releasenotes'].

This bug is mentioned in setuptools issue 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: Idb765d09f9498bc13f952c055026e29a46cab8d3
(cherry picked from commit 49970b3)
(cherry picked from commit 3f88a20)
openstack-mirroring pushed a commit to openstack/ansible-role-thales-hsm that referenced this issue Sep 26, 2023
With setuptools release 61.0.0 ansible-role-thales-hsm's package build
command (python3 setup.py sdist bdist_wheel) started to fail:

error: Multiple top-level packages discovered in a flat-layout:
['files', 'defaults', 'handlers', 'templates', 'releasenotes'].

This bug is mentioned in setuptools issue 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: Idb765d09f9498bc13f952c055026e29a46cab8d3
(cherry picked from commit 49970b3)
(cherry picked from commit 3f88a20)
(cherry picked from commit 1a8c645)
openstack-mirroring pushed a commit to openstack/ansible-role-atos-hsm that referenced this issue Sep 26, 2023
With the latest setuptools release (61.0.0) ansible-role-atos-hsm's
package build command (python3 setup.py sdist bdist_wheel) started to
fail:

error: Multiple top-level packages discovered in a flat-layout:
['defaults', 'handlers', 'templates', 'releasenotes'].

This issue is mentioned in setuptools bug 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

ansible-lint also released a new version (6.0.0), which has new rules
that blocks the gate. As a workaround, this patch caps ansible-lint
version <6.0.0 to unblock the gate.

[1] pypa/setuptools#3197

Change-Id: I3f827b3ed855ff46292dee7b21b74a622adc472d
(cherry picked from commit f5c86df)
(cherry picked from commit 6a02873)
(cherry picked from commit ebd5421)
nijel added a commit to WeblateOrg/siphashc that referenced this issue Oct 9, 2023
@bersbersbers
Copy link

one way to disable auto discovery is to explicitly set py_modules=[] in setup.py or py-modules = [] in pyproject.toml [tool.setuptools].

I may have misunderstood that workaround - @abravalheri, do you mean to literally write an empty list for py-modules? I tried it out, and while packages using that workaround are successfully installed, I cannot seem to import their modules (unless my working directory is the project directory, in which case installation is not required anyway).

Or was your recommended workaround to populate py-modules with the actual list of module names?

@abravalheri
Copy link
Contributor

abravalheri commented Dec 6, 2023

@bersbersbers the context for that is a distribution that does not contain any Python packages or modules (so there is nothing really to be imported).

If your project contains those, probably the best advice is to follow one of the suggestions in the error message.

openstack-mirroring pushed a commit to openstack/ansible-collections-openstack that referenced this issue Mar 20, 2024
Since setuptools release (61.0.0) ansible-collection-openstack's
package build command (python3 setup.py sdist bdist_wheel) is
finding multiple top-level packages in a flat-layout automatically.

This issue is mentioned in setuptools bug 3197 [1], and the suggested
workaround is to disable auto-discovery by adding 'py_modules=[]' in
setup.py.

[1] pypa/setuptools#3197

Change-Id: I4aef1fd59375c4a3bc9e362e7949fa153e4cbcb0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.