From d736d505c5d37973cf77e94a281001e2c7d933a4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 20 Nov 2024 00:33:54 -0500 Subject: [PATCH] fix: changelog and update test list Signed-off-by: Henry Schreiner --- docs/changelog/3446.feature.rst | 3 +++ src/tox/session/cmd/schema.py | 5 ++--- tests/config/cli/conftest.py | 2 ++ tests/session/cmd/test_schema.py | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/3446.feature.rst create mode 100644 tests/session/cmd/test_schema.py diff --git a/docs/changelog/3446.feature.rst b/docs/changelog/3446.feature.rst new file mode 100644 index 000000000..6edb4c852 --- /dev/null +++ b/docs/changelog/3446.feature.rst @@ -0,0 +1,3 @@ +Add a ``schema`` command to produce a JSON Schema for tox and the current plugins. + +- by :user:`henryiii` diff --git a/src/tox/session/cmd/schema.py b/src/tox/session/cmd/schema.py index 3a4af420e..ee708756d 100644 --- a/src/tox/session/cmd/schema.py +++ b/src/tox/session/cmd/schema.py @@ -6,7 +6,6 @@ import sys import typing from pathlib import Path -from types import NoneType from typing import TYPE_CHECKING import packaging.requirements @@ -39,7 +38,7 @@ def _process_type(of_type: typing.Any) -> dict[str, typing.Any]: # noqa: C901, }: return {"type": "string"} if typing.get_origin(of_type) is typing.Union: - types = [x for x in typing.get_args(of_type) if x is not NoneType] + types = [x for x in typing.get_args(of_type) if x is not type(None)] if len(types) == 1: return _process_type(types[0]) msg = f"Union types are not supported: {of_type}" @@ -95,7 +94,7 @@ def gen_schema(state: State) -> int: strict = state.conf.options.strict # Accessing this adds extra stuff to core, so we need to do it first - env_properties = _get_schema(state.envs["3.13"].conf, path="#/properties/env_run_base/properties") + env_properties = _get_schema(state.envs["py"].conf, path="#/properties/env_run_base/properties") properties = _get_schema(core, path="#/properties") diff --git a/tests/config/cli/conftest.py b/tests/config/cli/conftest.py index d5852bff8..69da08843 100644 --- a/tests/config/cli/conftest.py +++ b/tests/config/cli/conftest.py @@ -12,6 +12,7 @@ from tox.session.cmd.quickstart import quickstart from tox.session.cmd.run.parallel import run_parallel from tox.session.cmd.run.sequential import run_sequential +from tox.session.cmd.schema import gen_schema from tox.session.cmd.show_config import show_config if TYPE_CHECKING: @@ -23,6 +24,7 @@ def core_handlers() -> dict[str, Callable[[State], int]]: return { "config": show_config, "c": show_config, + "schema": gen_schema, "list": list_env, "l": list_env, "run": run_sequential, diff --git a/tests/session/cmd/test_schema.py b/tests/session/cmd/test_schema.py new file mode 100644 index 000000000..49d5ea257 --- /dev/null +++ b/tests/session/cmd/test_schema.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from pathlib import Path + + from tox.pytest import MonkeyPatch, ToxProjectCreator + + +def test_show_schema_empty_dir(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch, tmp_path: Path) -> None: + monkeypatch.chdir(tmp_path) + + project = tox_project({}) + result = project.run("schema") + assert "properties" in result.out