From 4b7244937eea1a5bcd1c64377920009a19e14dc0 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 29 Mar 2025 22:12:06 +0100 Subject: [PATCH 1/2] Allow package-data for stubs packages --- CHANGELOG.rst | 2 ++ .../plugins/setuptools.schema.json | 12 ++++++++++-- tests/examples/setuptools/08-pyproject.toml | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e08559a6..8eb85a87 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,8 @@ Changelog Development Version ==================== +* Added support for specifying package-data for stub packages, #248. + Version 0.24.1 ============== diff --git a/src/validate_pyproject/plugins/setuptools.schema.json b/src/validate_pyproject/plugins/setuptools.schema.json index ec887b35..73336815 100644 --- a/src/validate_pyproject/plugins/setuptools.schema.json +++ b/src/validate_pyproject/plugins/setuptools.schema.json @@ -116,7 +116,11 @@ "type": "object", "additionalProperties": false, "propertyNames": { - "anyOf": [{"type": "string", "format": "python-module-name"}, {"const": "*"}] + "anyOf": [ + {"type": "string", "format": "python-module-name"}, + {"type": "string", "format": "pep561-stub-name"}, + {"const": "*"} + ] }, "patternProperties": { "^.*$": {"type": "array", "items": {"type": "string"}} @@ -140,7 +144,11 @@ "type": "object", "additionalProperties": false, "propertyNames": { - "anyOf": [{"type": "string", "format": "python-module-name"}, {"const": "*"}] + "anyOf": [ + {"type": "string", "format": "python-module-name"}, + {"type": "string", "format": "pep561-stub-name"}, + {"const": "*"} + ] }, "patternProperties": { "^.*$": {"type": "array", "items": {"type": "string"}} diff --git a/tests/examples/setuptools/08-pyproject.toml b/tests/examples/setuptools/08-pyproject.toml index 0e7ccd93..e01ee07e 100644 --- a/tests/examples/setuptools/08-pyproject.toml +++ b/tests/examples/setuptools/08-pyproject.toml @@ -16,3 +16,7 @@ packages = ["mypkg-stubs"] [tool.setuptools.package-data] "*" = ["*.pyi"] +"mypkg-stubs" = ["METADATA.toml"] + +[tool.setuptools.exclude-package-data] +"mypkg-stubs" = ["*.rst"] From 80a6d7dac474908dd43f2fd418e666cd8c3663de Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:42:45 +0200 Subject: [PATCH 2/2] Add formatter function to reduce duplications --- src/validate_pyproject/formats.py | 9 +++++++++ .../plugins/setuptools.schema.json | 16 ++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/validate_pyproject/formats.py b/src/validate_pyproject/formats.py index 1cf4a465..ae016994 100644 --- a/src/validate_pyproject/formats.py +++ b/src/validate_pyproject/formats.py @@ -313,6 +313,15 @@ def python_module_name_relaxed(value: str) -> bool: return python_module_name(value.replace("-", "_")) +def package_data_module_name_or_wildcard(value: str) -> bool: + """Python module name, stubs package name or wildcard used for package-data.""" + if value == "*": + return True + if python_module_name(value): + return True + return pep561_stub_name(value) + + def python_entrypoint_group(value: str) -> bool: """See ``Data model > group`` in the :ref:`PyPA's entry-points specification `. diff --git a/src/validate_pyproject/plugins/setuptools.schema.json b/src/validate_pyproject/plugins/setuptools.schema.json index 73336815..330085d9 100644 --- a/src/validate_pyproject/plugins/setuptools.schema.json +++ b/src/validate_pyproject/plugins/setuptools.schema.json @@ -115,13 +115,7 @@ ], "type": "object", "additionalProperties": false, - "propertyNames": { - "anyOf": [ - {"type": "string", "format": "python-module-name"}, - {"type": "string", "format": "pep561-stub-name"}, - {"const": "*"} - ] - }, + "propertyNames": {"type": "string", "format": "package-data-module-name-or-wildcard"}, "patternProperties": { "^.*$": {"type": "array", "items": {"type": "string"}} } @@ -143,13 +137,7 @@ ], "type": "object", "additionalProperties": false, - "propertyNames": { - "anyOf": [ - {"type": "string", "format": "python-module-name"}, - {"type": "string", "format": "pep561-stub-name"}, - {"const": "*"} - ] - }, + "propertyNames": {"type": "string", "format": "package-data-module-name-or-wildcard"}, "patternProperties": { "^.*$": {"type": "array", "items": {"type": "string"}} }