Skip to content

Commit

Permalink
Migrate to ruff, add pathlib support to the API. (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR authored Feb 24, 2025
1 parent d616fcf commit 0758742
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 195 deletions.
6 changes: 0 additions & 6 deletions .bandit.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .bumpversion.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

16 changes: 0 additions & 16 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
tox
- name: Upload coverage report
run: bash <(curl -s https://codecov.io/bash)
uses: codecov/codecov-action@v5
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

21 changes: 5 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
hooks:
- id: bandit
args: [-r, -c, .bandit.yml]
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/psf/black.git
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- id: ruff
args: [ --fix ]
- id: ruff-format
21 changes: 0 additions & 21 deletions pylintrc

This file was deleted.

159 changes: 149 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,156 @@
[tool.isort]
profile = "black"
multi_line_output = 3
[tool.bumpversion]
current_version = "1.7.0"
commit = true
tag = true
tag_name = "v{new_version}"

[tool.mypy]
check_untyped_defs = true
ignore_missing_imports = true
no_warn_no_return = true
[[tool.bumpversion.files]]
filename = "setup.py"

[[tool.bumpversion.files]]
filename = "queuelib/__init__.py"

[tool.coverage.run]
branch = true
omit = [
"queuelib/tests/*",
]

[[tool.mypy.overrides]]
module = "queuelib.tests.*"
allow_untyped_defs = true
allow_untyped_calls = true
check_untyped_defs = false

[tool.black]
target-version = ["py38", "py39", "py310", "py311", "py312"]
[tool.pylint.MASTER]
persistent = "no"

[tool.pylint."MESSAGES CONTROL"]
enable = [
"useless-suppression",
]
disable = [
"consider-using-with",
"duplicate-code",
"invalid-name",
"line-too-long",
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"too-few-public-methods",
"unspecified-encoding",
]

[tool.ruff.lint]
extend-select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# pydocstyle
"D",
# flake8-future-annotations
"FA",
# flynt
"FLY",
# refurb
"FURB",
# isort
"I",
# flake8-implicit-str-concat
"ISC",
# flake8-logging
"LOG",
# Perflint
"PERF",
# pygrep-hooks
"PGH",
# flake8-pie
"PIE",
# pylint
"PL",
# flake8-use-pathlib
"PTH",
# flake8-pyi
"PYI",
# flake8-quotes
"Q",
# flake8-return
"RET",
# flake8-raise
"RSE",
# Ruff-specific rules
"RUF",
# flake8-bandit
"S",
# flake8-simplify
"SIM",
# flake8-slots
"SLOT",
# flake8-debugger
"T10",
# flake8-type-checking
"TC",
# pyupgrade
"UP",
# pycodestyle warnings
"W",
# flake8-2020
"YTT",
]
ignore = [
# Missing docstring in public module
"D100",
# Missing docstring in public class
"D101",
# Missing docstring in public method
"D102",
# Missing docstring in public function
"D103",
# Missing docstring in public package
"D104",
# Missing docstring in magic method
"D105",
# Missing docstring in public nested class
"D106",
# Missing docstring in __init__
"D107",
# One-line docstring should fit on one line with quotes
"D200",
# No blank lines allowed after function docstring
"D202",
# 1 blank line required between summary line and description
"D205",
# Multi-line docstring closing quotes should be on a separate line
"D209",
# First line should end with a period
"D400",
# First line should be in imperative mood; try rephrasing
"D401",
# First line should not be the function's "signature"
"D402",
# First word of the first line should be properly capitalized
"D403",
# Too many return statements
"PLR0911",
# Too many branches
"PLR0912",
# Too many arguments in function definition
"PLR0913",
# Too many statements
"PLR0915",
# Magic value used in comparison
"PLR2004",
# String contains ambiguous {}.
"RUF001",
# Docstring contains ambiguous {}.
"RUF002",
# Comment contains ambiguous {}.
"RUF003",
# Mutable class attributes should be annotated with `typing.ClassVar`
"RUF012",
# Use of `assert` detected
"S101",
]

[tool.ruff.lint.pydocstyle]
convention = "pep257"
7 changes: 7 additions & 0 deletions queuelib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
from queuelib.pqueue import PriorityQueue
from queuelib.queue import FifoDiskQueue, LifoDiskQueue
from queuelib.rrqueue import RoundRobinQueue

__all__ = [
"FifoDiskQueue",
"LifoDiskQueue",
"PriorityQueue",
"RoundRobinQueue",
]
15 changes: 10 additions & 5 deletions queuelib/pqueue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Any, Callable, Iterable, List, Optional
from __future__ import annotations

from queuelib.queue import BaseQueue
from typing import TYPE_CHECKING, Any, Callable

if TYPE_CHECKING:
from collections.abc import Iterable

from queuelib.queue import BaseQueue


class PriorityQueue:
Expand Down Expand Up @@ -44,7 +49,7 @@ def push(self, obj: Any, priority: int = 0) -> None:
if self.curprio is None or priority < self.curprio:
self.curprio = priority

def pop(self) -> Optional[Any]:
def pop(self) -> Any | None:
if self.curprio is None:
return None
q = self.queues[self.curprio]
Expand All @@ -56,12 +61,12 @@ def pop(self) -> Optional[Any]:
self.curprio = min(prios) if prios else None
return m

def peek(self) -> Optional[Any]:
def peek(self) -> Any | None:
if self.curprio is None:
return None
return self.queues[self.curprio].peek()

def close(self) -> List[int]:
def close(self) -> list[int]:
active = []
for p, q in self.queues.items():
if len(q):
Expand Down
Loading

0 comments on commit 0758742

Please sign in to comment.