From d49cbecf8c336322eccdb767d4128dd7a8feecd0 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Fri, 23 Feb 2024 19:23:54 +0100 Subject: [PATCH] Cleanup spack.schema (#42815) * Move spec_list into its own file, instead of __init__.py * Remove spack.schema.spack This module was introduced in #33960 It's almost an exact duplicate of spack.schema.env, and is not used anywhere. * Fix typo --- lib/spack/spack/schema/__init__.py | 23 -------------- lib/spack/spack/schema/definitions.py | 4 +-- lib/spack/spack/schema/env.py | 6 ++-- lib/spack/spack/schema/spack.py | 46 --------------------------- lib/spack/spack/schema/spec_list.py | 24 ++++++++++++++ 5 files changed, 29 insertions(+), 74 deletions(-) delete mode 100644 lib/spack/spack/schema/spack.py create mode 100644 lib/spack/spack/schema/spec_list.py diff --git a/lib/spack/spack/schema/__init__.py b/lib/spack/spack/schema/__init__.py index d6df072117..03fe4039a8 100644 --- a/lib/spack/spack/schema/__init__.py +++ b/lib/spack/spack/schema/__init__.py @@ -6,7 +6,6 @@ import warnings import llnl.util.lang -import llnl.util.tty # jsonschema is imported lazily as it is heavy to import @@ -62,25 +61,3 @@ def _deprecated_properties(validator, deprecated, instance, schema): Validator = llnl.util.lang.Singleton(_make_validator) - -spec_list_schema = { - "type": "array", - "default": [], - "items": { - "anyOf": [ - { - "type": "object", - "additionalProperties": False, - "properties": { - "matrix": { - "type": "array", - "items": {"type": "array", "items": {"type": "string"}}, - }, - "exclude": {"type": "array", "items": {"type": "string"}}, - }, - }, - {"type": "string"}, - {"type": "null"}, - ] - }, -} diff --git a/lib/spack/spack/schema/definitions.py b/lib/spack/spack/schema/definitions.py index 1f8b8b4833..8f0699a175 100644 --- a/lib/spack/spack/schema/definitions.py +++ b/lib/spack/spack/schema/definitions.py @@ -10,7 +10,7 @@ """ from typing import Any, Dict -import spack.schema +from .spec_list import spec_list_schema #: Properties for inclusion in other schemas properties: Dict[str, Any] = { @@ -20,7 +20,7 @@ "items": { "type": "object", "properties": {"when": {"type": "string"}}, - "patternProperties": {r"^(?!when$)\w*": spack.schema.spec_list_schema}, + "patternProperties": {r"^(?!when$)\w*": spec_list_schema}, }, } } diff --git a/lib/spack/spack/schema/env.py b/lib/spack/spack/schema/env.py index 676fbeb277..d2df795a3d 100644 --- a/lib/spack/spack/schema/env.py +++ b/lib/spack/spack/schema/env.py @@ -16,11 +16,11 @@ import spack.schema.merged import spack.schema.projections +from .spec_list import spec_list_schema + #: Top level key in a manifest file TOP_LEVEL_KEY = "spack" -projections_scheme = spack.schema.projections.properties["projections"] - properties: Dict[str, Any] = { "spack": { "type": "object", @@ -34,7 +34,7 @@ # extra environment schema properties { "include": {"type": "array", "default": [], "items": {"type": "string"}}, - "specs": spack.schema.spec_list_schema, + "specs": spec_list_schema, }, ), } diff --git a/lib/spack/spack/schema/spack.py b/lib/spack/spack/schema/spack.py deleted file mode 100644 index 7d5a13c17e..0000000000 --- a/lib/spack/spack/schema/spack.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other -# Spack Project Developers. See the top-level COPYRIGHT file for details. -# -# SPDX-License-Identifier: (Apache-2.0 OR MIT) - -"""Schema for spack environment - -.. literalinclude:: _spack_root/lib/spack/spack/schema/spack.py - :lines: 20- -""" -from typing import Any, Dict - -from llnl.util.lang import union_dicts - -import spack.schema -import spack.schema.gitlab_ci as ci_schema # DEPRECATED -import spack.schema.merged as merged_schema - -#: Properties for inclusion in other schemas -properties: Dict[str, Any] = { - "spack": { - "type": "object", - "default": {}, - "additionalProperties": False, - "properties": union_dicts( - # Include deprecated "gitlab-ci" section - ci_schema.properties, - # merged configuration scope schemas - merged_schema.properties, - # extra environment schema properties - { - "include": {"type": "array", "default": [], "items": {"type": "string"}}, - "specs": spack.schema.spec_list_schema, - }, - ), - } -} - -#: Full schema with metadata -schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Spack environment file schema", - "type": "object", - "additionalProperties": False, - "properties": properties, -} diff --git a/lib/spack/spack/schema/spec_list.py b/lib/spack/spack/schema/spec_list.py new file mode 100644 index 0000000000..67d6b2745a --- /dev/null +++ b/lib/spack/spack/schema/spec_list.py @@ -0,0 +1,24 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) +matrix_schema = {"type": "array", "items": {"type": "array", "items": {"type": "string"}}} + +spec_list_schema = { + "type": "array", + "default": [], + "items": { + "anyOf": [ + { + "type": "object", + "additionalProperties": False, + "properties": { + "matrix": matrix_schema, + "exclude": {"type": "array", "items": {"type": "string"}}, + }, + }, + {"type": "string"}, + {"type": "null"}, + ] + }, +}