Skip to content
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
3 changes: 2 additions & 1 deletion src/validate_pyproject/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def _ensure_compatibility(self, reference: str, schema: Schema) -> Schema:
if sid in self._schemas:
raise errors.SchemaWithDuplicatedId(sid)
version = schema.get("$schema")
if version and version != self.spec_version:
# Support schemas with missing trailing # (incorrect, but required before 0.15)
if version and version.rstrip("#") != self.spec_version.rstrip("#"):
raise errors.InvalidSchemaVersion(reference, version, self.spec_version)
return schema

Expand Down
2 changes: 1 addition & 1 deletion src/validate_pyproject/plugins/distutils.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",

"$id": "https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html",
"title": "``tool.distutils`` table",
Expand Down
2 changes: 1 addition & 1 deletion src/validate_pyproject/plugins/setuptools.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",

"$id": "https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html",
"title": "``tool.setuptools`` table",
Expand Down
2 changes: 1 addition & 1 deletion src/validate_pyproject/project_metadata.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",

"$id": "https://packaging.python.org/en/latest/specifications/declaring-project-metadata/",
"title": "Package metadata stored in the ``project`` table",
Expand Down
2 changes: 1 addition & 1 deletion src/validate_pyproject/pyproject_toml.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",

"$id": "https://packaging.python.org/en/latest/specifications/declaring-build-dependencies/",
"title": "Data structure for ``pyproject.toml`` files",
Expand Down
12 changes: 10 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ def test_with_plugins(self):
assert "setuptools" in tool["properties"]
assert "$ref" in tool["properties"]["setuptools"]

def fake_plugin(self, name, schema_version=7):
def fake_plugin(self, name, schema_version=7, end="#"):
schema = {
"$id": f"https://example.com/{name}.schema.json",
"$schema": f"http://json-schema.org/draft-{schema_version:02d}/schema",
"$schema": f"http://json-schema.org/draft-{schema_version:02d}/schema{end}",
"type": "object",
}
return types.Schema(schema)

@pytest.mark.parametrize("end", ["", "#"], ids=["no#", "with#"])
def test_schema_ending(self, end):
fn = wraps(self.fake_plugin)(partial(self.fake_plugin, end=end))
plg = plugins.PluginWrapper("plugin", fn)
registry = api.SchemaRegistry([plg])
main_schema = registry[registry.main]
assert main_schema["$schema"] == "http://json-schema.org/draft-07/schema#"

def test_incompatible_versions(self):
fn = wraps(self.fake_plugin)(partial(self.fake_plugin, schema_version=8))
plg = plugins.PluginWrapper("plugin", fn)
Expand Down