Skip to content

Commit

Permalink
chore: ruff-format (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Nov 2, 2023
1 parent 07abfad commit 5c82dc5
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 73 deletions.
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Expand Up @@ -4,13 +4,6 @@ ci:
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/psf/black
rev: "23.10.1"
hooks:
- id: black
args:
- "--preview"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -35,6 +28,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
Expand Down
6 changes: 3 additions & 3 deletions nox/_option_set.py
Expand Up @@ -205,9 +205,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.parser_args = args
self.parser_kwargs = kwargs
self.options: collections.OrderedDict[str, Option] = collections.OrderedDict()
self.groups: collections.OrderedDict[str, OptionGroup] = (
collections.OrderedDict()
)
self.groups: collections.OrderedDict[
str, OptionGroup
] = collections.OrderedDict()

def add_options(self, *args: Option) -> None:
"""Adds a sequence of Options to the OptionSet.
Expand Down
6 changes: 4 additions & 2 deletions nox/registry.py
Expand Up @@ -29,7 +29,8 @@


@overload
def session_decorator(__func: F) -> F: ...
def session_decorator(__func: F) -> F:
...


@overload
Expand All @@ -42,7 +43,8 @@ def session_decorator(
venv_backend: Any | None = ...,
venv_params: Any | None = ...,
tags: Sequence[str] | None = ...,
) -> Callable[[F], F]: ...
) -> Callable[[F], F]:
...


def session_decorator(
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Expand Up @@ -81,6 +81,9 @@ extend-select = [
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"ISC001", # Conflicts with formatter
]

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
42 changes: 28 additions & 14 deletions tests/test__version.py
Expand Up @@ -56,32 +56,40 @@ def test_get_nox_version() -> None:
[
("", None),
(
dedent("""
dedent(
"""
import nox
nox.needs_version = '>=2020.12.31'
"""),
"""
),
">=2020.12.31",
),
(
dedent("""
dedent(
"""
import nox
nox.needs_version = 'bogus'
nox.needs_version = '>=2020.12.31'
"""),
"""
),
">=2020.12.31",
),
(
dedent("""
dedent(
"""
import nox.sessions
nox.needs_version = '>=2020.12.31'
"""),
"""
),
">=2020.12.31",
),
(
dedent("""
dedent(
"""
import nox as _nox
_nox.needs_version = '>=2020.12.31'
"""),
"""
),
None,
),
],
Expand All @@ -94,30 +102,36 @@ def test_parse_needs_version(text: str, expected: str | None) -> None:
@pytest.mark.parametrize("specifiers", ["", ">=2020.12.31", ">=2020.12.31,<9999.99.99"])
def test_check_nox_version_succeeds(temp_noxfile, specifiers: str) -> None:
"""It does not raise if the version specifiers are satisfied."""
text = dedent(f"""
text = dedent(
f"""
import nox
nox.needs_version = "{specifiers}"
""")
"""
)
check_nox_version(temp_noxfile(text))


@pytest.mark.parametrize("specifiers", [">=9999.99.99"])
def test_check_nox_version_fails(temp_noxfile, specifiers: str) -> None:
"""It raises an exception if the version specifiers are not satisfied."""
text = dedent(f"""
text = dedent(
f"""
import nox
nox.needs_version = "{specifiers}"
""")
"""
)
with pytest.raises(VersionCheckFailed):
check_nox_version(temp_noxfile(text))


@pytest.mark.parametrize("specifiers", ["invalid", "2020.12.31"])
def test_check_nox_version_invalid(temp_noxfile, specifiers: str) -> None:
"""It raises an exception if the version specifiers cannot be parsed."""
text = dedent(f"""
text = dedent(
f"""
import nox
nox.needs_version = "{specifiers}"
""")
"""
)
with pytest.raises(InvalidVersionSpecifier):
check_nox_version(temp_noxfile(text))
3 changes: 2 additions & 1 deletion tests/test_action_helper.py
Expand Up @@ -62,7 +62,8 @@ def test_filter_version_invalid_minor():
",".join(f"3.{minor}" for minor in range(20)): [
f"3.{minor}"
for i, minor in enumerate(minor_ for minor_ in range(20) if minor_ != 11)
] + ["3.11"],
]
+ ["3.11"],
}


Expand Down
12 changes: 8 additions & 4 deletions tests/test_tasks.py
Expand Up @@ -113,22 +113,26 @@ def reset_global_nox_options():


def test_load_nox_module_needs_version_static(reset_needs_version, tmp_path):
text = dedent("""
text = dedent(
"""
import nox
nox.needs_version = ">=9999.99.99"
""")
"""
)
noxfile = tmp_path / "noxfile.py"
noxfile.write_text(text)
config = _options.options.namespace(noxfile=str(noxfile))
assert tasks.load_nox_module(config) == 2


def test_load_nox_module_needs_version_dynamic(reset_needs_version, tmp_path):
text = dedent("""
text = dedent(
"""
import nox
NOX_NEEDS_VERSION = ">=9999.99.99"
nox.needs_version = NOX_NEEDS_VERSION
""")
"""
)
noxfile = tmp_path / "noxfile.py"
noxfile.write_text(text)
config = _options.options.namespace(noxfile=str(noxfile))
Expand Down

0 comments on commit 5c82dc5

Please sign in to comment.