Skip to content

Commit

Permalink
feat: support PEP 639 (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Oct 15, 2024
2 parents 41e9e09 + 9236307 commit cbfc444
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 24 deletions.
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"""
# 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"]

0 comments on commit cbfc444

Please sign in to comment.