Skip to content
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

feat: support PEP 639 #210

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/validate_pyproject/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,9 @@ def uint(value: builtins.int) -> bool:
def int(value: builtins.int) -> bool:
r"""Signed 64-bit integer (:math:`-2^{63} \leq x < 2^{63}`)"""
return -(2**63) <= value < 2**63


def SPDX(value: str) -> bool:
"""Should validate eventually"""
henryiii marked this conversation as resolved.
Show resolved Hide resolved
# TODO: validate conditional to the presence of (the right version) of packaging
return True
79 changes: 55 additions & 24 deletions src/validate_pyproject/project_metadata.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
"`Project license <https://peps.python.org/pep-0621/#license>`_.",
"oneOf": [
{
"type": "string",
"description": "An SPDX license identifier",
"format": "SPDX"
},
{
"type": "object",
"properties": {
"file": {
"type": "string",
Expand All @@ -116,6 +122,7 @@
"required": ["file"]
},
{
"type": "object",
"properties": {
"text": {
"type": "string",
Expand All @@ -130,6 +137,13 @@
}
]
},
"license-files": {
"description": "Paths or globs to paths of license files",
"type": "array",
"items": {
"type": "string"
}
},
"authors": {
"type": "array",
"items": {"$ref": "#/definitions/author"},
Expand Down Expand Up @@ -232,6 +246,7 @@
"readme",
"requires-python",
"license",
"license-files",
"authors",
"maintainers",
"keywords",
Expand All @@ -248,32 +263,48 @@
},
"required": ["name"],
"additionalProperties": false,
"if": {
"not": {
"required": ["dynamic"],
"properties": {
"dynamic": {
"contains": {"const": "version"},
"$$description": ["version is listed in ``dynamic``"]
}
"allOf": [
{
"if": {
"not": {
"required": ["dynamic"],
"properties": {
"dynamic": {
"contains": {"const": "version"},
"$$description": ["version is listed in ``dynamic``"]
}
}
},
"$$comment": [
"According to :pep:`621`:",
" If the core metadata specification lists a field as \"Required\", then",
" the metadata MUST specify the field statically or list it in dynamic",
"In turn, `core metadata`_ defines:",
" The required fields are: Metadata-Version, Name, Version.",
" All the other fields are optional.",
"Since ``Metadata-Version`` is defined by the build back-end, ``name`` and",
"``version`` are the only mandatory information in ``pyproject.toml``.",
".. _core metadata: https://packaging.python.org/specifications/core-metadata/"
]
},
"then": {
"required": ["version"],
"$$description": ["version should be statically defined in the ``version`` field"]
}
},
"$$comment": [
"According to :pep:`621`:",
" If the core metadata specification lists a field as \"Required\", then",
" the metadata MUST specify the field statically or list it in dynamic",
"In turn, `core metadata`_ defines:",
" The required fields are: Metadata-Version, Name, Version.",
" All the other fields are optional.",
"Since ``Metadata-Version`` is defined by the build back-end, ``name`` and",
"``version`` are the only mandatory information in ``pyproject.toml``.",
".. _core metadata: https://packaging.python.org/specifications/core-metadata/"
]
},
"then": {
"required": ["version"],
"$$description": ["version should be statically defined in the ``version`` field"]
},
{
"if": {
"required": ["license-files"]
},
"then": {
"properties": {
"license": {
"type": "string"
}
}
}
}
],

"definitions": {
"author": {
Expand Down
5 changes: 5 additions & 0 deletions tests/examples/simple/pep638.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
name = "example"
version = "1.2.3"
license = "MIT OR GPL-2.0-or-later OR (FSFUL AND BSD-2-Clause)"
license-files = ["licenses/LICENSE.MIT", "licenses/LICENSE.CC0"]
1 change: 1 addition & 0 deletions tests/invalid-examples/pep621/pep639/bothstyles.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`project.license` must be string
5 changes: 5 additions & 0 deletions tests/invalid-examples/pep621/pep639/bothstyles.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
name = "x"
version = "1.2.3"
license.text = "Something"
license-files = ["value"]