Skip to content

Commit

Permalink
Replace black, isort, and some flake8 plugins with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 17, 2024
1 parent 93d93c5 commit 68460fd
Show file tree
Hide file tree
Showing 10 changed files with 789 additions and 861 deletions.
6 changes: 2 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[flake8]
select = B,B9,C,D,DAR,E,F,N,RST,S,W
ignore = E203,E501,RST201,RST203,RST301,W503
select = D,DAR,RST
ignore = RST201,RST203,RST301
max-line-length = 80
max-complexity = 10
docstring-convention = google
per-file-ignores = tests/*:S101
rst-roles = class,const,func,meth,mod,ref
rst-directives = deprecated
28 changes: 10 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
- id: ruff
name: ruff check
entry: ruff check
require_serial: true
language: system
types: [python]
types_or: [pyi, python]
- id: ruff-format
name: ruff format
entry: ruff format
require_serial: true
language: system
types_or: [pyi, python]
- id: check-added-large-files
name: Check for added large files
entry: check-added-large-files
Expand Down Expand Up @@ -40,26 +46,12 @@ repos:
types: [python]
require_serial: true
args: [--darglint-ignore-regex, .*]
- id: isort
name: isort
entry: isort
require_serial: true
language: system
types_or: [cython, pyi, python]
args: ["--filter-files"]
- id: trailing-whitespace
name: Trim Trailing Whitespace
entry: trailing-whitespace-fixer
language: system
types: [text]
stages: [commit, push, manual]
- id: pyupgrade
name: pyupgrade
description: Automatically upgrade syntax for newer versions.
entry: pyupgrade
language: system
types: [python]
args: [--py37-plus]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
Expand Down
12 changes: 5 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,13 @@ def precommit(session: Session) -> None:
"--show-diff-on-failure",
]
session.install(
"black",
"darglint",
"flake8",
"flake8-bandit",
"flake8-bugbear",
"flake8-docstrings",
"flake8-rst-docstrings",
"isort",
"pep8-naming",
"pre-commit",
"pre-commit-hooks",
"pyupgrade",
"ruff",
)
session.run("pre-commit", *args)
if args and args[0] == "install":
Expand Down Expand Up @@ -168,7 +163,10 @@ def mypy(session: Session) -> None:
@session
@nox.parametrize(
"python,poetry",
[(python_versions[0], "1.6.1"), *((python, None) for python in python_versions)],
[
(python_versions[0], "1.6.1"),
*((python, None) for python in python_versions),
],
)
def tests(session: Session, poetry: Optional[str]) -> None:
"""Run the test suite."""
Expand Down
1,530 changes: 735 additions & 795 deletions poetry.lock

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ nox = ">=2020.8.22"
tomlkit = ">=0.7"
packaging = ">=20.9"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = ">=6.2.5"
coverage = {extras = ["toml"], version = ">=6.3"}
safety = ">=1.10.3"
Expand All @@ -32,12 +32,8 @@ sphinx = ">=4.3.2"
sphinx-autobuild = ">=2021.3.14"
pre-commit = ">=2.17.0"
flake8 = ">=4.0.1"
black = ">=22.3"
flake8-bandit = ">=2.1.2"
flake8-bugbear = ">=22.1.11"
flake8-docstrings = ">=1.6.0"
flake8-rst-docstrings = ">=0.2.5"
pep8-naming = ">=0.12.1"
# TODO: The 'python < 4' constraint is a workaround to allow poetry to
# generate a lock file. Hopefully there's an alternative to darglint
# before Python 4 is released.
Expand All @@ -49,9 +45,8 @@ Pygments = ">=2.11.2"
poetry = {version=">=1.1.12", python="<4"}
pytest-datadir = ">=1.3.1"
typing-extensions = ">=4.0.1"
pyupgrade = ">=2.31.0"
isort = ">=5.10.1"
myst-parser = ">=0.16.1"
ruff = ">=0.6.5"

[tool.coverage.paths]
source = ["src", "*/site-packages"]
Expand All @@ -64,10 +59,29 @@ source = ["nox_poetry"]
show_missing = true
fail_under = 100

[tool.isort]
profile = "black"
force_single_line = true
lines_after_imports = 2
[tool.ruff]
line-length = 88
target-version = "py38"

[tool.ruff.lint]
select = [
"F", # Pyflakes
"E", # pycodestyle (error)
"W", # pycodestyle (warning)
"C90", # mccabe
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"S", # flake8-bandit
"B", # flake8-bugbear
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["B018", "S101", "S607"]

[tool.ruff.lint.isort]
force-single-line = true
lines-after-imports = 2

[tool.mypy]
strict = true
Expand Down
7 changes: 6 additions & 1 deletion src/nox_poetry/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ def installroot(
# as success; this means that the package was not in the wheel cache.
name = self.poetry.config.name
self.session.run_always(
"pip", "cache", "remove", name, success_codes=[0, 1], silent=True
"pip",
"cache",
"remove",
name,
success_codes=[0, 1],
silent=True,
)

self.session.install(f"--constraint={requirements}", package)
Expand Down
13 changes: 3 additions & 10 deletions src/nox_poetry/sessions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Iterable
from typing import List
from typing import Mapping
from typing import NoReturn
from typing import Optional
from typing import Sequence
from typing import TypeVar
from typing import Union
from typing import overload

import nox.sessions
import nox.virtualenv

Python = Optional[Union[str, Sequence[str], bool]]
Python = str | Sequence[str] | bool | None

class _PoetrySession:
def install(self, *args: str, **kwargs: Any) -> None: ...
Expand All @@ -41,8 +34,8 @@ def session(
__func: None = ...,
python: Python = ...,
py: Python = ...,
reuse_venv: Optional[bool] = ...,
name: Optional[str] = ...,
reuse_venv: bool | None = ...,
name: str | None = ...,
venv_backend: Any = ...,
venv_params: Any = ...,
tags: Sequence[str] = ...,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_dependency(self, name: str, data: Any = None) -> Package:
if package["name"] == name:
url = package.get("source", {}).get("url")
if url is not None:
# Abuse Package.version to store the URL (for ``list_packages``).
# Abuse Package.version to store the URL (for ``list_packages``). # noqa: E501
return Package(name, url)
return Package(name, package["version"])
raise ValueError(f"{name}: package not found")
Expand Down
8 changes: 1 addition & 7 deletions tests/functional/test_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functional tests for the `@session` decorator."""

import sys
from importlib.metadata import version
from pathlib import Path

import nox.sessions
Expand All @@ -13,12 +13,6 @@
from tests.functional.conftest import run_nox_with_noxfile


if sys.version_info >= (3, 8):
from importlib.metadata import version
else:
from importlib_metadata import version


def test_local(project: Project) -> None:
"""It installs the local package."""

Expand Down
8 changes: 1 addition & 7 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
"""Fixtures."""

import sys
from pathlib import Path
from typing import Any
from typing import Optional
from typing import Protocol
from typing import cast


if sys.version_info >= (3, 8):
from typing import Protocol
else:
from typing_extensions import Protocol

import pytest
from nox.sessions import Session

Expand Down

0 comments on commit 68460fd

Please sign in to comment.