Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
domdfcoding opened this issue Mar 24, 2022 · 2 comments · Fixed by #3218
Closed

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

domdfcoding opened this issue Mar 24, 2022 · 2 comments · Fixed by #3218
Assignees
Labels

Comments

@domdfcoding
Copy link
Contributor

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

@domdfcoding domdfcoding added bug Needs Triage Issues that need to be evaluated for severity and status. labels Mar 24, 2022
@abravalheri
Copy link
Contributor

Thank you very much @domdfcoding for checking this.
Yeah it is definitely a bug and an edge case that I do not foresee coming.

@abravalheri
Copy link
Contributor

Hi @domdfcoding I have prepared a PR addressing this problem. However there seems to be a popular pattern in the community of people partially specifying the [project] table (without the proper dynamic).

To prevent existing packages from breaking I decided to issue an warning while still preserving the config values.

Once the transition phase is over, project metadata external to pyproject.toml that does not set dynamic properly, will be ignored.

If you need to be more strict, you can set PYTHONWARNINGS to error for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants