diff --git a/src/validate_pyproject/api.py b/src/validate_pyproject/api.py index 779daf6..2c6bce2 100644 --- a/src/validate_pyproject/api.py +++ b/src/validate_pyproject/api.py @@ -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 diff --git a/src/validate_pyproject/plugins/distutils.schema.json b/src/validate_pyproject/plugins/distutils.schema.json index 213fc0c..93cd2e8 100644 --- a/src/validate_pyproject/plugins/distutils.schema.json +++ b/src/validate_pyproject/plugins/distutils.schema.json @@ -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", diff --git a/src/validate_pyproject/plugins/setuptools.schema.json b/src/validate_pyproject/plugins/setuptools.schema.json index 8b31143..226facd 100644 --- a/src/validate_pyproject/plugins/setuptools.schema.json +++ b/src/validate_pyproject/plugins/setuptools.schema.json @@ -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", diff --git a/src/validate_pyproject/project_metadata.schema.json b/src/validate_pyproject/project_metadata.schema.json index 462eb16..8ad7199 100644 --- a/src/validate_pyproject/project_metadata.schema.json +++ b/src/validate_pyproject/project_metadata.schema.json @@ -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", diff --git a/src/validate_pyproject/pyproject_toml.schema.json b/src/validate_pyproject/pyproject_toml.schema.json index 13a9105..2e06117 100644 --- a/src/validate_pyproject/pyproject_toml.schema.json +++ b/src/validate_pyproject/pyproject_toml.schema.json @@ -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", diff --git a/tests/test_api.py b/tests/test_api.py index 4d5e75e..48e7ce2 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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)