11

I'm currently trying to move our internal projects away from setup.py to pyproject.toml (PEP-518). I'd like to not use build backend specific configuration if possible, even though I do specify the backend in the [build-system] section by require'ing it.

The pyproject.toml files are more or less straight-forward translations of the setup.py files, with the metadata set according to PEP-621, including the dependencies. We are using setuptools_scm for the determination of the version, therefore the version field ends up in the dynamic section.

We used to set the packages parameter to setup in our setup.py files, but I couldn't find any corresponding field in pyproject.toml, so I simply omitted it.

When building the project using python3 -m build ., I end up with a package named UNKNOWN, even though I have the name field set in the [project] section. It seems that this breaks very early in the build:

$ python -m build .
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools, setuptools_scm[toml]>=6.2, wheel)
* Getting dependencies for sdist...
running egg_info
writing UNKNOWN.egg-info/PKG-INFO
....

I'm using python 3.8.11 and the following packages:

build==0.8.0
distlib==0.3.4
filelock==3.4.1
packaging==21.3
pep517==0.12.0
pip==22.0.4
platformdirs==2.4.0
pyparsing==3.0.9
setuptools==62.1.0
six==1.16.0
tomli==1.2.3
virtualenv==20.14.1
wheel==0.37.1

My (abbreviated) pyproject.toml looks like this:

[project]
name = "coolproject"
dependencies = [
   'pyyaml==5.3',
   'anytree==2.8.0',
   'pytest'
]
dynamic = [
   "version"
]

[build-system]
requires = ["setuptools", "wheel", "setuptools_scm[toml]>=6.2"]

[tool.setuptools_scm]

Any ideas?

arne
  • 4,514
  • 1
  • 28
  • 47
  • 2
    Why not specify the `build-backend`? Does it work if you set it to `build-backend = "setuptools.build_meta"`? -- If not specified, the build front-end (_pip_) kind of defaults to invoking `setuptools.build_meta:__legacy__` instead which is probably not what you want here. – sinoroc May 23 '22 at 18:45
  • I tried, but it doesn't change anything. – arne May 24 '22 at 01:26
  • It should work. I do not see why it should not work. Maybe clean up things (for example: delete `dist` and `build` directories) and try again. Maybe also try without `setuptools_scm` first (make sure to set `version`). – sinoroc May 24 '22 at 13:03
  • 1
    I copied your pyproject.toml, replaced `dynamic = ["version"]` with `version = "1.0"`, did `git init && git add . && git commit -m x`, and ran `python -m build .` ... and got `coolproject-1.0` just fine. – AKX May 24 '22 at 13:18
  • @AKX: Doesn't work for me. Maybe an issue with the setuptools versions since PEP612 support is rather recent. – arne May 24 '22 at 16:06
  • Found the problem: My "system" pip is version 19.3.1, which apparently cannot install a version of setuptools that can handle PEP612 metadata. I can't get a new pip from within the pyproject.toml by adding it to `build-system.requires`, So I need to work with `--no-isolation` for the moment. – arne May 24 '22 at 16:24
  • 1
    You can install an user pip with `pip install --user pip` as a regular user... – AKX May 24 '22 at 17:40
  • @AKX Right! I totally forgot, because I only use venvs! Thanks, I'll try. – arne May 25 '22 at 06:30
  • @AKX Finally! Thank you so much! Wanna turn your comments into an answer? – arne May 25 '22 at 06:34
  • For a pure `pyproject.toml` (empty setup.cfg for editable installs), I had to set `dynamic=["version"]` and remove the version property altogether. – marscher Jun 15 '22 at 08:39
  • The build process is now extremely sensitive to where you put, and how you name your package and sub directories. basically they have to have the same exact name as you package. See my answer [here](https://stackoverflow.com/a/74421415/1147688) on the details about this. – not2qubit Nov 15 '22 at 02:51

2 Answers2

3

On Debian/Ubuntu "UNKNOWN" packages can be created if an older system version of setuptools is installed as well.

Workaround:

sudo apt purge python3-setuptools

https://github.com/pypa/setuptools/issues/3269

chrism
  • 31
  • 3
3

Turning @AKX's comments into an answer so that other people can find it more easily.

The problem may be an outdated pip/setuptools on the system. Apparently, version 19.3.1 which I have on my system cannot install a version of setuptools that can handle PEP621 metadata correctly.

You cannot require a new pip from within pyproject.toml using the build-system.requires directive.

In case you cannot update the system pip, you can always install on a per-user basis:

pip install --user pip

and you're good to go.

S Anand
  • 11,364
  • 2
  • 28
  • 23
arne
  • 4,514
  • 1
  • 28
  • 47