Skip to content

Commit

Permalink
chore: move to using Ruff (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Feb 22, 2023
1 parent 593017f commit befe771
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 68 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

42 changes: 5 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,19 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["-a", "from __future__ import annotations"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]

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

- repo: https://github.com/hadialqattan/pycln
rev: v2.1.3
hooks:
- id: pycln
args: [--all]
stages: [manual]

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: &flake8-dependencies
- flake8-bugbear

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.249
hooks:
- id: flake8
exclude: docs/conf.py
additional_dependencies: *flake8-dependencies
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
rev: v1.0.1
hooks:
- id: mypy
files: ^nox/
Expand All @@ -82,13 +55,8 @@ repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-log-warn
exclude: ^tests/test_sessions.py$
- id: python-no-eval
exclude: ^nox/manifest.py$
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
2 changes: 1 addition & 1 deletion nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __str__(self) -> str:
return self.id
else:
call_spec = self.call_spec
args = [f"{k}={call_spec[k]!r}" for k in call_spec.keys()]
args = [f"{k}={call_spec[k]!r}" for k in call_spec]
return ", ".join(args)

__repr__ = __str__
Expand Down
2 changes: 1 addition & 1 deletion nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run(

try:
return_code, output = popen(
[cmd_path] + list(args), silent=silent, env=env, **popen_kws
[cmd_path, *list(args)], silent=silent, env=env, **popen_kws
)

if return_code not in success_codes:
Expand Down
7 changes: 2 additions & 5 deletions nox/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ def __init__(self, keywords: set[str]) -> None:
self._keywords = keywords

def __getitem__(self, variable_name: str) -> bool:
for keyword in self._keywords:
if variable_name in keyword:
return True
return False
return any(variable_name in keyword for keyword in self._keywords)

def __iter__(self) -> Iterator[str]:
return iter(self._keywords)
Expand All @@ -347,7 +344,7 @@ def __len__(self) -> int:
def keyword_match(expression: str, keywords: Iterable[str]) -> Any:
"""See if an expression matches the given set of keywords."""
locals = KeywordLocals(set(keywords))
return eval(expression, {}, locals)
return eval(expression, {}, locals) # noqa: PGH001


def _null_session_func_(session: Session) -> None:
Expand Down
7 changes: 2 additions & 5 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(

if self.bin_paths:
self.env["PATH"] = os.pathsep.join(
self.bin_paths + [self.env.get("PATH", "")]
[*self.bin_paths, self.env.get("PATH", "")]
)

@property
Expand Down Expand Up @@ -264,10 +264,7 @@ def create(self) -> bool:
# Ensure the pip package is installed.
cmd.append("pip")

if self.interpreter:
python_dep = f"python={self.interpreter}"
else:
python_dep = "python"
python_dep = f"python={self.interpreter}" if self.interpreter else "python"
cmd.append(python_dep)

logger.info(f"Creating conda env in {self.location_name} with {python_dep}")
Expand Down
37 changes: 26 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ tox-to-nox = "nox.tox_to_nox:main"
[tool.hatch]
metadata.allow-ambiguous-features = true # disable normalization (tox-to-nox) for back-compat


[tool.isort]
profile = "black"

[tool.coverage.run]
branch = true
omit = [ "nox/_typing.py" ]

[tool.coverage.report]
exclude_lines = [ "pragma: no cover", "if TYPE_CHECKING:", "@overload" ]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [ "-ra", "--strict-markers", "--strict-config" ]
Expand All @@ -86,6 +75,13 @@ filterwarnings = [ "error" ]
log_cli_level = "info"
testpaths = [ "tests" ]

[tool.coverage.run]
branch = true
omit = [ "nox/_typing.py" ]

[tool.coverage.report]
exclude_lines = [ "pragma: no cover", "if TYPE_CHECKING:", "@overload" ]

[tool.mypy]
files = [ "nox/**/*.py", "noxfile.py" ]
python_version = "3.7"
Expand All @@ -97,3 +93,22 @@ 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 = []
2 changes: 1 addition & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_custom_stdout(capsys, tmpdir):


def test_custom_stdout_silent_flag(capsys, tmpdir):
with open(str(tmpdir / "out.txt"), "w+b") as stdout:
with open(str(tmpdir / "out.txt"), "w+b") as stdout: # noqa: SIM117
with pytest.raises(ValueError, match="silent"):
nox.command.run([PYTHON, "-c", 'print("hi")'], stdout=stdout, silent=True)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def my_session(session):
# the session sets "no venv backend" but declares some pythons
my_session.python = ["3.7", "3.8"]
my_session.venv_backend = "none"
my_session.should_warn = dict()
my_session.should_warn = {}

sessions = manifest.make_session("my_session", my_session)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def session_func():

session_func.python = None
session_func.venv_backend = None
session_func.should_warn = dict()
session_func.should_warn = {}
session_func.tags = []


Expand Down

0 comments on commit befe771

Please sign in to comment.