Skip to content

Commit

Permalink
Update ruff to 0.8.4
Browse files Browse the repository at this point in the history
This introduces some new checks that are fixed
in this commit as well.

* pyproject.toml : Update ruff to 0.8.4
* poetry.lock : Automatic update.
* .pre-commit-config.yaml : Sync ruff version with `poetry.lock`
* run ruff on code base
  • Loading branch information
real-yfprojects committed Jan 1, 2025
1 parent e58db92 commit 623a2c8
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repos:

# Lint python code with ruff (also sorts imports)
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "bbaf495f2dc6ce2853c91dc0b2c75d3b8249c15c" # frozen: v0.1.15
rev: "f0b5944bef86f50d875305821a0ab0d8c601e465" # frozen: v0.8.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
41 changes: 21 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sphinx-polyversion = "sphinx_polyversion.main:main"

[tool.poetry.group.lint.dependencies]
mypy = "^1.7.1"
ruff = "^0.1.6"
ruff = "^0.8.4"
black = "^23.11.0"

[tool.poetry.group.test.dependencies]
Expand Down Expand Up @@ -79,7 +79,9 @@ ignore_missing_imports = true

[tool.ruff]
target-version = "py38"
line-length = 88 # Same as Black.

[tool.ruff.lint]
select = [
"T", # flake8-print
"I", # isort
Expand Down Expand Up @@ -126,18 +128,15 @@ ignore = [
"TD002", # missing author
]

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed or of form `dummyN`.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?)|dummy\\d*)$"

# Less strict rules for docs/* and tests/*.
[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"docs/*" = ["PLR", "D1", "PTH", "INP"]
"tests/*" = ["PLR2004"]

[tool.ruff.pylint]
[tool.ruff.lint.pylint]
# Allow more arguments for complexity check
max-args = 8

Expand Down
6 changes: 3 additions & 3 deletions sphinx_polyversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from sphinx_polyversion.json import GLOBAL_DECODER, GLOBAL_ENCODER

__all__ = (
"GLOBAL_DECODER",
"GLOBAL_ENCODER",
"DefaultDriver",
"apply_overrides",
"load",
"order_versions",
"DefaultDriver",
"GLOBAL_DECODER",
"GLOBAL_ENCODER",
)

logger = getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion sphinx_polyversion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sphinx_polyversion.json import GLOBAL_DECODER
from sphinx_polyversion.main import get_parser

__all__ = ["load", "apply_overrides"]
__all__ = ["apply_overrides", "load"]


class LoadError(RuntimeError):
Expand Down
4 changes: 2 additions & 2 deletions sphinx_polyversion/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
StrPath = Union[str, PathLike[str]]


__all__ = ["Driver", "DefaultDriver"]
__all__ = ["DefaultDriver", "Driver"]


EXC_INFO = Tuple[Type[BaseException], BaseException, TracebackType]
Expand Down Expand Up @@ -508,7 +508,7 @@ def __init__(
self.encoder = encoder or GLOBAL_ENCODER
self.root_data_factory = root_data_factory

if isinstance(builder, dict) or isinstance(env, dict) and not selector:
if isinstance(builder, dict) or (isinstance(env, dict) and not selector):
raise ValueError(
"Must provide selector if a mapping is passed for `builder` or `env`."
)
Expand Down
2 changes: 1 addition & 1 deletion sphinx_polyversion/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from sphinx_polyversion.utils import async_all
from sphinx_polyversion.vcs import VersionProvider

__all__ = ["GitRef", "GitRefType", "Git", "file_predicate", "refs_by_type"]
__all__ = ["Git", "GitRef", "GitRefType", "file_predicate", "refs_by_type"]

logger = getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions sphinx_polyversion/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
runtime_checkable,
)

__all__ = ["Encoder", "Decoder", "RecursionWarning", "std_hook"]
__all__ = ["Decoder", "Encoder", "RecursionWarning", "std_hook"]


#: Python types representing a key in JSON mapping
Expand Down Expand Up @@ -226,7 +226,7 @@ def transform(self, o: JSONable) -> JSON_TYPE_DUMP:
if hasattr(o, "_json_fields"):
# type JSONable
fields = o._json_fields() # type: ignore
if t := type(o) == type(fields):
if t := type(o) is type(fields):
warnings.warn(
f"Class {t} returns itself as json field container",
RecursionWarning,
Expand Down Expand Up @@ -500,7 +500,7 @@ def fields(o: Any) -> None | JSONable:
"""

@staticmethod
def from_json(cls: str, o: JSON_TYPE) -> Any:
def from_json(cls: str, o: JSON_TYPE) -> Any: # noqa: PLW0211
"""
Instanciate an object from its fields.
Expand Down Expand Up @@ -550,7 +550,7 @@ def fields(o: Any) -> str | None:
return None

@staticmethod
def from_json(cls: str, o: JSON_TYPE) -> Any:
def from_json(cls: str, o: JSON_TYPE) -> Any: # noqa: PLW0211
"""Decode an object."""
o = cast(str, o)
return datetime.fromisoformat(o)
26 changes: 13 additions & 13 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def no_git_env(_env: Mapping[str, str] | None = None) -> dict[str, str]:
}


@pytest.fixture()
@pytest.fixture
def git_testrepo(tmp_path: Path) -> Tuple[Path, List[GitRef]]:
"""Create a git repository for testing."""
git = ("git", *NO_FS_MONITOR)
Expand Down Expand Up @@ -162,13 +162,13 @@ def run_git(*args: str) -> None:
return tmp_path, refs


@pytest.fixture()
@pytest.fixture
def git() -> Git:
"""Create a `Git` instance for testing."""
return Git(branch_regex=".*", tag_regex=".*")


@pytest.fixture()
@pytest.fixture
def git_with_predicate() -> Git:
"""Create a `Git` instance with a predicate for testing."""

Expand All @@ -182,13 +182,13 @@ async def predicate(root: Path, ref: GitRef) -> bool:
)


@pytest.fixture()
@pytest.fixture
def git_with_buffer_size() -> Git:
"""Create a `Git` instance with a buffer size for testing."""
return Git(branch_regex=".*", tag_regex=".*", buffer_size=1024)


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_aroot(git: Git, git_testrepo: Tuple[Path, List[GitRef]]):
"""Test the `aroot` method."""
repo_path, _ = git_testrepo
Expand All @@ -199,7 +199,7 @@ async def test_aroot(git: Git, git_testrepo: Tuple[Path, List[GitRef]]):
assert root == repo_path


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_checkout(
git: Git,
git_testrepo: Tuple[Path, List[GitRef]],
Expand All @@ -211,7 +211,7 @@ async def test_checkout(
assert (tmp_path / "test.txt").read_text() == "test"


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_checkout_with_buffer(
git_with_buffer_size: Git,
git_testrepo: Tuple[Path, List[GitRef]],
Expand All @@ -223,7 +223,7 @@ async def test_checkout_with_buffer(
assert (tmp_path / "test.txt").read_text() == "test"


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_predicate(git_with_predicate: Git):
"""Test the `predicate` method."""
root = "."
Expand All @@ -248,7 +248,7 @@ def compare_refs(ref1: GitRef, ref2: GitRef) -> bool:
)


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_retrieve(git: Git, git_testrepo: Tuple[Path, List[GitRef]]):
"""Test the `retrieve` method."""
root, git_refs = git_testrepo
Expand All @@ -259,7 +259,7 @@ async def test_retrieve(git: Git, git_testrepo: Tuple[Path, List[GitRef]]):
assert compare_refs(ref1, ref2)


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_retrieve_with_predicate(
git_with_predicate: Git, git_testrepo: Tuple[Path, List[GitRef]]
):
Expand All @@ -271,7 +271,7 @@ async def test_retrieve_with_predicate(
assert compare_refs(refs[1], git_refs[3])


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_closest_tag(git_testrepo: Tuple[Path, List[GitRef]]):
"""Test the `closest_tag` method."""
root, git_refs = git_testrepo
Expand All @@ -296,7 +296,7 @@ async def test_closest_tag(git_testrepo: Tuple[Path, List[GitRef]]):
assert await closest_tag(root, git_refs[0], ["1.0", "2.0"]) is None


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_file_exists(git_testrepo: Tuple[Path, List[GitRef]]):
"""Test the `file_exists` method."""
root, git_refs = git_testrepo
Expand All @@ -313,7 +313,7 @@ async def test_file_exists(git_testrepo: Tuple[Path, List[GitRef]]):
assert not await file_exists(root, git_refs[1], Path("dir3"))


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_file_predicate(git_testrepo: Tuple[Path, List[GitRef]]):
"""Test the `file_exists` method."""
root, git_refs = git_testrepo
Expand Down
Loading

0 comments on commit 623a2c8

Please sign in to comment.