diff --git a/Makefile b/Makefile index 5874cb7..f9f3f1b 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ PYTHON ?= $(PY_ENV_DIR)/bin/python endif PY_ENV_STAMP := $(PY_ENV_DIR)/.stamp INSTALL_STAMP := $(PY_ENV_DIR)/.install-stamp +LOCAL_DIST_DIR := dist-install-local ifneq ($(filter install-local uninstall-local,$(MAKECMDGOALS)),) ifeq ($(origin PYTHON),file) @@ -38,6 +39,9 @@ help: # Create/update the virtual environment and install dev/test dependencies py-env: $(PY_ENV_STAMP) +$(PY_ENV_DIR)/bin/python: + $(PYTHON_BOOTSTRAP) -m venv $(PY_ENV_DIR) + $(PY_ENV_STAMP): gts/pyproject.toml .gts-spec/tests/requirements.txt Makefile @echo "Creating/updating Python virtual environment in $(PY_ENV_DIR)..." $(PYTHON_BOOTSTRAP) -m venv $(PY_ENV_DIR) @@ -60,8 +64,11 @@ build: py-env $(PYTHON) -m build --outdir dist ./gts # Install the locally built wheel, equivalent to installing the published gts package -install-local: build - $(PYTHON) -m pip install --force-reinstall dist/gts-*.whl +install-local: $(if $(filter $(PY_ENV_DIR)/bin/python,$(PYTHON)),$(PY_ENV_DIR)/bin/python) + @rm -rf $(LOCAL_DIST_DIR) + $(PYTHON) -m pip install --upgrade build + $(PYTHON) -m build --outdir $(LOCAL_DIST_DIR) ./gts + $(PYTHON) -m pip install --force-reinstall $(LOCAL_DIST_DIR)/gts-*.whl # Uninstall gts from the selected interpreter uninstall-local: @@ -70,7 +77,7 @@ uninstall-local: # Remove venv and build artifacts clean: - rm -rf $(PY_ENV_DIR) dist/ gts/dist/ gts/*.egg-info + rm -rf $(PY_ENV_DIR) dist/ $(LOCAL_DIST_DIR) gts/dist/ gts/*.egg-info # -------- Code quality -------- diff --git a/gts/src/gts/_cli.py b/gts/src/gts/_cli.py index 31c16f7..fc5cd1b 100644 --- a/gts/src/gts/_cli.py +++ b/gts/src/gts/_cli.py @@ -39,6 +39,18 @@ def build_parser() -> argparse.ArgumentParser: ) s.add_argument("--gts-id", required=True, help="GTS ID of the object") + s = sub.add_parser( + "validate-type-schema", + help="Validate a type schema against its base type schema (OP#12 schema-vs-schema)", + ) + s.add_argument("--gts-id", required=True, help="GTS ID of the type schema") + + s = sub.add_parser( + "validate-entity", + help="Validate an entity (instance or schema) by GTS ID", + ) + s.add_argument("--gts-id", required=True, help="GTS ID of the entity") + s = sub.add_parser( "resolve-relationships", help="Resolve relationships for an entity" ) @@ -144,6 +156,10 @@ def main(argv: list[str] | None = None) -> None: out = ops.uuid(args.gts_id).to_dict() elif args.op == "validate-instance": out = ops.validate_instance(args.gts_id).to_dict() + elif args.op == "validate-type-schema": + out = ops.validate_schema(args.gts_id).to_dict() + elif args.op == "validate-entity": + out = ops.validate_entity(args.gts_id).to_dict() elif args.op == "resolve-relationships": out = ops.schema_graph(args.gts_id).to_dict() elif args.op == "compatibility": diff --git a/tests/test_cli.py b/tests/test_cli.py index ae7177d..9ce6a62 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,6 +25,16 @@ "--gts-id", "gts.vendor.package.namespace.type.v1~vendor.package.namespace.item.v1", ], + [ + "validate-type-schema", + "--gts-id", + "gts.vendor.package.namespace.type.v1~", + ], + [ + "validate-entity", + "--gts-id", + "gts.vendor.package.namespace.type.v1~", + ], ["resolve-relationships", "--gts-id", "gts.vendor.package.namespace.type.v1~"], [ "compatibility",