Skip to content

Commit

Permalink
chore: modernize Ruff config, bump pre-commit (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Nov 1, 2023
1 parent 404c63b commit b6e626b
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 234 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ ci:

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

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -26,18 +26,18 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.7.0"
rev: "1.3.0"
hooks:
- id: pyproject-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.255
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.6.1
hooks:
- id: mypy
files: ^nox/
Expand All @@ -48,7 +48,7 @@ repos:
- importlib_metadata

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.6
hooks:
- id: codespell

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Finally note that the ``--no-venv`` flag is a shortcut for ``--force-venv-backen
Re-using virtualenvs
--------------------

By default, Nox deletes and recreates virtualenvs every time it is run. This is usually fine for most projects and continuous integration environments as `pip's caching <https://pip.pypa.io/en/stable/cli/pip_install/#caching>`_ makes re-install rather quick. However, there are some situations where it is advantageous to re-use the virtualenvs between runs. Use ``-r`` or ``--reuse-existing-virtualenvs``:
By default, Nox deletes and recreates virtualenvs every time it is run. This is usually fine for most projects and continuous integration environments as `pip's caching <https://pip.pypa.io/en/stable/cli/pip_install/#caching>`_ makes re-install rather quick. However, there are some situations where it is advantageous to reuse the virtualenvs between runs. Use ``-r`` or ``--reuse-existing-virtualenvs``:

.. code-block:: console
Expand Down
8 changes: 3 additions & 5 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ def __init__(
noxfile: bool = False,
merge_func: Callable[[Namespace, Namespace], Any] | None = None,
finalizer_func: Callable[[Any, Namespace], Any] | None = None,
default: bool
| str
| None
| list[str]
| Callable[[], bool | str | None | list[str]] = None,
default: (
bool | str | None | list[str] | Callable[[], bool | str | None | list[str]]
) = None,
hidden: bool = False,
completer: Callable[..., Sequence[str]] | None = None,
**kwargs: Any,
Expand Down
10 changes: 4 additions & 6 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
_option_set.OptionGroup(
"environment",
"Environment options",
(
"These arguments are used to control Nox's creation and usage of virtual"
" environments."
),
"These arguments are used to control Nox's creation and usage of virtual"
" environments.",
),
_option_set.OptionGroup(
"execution",
Expand Down Expand Up @@ -394,7 +392,7 @@ def _session_completer(
"--no-reuse-existing-virtualenvs",
),
group=options.groups["environment"],
help="Re-use existing virtualenvs instead of recreating them.",
help="Reuse existing virtualenvs instead of recreating them.",
),
_option_set.Option(
"R",
Expand All @@ -403,7 +401,7 @@ def _session_completer(
group=options.groups["environment"],
action="store_true",
help=(
"Re-use existing virtualenvs and skip package re-installation."
"Reuse existing virtualenvs and skip package re-installation."
" This is an alias for '--reuse-existing-virtualenvs --no-install'."
),
finalizer_func=_R_finalizer,
Expand Down
6 changes: 2 additions & 4 deletions nox/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@


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


@overload
Expand All @@ -43,8 +42,7 @@ 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
6 changes: 2 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ def _check_python_version(session: nox.Session) -> None:
session.run(
"python",
"-c",
(
"import sys; assert '.'.join(str(v) for v in sys.version_info[:2]) =="
f" '{python_version}'"
),
"import sys; assert '.'.join(str(v) for v in sys.version_info[:2]) =="
f" '{python_version}'",
)
if python_version[:2] != "2.":
session.run(
Expand Down
42 changes: 19 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ classifiers = [
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Testing",
]
dependencies = [
Expand All @@ -52,21 +52,36 @@ tox_to_nox = [
"jinja2",
"tox<4",
]

[project.urls]
bug-tracker = "https://github.com/wntrblm/nox/issues"
documentation = "https://nox.thea.codes"
homepage = "https://github.com/wntrblm/nox"
repository = "https://github.com/wntrblm/nox"

[project.scripts]
nox = "nox.__main__:main"
tox-to-nox = "nox.tox_to_nox:main"


[tool.hatch]
metadata.allow-ambiguous-features = true # disable normalization (tox-to-nox) for back-compat

[tool.ruff]
target-version = "py37"

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"C4", # flake8-comprehensions
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"UP", # pyupgrade
"YTT", # flake8-2020
]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [ "-ra", "--strict-markers", "--strict-config" ]
Expand All @@ -93,22 +108,3 @@ enable_error_code = [ "ignore-without-code", "redundant-expr", "truthy-bool" ]
[[tool.mypy.overrides]]
module = [ "argcomplete", "colorlog.*", "py", "tox.*" ]
ignore_missing_imports = true

[tool.ruff]
select = [
"E", "F", "W", # flake8
"B", "B904", # flake8-bugbear
"I", # isort
"C4", # flake8-comprehensions
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"UP", # pyupgrade
"YTT", # flake8-2020
]
extend-ignore = ["E501"]
target-version = "py37"
exclude = []
42 changes: 14 additions & 28 deletions tests/test__version.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,32 @@ 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 @@ -102,36 +94,30 @@ 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))
10 changes: 4 additions & 6 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_no_bin_paths(self):
with pytest.raises(
ValueError, match=r"^The environment does not have a bin directory\.$"
):
session.bin
session.bin # noqa: B018
assert session.bin_paths is None

def test_virtualenv_as_none(self):
Expand Down Expand Up @@ -799,7 +799,7 @@ def test___slots__(self):
with pytest.raises(AttributeError):
session.foo = "bar"
with pytest.raises(AttributeError):
session.quux
session.quux # noqa: B018

def test___dict__(self):
session, _ = self.make_session_and_runner()
Expand Down Expand Up @@ -1057,10 +1057,8 @@ def func(session):
session.run(
sys.executable,
"-c",
(
"import os; raise SystemExit(0 if"
f' os.environ["NOX_CURRENT_SESSION"] == {session.name!r} else 0)'
),
"import os; raise SystemExit(0 if"
f' os.environ["NOX_CURRENT_SESSION"] == {session.name!r} else 0)',
)

runner.func = func
Expand Down
12 changes: 4 additions & 8 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,22 @@ 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 b6e626b

Please sign in to comment.