Skip to content

[BUG] [pyproject.toml] Setuptools improperly backfills values in pyproject.toml #3195

Closed
@domdfcoding

Description

@domdfcoding

setuptools version

setuptools==61.0.0

Python version

Python 3.8

OS

Ubuntu

Additional environment information

No response

Description

When using pyproject.toml for configuration alongside setup.cfg, setuptools will use the value for classifiers from setup.cfg if it is not given in pyprojet.toml even ifclassifiers is not listed in dynamic. This is not allowed under PEP 621[1]

If the metadata does not list a field in dynamic, then a build back-end CANNOT fill in the requisite metadata on behalf of the user (i.e. dynamic is the only way to allow a tool to fill in metadata and the user must opt into the filling in).

[1] https://peps.python.org/pep-0621/#dynamic

Expected behavior

setuptools should only take the value from setup.cfg is classifiers is listed in dynamic.

There is a separate issue where if classifiers is in dynamic, setuptools throws an error:

  File "/tmp/build-env-lbp441r9/lib/python3.8/site-packages/setuptools/dist.py", line 836, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/tmp/build-env-lbp441r9/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 52, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
  File "/tmp/build-env-lbp441r9/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 118, in read_configuration
    return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
  File "/tmp/build-env-lbp441r9/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 163, in expand_configuration
    _expand_all_dynamic(project_cfg, setuptools_cfg, package_dir, root_dir, ignore)
  File "/tmp/build-env-lbp441r9/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py", line 252, in _expand_all_dynamic
    project_cfg["classifiers"] = value.splitlines()
AttributeError: 'NoneType' object has no attribute 'splitlines'

How to Reproduce

  1. Clone the following gist: https://gist.github.com/domdfcoding/88f2b9d8e7cfd3c39a3404c3be6e4c87
  2. Build the project with python3 -m pip wheel .
  3. Inspect the METADATA file in the wheel, and observe the presence of the Development Status :: 5 - Production/Stable classifier.

Output

N/A

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions