Skip to content

Commit

Permalink
fix: validate entries in nox.config, too
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 12, 2024
1 parent 9731a53 commit 8662eb5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ repos:
files: ^nox/
args: []
additional_dependencies:
- attrs
- colorlog
- dependency-groups>=1.2
- jinja2
Expand Down
59 changes: 27 additions & 32 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,44 @@

import argparse
import collections
import dataclasses
import functools
from argparse import ArgumentError as ArgumentError # noqa: PLC0414
from argparse import ArgumentParser, Namespace
from collections.abc import Callable, Iterable
from typing import Any, Literal

import argcomplete
import attrs
import attrs.validators as av

av_opt_str = av.optional(av.instance_of(str))
av_opt_list_str = av.optional(
av.deep_iterable(
member_validator=av.instance_of(str),
iterable_validator=attrs.validators.instance_of(list),
)
)
av_bool = av.instance_of(bool)


# Python 3.10+ has slots=True (or attrs does), also kwonly=True
@dataclasses.dataclass
@attrs.define(slots=True, kw_only=True)
class NoxOptions:
__slots__ = (
"default_venv_backend",
"envdir",
"error_on_external_run",
"error_on_missing_interpreters",
"force_venv_backend",
"keywords",
"pythons",
"report",
"reuse_existing_virtualenvs",
"reuse_venv",
"sessions",
"stop_on_first_error",
"tags",
"verbose",
default_venv_backend: None | str = attrs.field(validator=av_opt_str)
envdir: None | str = attrs.field(validator=av_opt_str)
error_on_external_run: bool = attrs.field(validator=av_bool)
error_on_missing_interpreters: bool = attrs.field(validator=av_bool)
force_venv_backend: None | str = attrs.field(validator=av_opt_str)
keywords: None | list[str] = attrs.field(validator=av_opt_list_str)
pythons: None | list[str] = attrs.field(validator=av_opt_list_str)
report: None | str = attrs.field(validator=av_opt_str)
reuse_existing_virtualenvs: bool = attrs.field(validator=av_bool)
reuse_venv: None | Literal["no", "yes", "never", "always"] = attrs.field(
validator=av.optional(av.in_(["no", "yes", "never", "always"]))
)
default_venv_backend: None | str
envdir: None | str
error_on_external_run: bool
error_on_missing_interpreters: bool
force_venv_backend: None | str
keywords: None | list[str]
pythons: None | list[str]
report: None | str
reuse_existing_virtualenvs: bool
reuse_venv: None | Literal["no", "yes", "never", "always"]
sessions: None | list[str]
stop_on_first_error: bool
tags: None | list[str]
verbose: bool
sessions: None | list[str] = attrs.field(validator=av_opt_list_str)
stop_on_first_error: bool = attrs.field(validator=av_bool)
tags: None | list[str] = attrs.field(validator=av_opt_list_str)
verbose: bool = attrs.field(validator=av_bool)


class OptionGroup:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ classifiers = [
]
dependencies = [
"argcomplete>=1.9.4,<4",
"attrs>=23.1",
"colorlog>=2.6.1,<7",
"dependency-groups>=1.1",
"packaging>=20.9",
Expand Down

0 comments on commit 8662eb5

Please sign in to comment.