setuptools: [BUG]

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 https://github.com/nucleic/kiwi/issues/130 with the kiwisolver developers, but it appears that setuptools 60.10.0 does work. Based on looking at https://github.com/pypa/setuptools/compare/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.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 42 (18 by maintainers)

Commits related to this issue

Most upvoted comments

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

As a quick fix, in setup.py

setuptools.setup(..,packages=[],..)

or

setuptools.setup(..,py_modules=[],..)

@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.

Question: since you have an undertime.py wouldn’t it be the case that instead of packages = # nothing you want to use py_modules = undertime?

because i want to keep things simple and not use an entry_point because those are traditionally slow.

it’s just one script darn it! 😃

so i ship it with scripts =

i have had the same problem in undertime. suddenly, setuptools starting failing my CI while everything worked fine literally an hour earlier. this is quite strange because the dependency list didn’t change, the container image didn’t change, and the commit (on my side) which introduced the problem (according to git bisect) happened months ago.

so i don’t understand why this started failing all of sudden.

i also don’t understand the fix: #3211 mentions the configuration option, but I can’t find documentation on that setting anywhere (and it’s kind of hard to search for configuration in the documentation, because there’s a lot of false positives). it’s not documented here or here or here.

in the end, I had to add this line to my setup.cfg:

[option]
packages =

… to, basically, disable autodiscovery. and yes, i have a weird-ish package (it only ships scripts) but I don’t think it’s a particularly strange one.

a little care about backwards compatibility would have been appreciated here. 😉

i hope this hack will be useful for others!

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

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 ?