13

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?

11
  • 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. Commented May 23, 2022 at 18:45
  • I tried, but it doesn't change anything. Commented May 24, 2022 at 1: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). Commented May 24, 2022 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. Commented May 24, 2022 at 13:18
  • 1
    You can install an user pip with pip install --user pip as a regular user... Commented May 24, 2022 at 17:40

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

That, or upgrade the thing.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.