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

chore: move to using Ruff #691

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ruff's implementation is smarter than a simple grep, so it can tell session.warn isn't logging's warn! :)

- 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