I’m trying to make a working pure-pyproject.toml file for my modules. I’ve run out of ideas and lost patience with the setuptools documentation.
Background: I’ve been publishing some modules to PyPI for years. A few years back I upgraded my ancient setup.py based setuptools stuff to use pyproject.toml, with an adjacent setup.cfg file. Now I’m using only the pyproject.toml file and getting broken wheel builds. I haven’t been able to see the configuration error.
As my working example, my cs.gimmicks module. Here’s the contents of an older correct wheel file:
% unzip -l cs.gimmicks-20230212-py3-none-any.whl
Archive: cs.gimmicks-20230212-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
3916 02-12-2023 00:37 cs/gimmicks.py
2190 02-12-2023 00:37 cs.gimmicks-20230212.dist-info/METADATA
92 02-12-2023 00:37 cs.gimmicks-20230212.dist-info/WHEEL
3 02-12-2023 00:37 cs.gimmicks-20230212.dist-info/top_level.txt
396 02-12-2023 00:37 cs.gimmicks-20230212.dist-info/RECORD
--------- -------
6597 5 files
This unpacks directly into site-packages making a cs/gimmicks.py file. That’s what should happen.
With my newer builds the wheel files look like this:
% unzip -l dist/cs.gimmicks-20230331-py3-none-any.whl
Archive: dist/cs.gimmicks-20230331-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
4840 03-31-2023 10:02 lib/python/cs/gimmicks.py
2529 03-15-2024 22:54 cs.gimmicks-20230331.dist-info/METADATA
92 03-15-2024 22:54 cs.gimmicks-20230331.dist-info/WHEEL
4 03-15-2024 22:54 cs.gimmicks-20230331.dist-info/top_level.txt
407 03-15-2024 22:54 cs.gimmicks-20230331.dist-info/RECORD
--------- -------
7872 5 files
which unpacks a lib/python/cs/gimmicks.py file. That reflects my source tree, where my Python stuff is all in a lib/python subdirectory - effectively this is the “src layout” approach, but with a different subdirectory. This is supposed to be happily supported by setuptools.
My release process generates a pyproject.toml with this content (minus the inline [project.readme] table):
[project]
name = "cs.gimmicks"
description = "Gimmicks and hacks to make some of my other modules more robust and less demanding of others."
authors = [
{ name = "Cameron Simpson", email = "cs@cskk.id.au" },
]
keywords = [
"python2",
"python3",
]
dependencies = []
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
]
version = "20230331"
[project.license]
text = "GNU General Public License v3 or later (GPLv3+)"
[project.urls]
URL = "https://bitbucket.org/cameron_simpson/css/commits/all"
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools == 61.2",
"trove-classifiers",
"wheel",
]
["tool.setuptools"]
py-modules = [
"cs.gimmicks",
]
["tool.setuptools".package-dir.""]
"" = "lib/python"
I’ve been hand hacking those bottom 2 tables in various ways and running:
python3 -m build -o . --wheel
all to no avail. I either get the incorrect lib/python/cs/gimmicks.py file in the wheel, or I get this error complaint:
error: Multiple top-level packages discovered in a flat-layout: ['lib', 'tmp185du45n'].
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.
Their package discover docs have not helped me.
Can someone explain what I could be putting here? Ideally not some autodiscovery config. (Indeed, their docs same the providing py-modules or packages turns off the autodiscovery, which is as I want it.)