Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding a json schema command #3446

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

henryiii
Copy link

@henryiii henryiii commented Nov 15, 2024

Started on a schema command that produces a JSONSchema. Includes a --strict mode that doesn't allow extra unknown commands. Mostly respects and supports plugins (tox-gh and tox-uv tested locally).

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

Making a draft PR to store progress.

Current schema can be seen rendered into the PR at the moment.

@henryiii
Copy link
Author

Adding a commit that would support plugins setup like tox-gh. To actually fix that one, though, it needs to be modified a bit something like this:

    bail_reason = None
    if state.conf.options.command == "schema":
        pass
    elif not core_conf["is_on_gh_action"]:
        bail_reason = "tox is not running in GitHub Actions"
    elif getattr(getattr(state.conf.options, "env", None), "is_default_list", False) is False:
        bail_reason = f"envlist is explicitly given via {'TOXENV' if os.environ.get('TOXENV') else '-e flag'}"
    else:
        logging.warning("running tox-gh")

@ssbarnea ssbarnea self-requested a review November 18, 2024 18:49
@ssbarnea ssbarnea changed the title feat: adding a schema command feat: adding a json schema command Nov 18, 2024
@henryiii henryiii force-pushed the henryiii/feat/schema branch 2 times, most recently from e535caf to d736d50 Compare November 20, 2024 06:15
Now running this passes:

    uvx check-jsonschema --schemafile src/tox/tox.schema.json tox.toml

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii force-pushed the henryiii/feat/schema branch 2 times, most recently from 7de32ca to b8f138a Compare November 20, 2024 06:41
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would want to ensure that the generated schema is valid, you can make use of https://python-jsonschema.readthedocs.io/en/latest/validate/ for validating it. We already do this in ansible-lint with ~20 schemas if you want to take a look.

@henryiii
Copy link
Author

henryiii commented Nov 24, 2024

I've been using uvx check-jsonschema --schemafile src/tox/tox.schema.json tox.toml to check it locally so I just need to look up a Python API for it, I'll check ansible-lint's usage. The biggest question, though; does it make sense to keep a (continually) rendered version in the repo? Or should it only be generated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants