Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FR] Relax package-data format in pyproject.toml so that it allows hyphens #4772

Description

@kfreezen

setuptools version

setuptools==75.6.0

Python version

Python 3.12.7

OS

macOS Sequoia (M3)

Additional environment information

No response

Description

This looks to be similar to #4341, but not sure.

The following works in setup.py

setup(
  ...,
  package_data={"some-hypens": ["file1", "file2"]}
)

but, if I do the following in pyproject.toml

[tool.setuptools.package-data]
some-hyphens = ["file1", "file2"]

I get the following error message:

... traceback omitted for conciseness ...
ValueError: invalid pyproject.toml config: `tool.setuptools.package-data`.
configuration error: `tool.setuptools.package-data` keys must be named by:

    at least one of the following:
      - {type: string, format: 'python-module-name'}
      - {predefined value: '*'}

If this is expected behavior, it is not clearly documented in https://setuptools.pypa.io/en/stable/userguide/datafiles.html

Expected behavior

I expected to be able to use hyphens in [tool.setuptools.package-data] in the exact same way that I used them in setup.py

How to Reproduce

  1. Clone my reproduction repo: https://github.com/kfreezen/package_data_repro
  2. Inside repo, run python -m build

Brainless reproduction script:

git clone https://github.com/kfreezen/package_data_repro.git
cd package_data_repro
python -m venv venv
. venv/bin/activate
pip install build
python -m build

Output

test git clone https://github.com/kfreezen/package_data_repro.git
cd package_data_repro
python -m venv venv
. venv/bin/activate
pip install build
python -m build
Cloning into 'package_data_repro'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (6/6), done.
Collecting build
  Using cached build-1.2.2.post1-py3-none-any.whl.metadata (6.5 kB)
Collecting packaging>=19.1 (from build)
  Using cached packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
Collecting pyproject_hooks (from build)
  Using cached pyproject_hooks-1.2.0-py3-none-any.whl.metadata (1.3 kB)
Using cached build-1.2.2.post1-py3-none-any.whl (22 kB)
Using cached packaging-24.2-py3-none-any.whl (65 kB)
Using cached pyproject_hooks-1.2.0-py3-none-any.whl (10 kB)
Installing collected packages: pyproject_hooks, packaging, build
Successfully installed build-1.2.2.post1 packaging-24.2 pyproject_hooks-1.2.0

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools==75.6.0
* Getting build dependencies for sdist...
configuration error: `tool.setuptools.package-data` keys must be named by:

    at least one of the following:
      - {type: string, format: 'python-module-name'}
      - {predefined value: '*'}

DESCRIPTION:
    Mapping from package names to lists of glob patterns. Usually this option is
    not needed when using ``include-package-data = true`` For more information
    on how to include data files, check ``setuptools`` `docs
    <https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_.

GIVEN VALUE:
    {
        "some-hyphens": [
            "README.md"
        ]
    }

OFFENDING RULE: 'propertyNames'

DEFINITION:
    {
        "type": "object",
        "additionalProperties": false,
        "propertyNames": {
            "anyOf": [
                {
                    "type": "string",
                    "format": "python-module-name"
                },
                {
                    "const": "*"
                }
            ]
        },
        "patternProperties": {
            "^.*$": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        }
    }

For more details about `format` see
https://validate-pyproject.readthedocs.io/en/latest/api/validate_pyproject.formats.html

Traceback (most recent call last):
  File "/Users/kfreezen/git/test/package_data_repro/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/Users/kfreezen/git/test/package_data_repro/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kfreezen/git/test/package_data_repro/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 317, in get_requires_for_build_sdist
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/build_meta.py", line 337, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
    self.run_setup()
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 157, in setup
    dist.parse_config_files()
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/dist.py", line 648, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 72, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 140, in read_configuration
    validate(subset, filepath)
  File "/private/var/folders/tm/qpl2pxbx66d29h6s9nk_gdmr0000gp/T/build-env-80m650g5/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 61, in validate
    raise ValueError(f"{error}\n{summary}") from None
ValueError: invalid pyproject.toml config: `tool.setuptools.package-data`.
configuration error: `tool.setuptools.package-data` keys must be named by:

    at least one of the following:
      - {type: string, format: 'python-module-name'}
      - {predefined value: '*'}


ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions