Skip to content

Commit

Permalink
fix: changelog and update test list
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Nov 20, 2024
1 parent 0123251 commit b8f138a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/changelog/3446.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add a ``schema`` command to produce a JSON Schema for tox and the current plugins.

- by :user:`henryiii`
5 changes: 2 additions & 3 deletions src/tox/session/cmd/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import typing
from pathlib import Path
from types import NoneType
from typing import TYPE_CHECKING

import packaging.requirements
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions tests/config/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions tests/session/cmd/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

import json
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("-qq", "schema")
schema = json.loads(result.out)
assert "properties" in schema
assert "tox_root" in schema["properties"]

0 comments on commit b8f138a

Please sign in to comment.