From 39c9cde7593e8e81b7cd59d6294f0351dee13485 Mon Sep 17 00:00:00 2001 From: tlento Date: Thu, 10 Aug 2023 11:24:10 -0700 Subject: [PATCH] Remove jsonschema dependencies MetricFlow's jsonschema dependency was a holdover from the days when it was a monolithic package supporting both open source and Transform internal use cases. The last remaining dependency was jsonschema parsing support for some Transform-specific attributes, which are no longer in use. This removes all explicit jsonschema dependencies, instead relying on dbt-semantic-interfaces for managing the relevant package installation requirements. --- metricflow/model/parsing/__init__.py | 0 metricflow/model/parsing/schemas_internal.py | 111 ------------------- pyproject.toml | 2 - 3 files changed, 113 deletions(-) delete mode 100644 metricflow/model/parsing/__init__.py delete mode 100644 metricflow/model/parsing/schemas_internal.py diff --git a/metricflow/model/parsing/__init__.py b/metricflow/model/parsing/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/metricflow/model/parsing/schemas_internal.py b/metricflow/model/parsing/schemas_internal.py deleted file mode 100644 index b6cdf64521..0000000000 --- a/metricflow/model/parsing/schemas_internal.py +++ /dev/null @@ -1,111 +0,0 @@ -from __future__ import annotations - -from typing import Any, Dict - -from dbt_semantic_interfaces.parsing.schema_validator import SchemaValidator -from dbt_semantic_interfaces.parsing.schemas import ( - aggregation_type_params_schema, - dimension_schema, - dimension_type_params_schema, - entity_schema, - measure_schema, - metric_input_measure_schema, - metric_input_schema, - metric_schema, - metric_type_params_schema, - node_relation_schema, - non_additive_dimension_schema, - semantic_model_schema, - validity_params_schema, -) -from jsonschema import RefResolver - - -def add_transform_metadata_fields_to_spec(spec: Dict[str, Any]) -> None: # type: ignore[misc] - """Adds transform metadata fields a spec.""" - properties = spec["properties"] - transform_metadata_fields = { - "description": {"type": "string"}, - "owners": { - "type": "array", - "items": {"type": "string"}, - }, - "display_name": {"type": "string"}, - "tier": {"type": ["string", "integer"]}, - } - - for k, v in transform_metadata_fields.items(): - if k in properties: - raise RuntimeError(f"Spec with id: {spec['$id']} contains transform metadata field: {k}") - - properties[k] = v - - -def add_locked_metadata_to_spec(spec: Dict[str, Any]) -> None: # type: ignore[misc] - """Adds locked metadata field to a spec.""" - properties = spec["properties"] - transform_metadata_fields = { - "locked_metadata": {"$ref": "locked_metadata"}, - } - - for k, v in transform_metadata_fields.items(): - if k in properties: - raise RuntimeError(f"Spec with id: {spec['$id']} contains transform metadata field: {k}") - - properties[k] = v - - -# Sub-object schemas -locked_metadata_schema = { - "$id": "locked_metadata", - "type": "object", - "properties": { - "value_format": {"type": "string"}, - "description": {"type": "string"}, - "display_name": {"type": "string"}, - "tier": {"type": ["string", "integer"]}, - "increase_is_good": {"type": "boolean"}, - "tags": { - "type": "array", - "items": {"type": "string"}, - }, - "private": {"type": "boolean"}, - "unit": {"type": "string"}, - }, - "additionalProperties": False, -} - - -# Add transform metadata fields to top level objects (metric, semantic model, derived entity) -add_transform_metadata_fields_to_spec(dimension_schema) -add_transform_metadata_fields_to_spec(measure_schema) -add_transform_metadata_fields_to_spec(entity_schema) - -add_transform_metadata_fields_to_spec(metric_schema) -add_locked_metadata_to_spec(metric_schema) - -add_transform_metadata_fields_to_spec(semantic_model_schema) - - -schema_store = { - # Top level schemas - metric_schema["$id"]: metric_schema, - semantic_model_schema["$id"]: semantic_model_schema, - # Sub-object schemas - metric_input_measure_schema["$id"]: metric_input_measure_schema, - metric_type_params_schema["$id"]: metric_type_params_schema, - locked_metadata_schema["$id"]: locked_metadata_schema, - entity_schema["$id"]: entity_schema, - measure_schema["$id"]: measure_schema, - dimension_schema["$id"]: dimension_schema, - validity_params_schema["$id"]: validity_params_schema, - dimension_type_params_schema["$id"]: dimension_type_params_schema, - aggregation_type_params_schema["$id"]: aggregation_type_params_schema, - non_additive_dimension_schema["$id"]: non_additive_dimension_schema, - metric_input_schema["$id"]: metric_input_schema, - node_relation_schema["$id"]: node_relation_schema, -} - -resolver = RefResolver.from_schema(schema=metric_schema, store=schema_store) -semantic_model_validator = SchemaValidator(semantic_model_schema, resolver=resolver) -metric_validator = SchemaValidator(metric_schema, resolver=resolver) diff --git a/pyproject.toml b/pyproject.toml index 6ebe34fa06..c11e6a9679 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,6 @@ dependencies = [ "dbt-semantic-interfaces~=0.2.0", "graphviz>=0.18.2, <0.21", "halo~=0.0.31", - "jsonschema==3.2.0", "more-itertools>=8.10.0, <10.2.0", "numpy>=1.22.2", "pandas~=1.5.0", @@ -62,7 +61,6 @@ dev-packages = [ "pytest-xdist~=3.2.1", "pytest~=7.1.1", "types-PyYAML", - "types-jsonschema", "types-python-dateutil", "types-tabulate", ]