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

pyupgrade/black/isort/flake8 → ruff #769

Merged
merged 5 commits into from
Mar 10, 2024
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
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

27 changes: 5 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,9 @@ repos:
args: []
additional_dependencies: [pyparsing, nox]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: "6.0.0"
hooks:
- id: flake8
additional_dependencies: ["pep8-naming"]
# Ignore all format-related checks as Black takes care of those.
args: ["--ignore", "E2,W5", "--select", "E,W,F,N"]
- id: ruff
args: [ --fix ]
- id: ruff-format
42 changes: 39 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,42 @@ module = ["_manylinux"]
ignore_missing_imports = true


[tool.isort]
profile = "black"
combine_as_imports = true
[tool.ruff]
src = ["src"]

[tool.ruff.lint]
extend-select = [
"B",
"E",
"F",
"I",
"N",
"UP",
"W"
]
ignore = [
"B009",
"B015",
"B018",
"B027",
"B028",
"B904",
"N818",
"UP032",
"UP030",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]
3 changes: 2 additions & 1 deletion src/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
Op,
Value,
Variable,
)
from ._parser import (
parse_marker as _parse_marker,
)
from ._tokenizer import ParserSyntaxError
Expand Down Expand Up @@ -69,7 +71,6 @@ def _normalize_extra_values(results: Any) -> Any:
def _format_marker(
marker: Union[List[str], MarkerAtom, str], first: Optional[bool] = True
) -> str:

assert isinstance(marker, (list, tuple, str))

# Sometimes we have a structure like [[...]] which is a single item list
Expand Down
5 changes: 3 additions & 2 deletions src/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
cast,
)

from . import requirements, specifiers, utils, version as version_module
from . import requirements, specifiers, utils
from . import version as version_module

T = typing.TypeVar("T")
if sys.version_info[:2] >= (3, 8): # pragma: no cover
Expand All @@ -44,7 +45,7 @@ def __init_subclass__(*_args, **_kwargs):
ExceptionGroup
except NameError: # pragma: no cover

class ExceptionGroup(Exception): # noqa: N818
class ExceptionGroup(Exception):
"""A minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.

If :external:exc:`ExceptionGroup` is already defined by Python itself,
Expand Down
6 changes: 0 additions & 6 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def _get_operator(self, op: str) -> CallableOperator:
return operator_callable

def _compare_compatible(self, prospective: Version, spec: str) -> bool:

# Compatible releases have an equivalent combination of >= and ==. That
# is that ~=2.2 is equivalent to >=2.2,==2.*. This allows us to
# implement this in terms of the other specifiers instead of
Expand All @@ -385,7 +384,6 @@ def _compare_compatible(self, prospective: Version, spec: str) -> bool:
)

def _compare_equal(self, prospective: Version, spec: str) -> bool:

# We need special logic to handle prefix matching
if spec.endswith(".*"):
# In the case of prefix matching we want to ignore local segment.
Expand Down Expand Up @@ -429,21 +427,18 @@ def _compare_not_equal(self, prospective: Version, spec: str) -> bool:
return not self._compare_equal(prospective, spec)

def _compare_less_than_equal(self, prospective: Version, spec: str) -> bool:

# NB: Local version identifiers are NOT permitted in the version
# specifier, so local version labels can be universally removed from
# the prospective version.
return Version(prospective.public) <= Version(spec)

def _compare_greater_than_equal(self, prospective: Version, spec: str) -> bool:

# NB: Local version identifiers are NOT permitted in the version
# specifier, so local version labels can be universally removed from
# the prospective version.
return Version(prospective.public) >= Version(spec)

def _compare_less_than(self, prospective: Version, spec_str: str) -> bool:

# Convert our spec to a Version instance, since we'll want to work with
# it as a version.
spec = Version(spec_str)
Expand All @@ -468,7 +463,6 @@ def _compare_less_than(self, prospective: Version, spec_str: str) -> bool:
return True

def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool:

# Convert our spec to a Version instance, since we'll want to work with
# it as a version.
spec = Version(spec_str)
Expand Down
2 changes: 0 additions & 2 deletions src/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ def micro(self) -> int:
def _parse_letter_version(
letter: Optional[str], number: Union[str, bytes, SupportsInt, None]
) -> Optional[Tuple[str, int]]:

if letter:
# We consider there to be an implicit 0 in a pre-release if there is
# not a numeral associated with it.
Expand Down Expand Up @@ -508,7 +507,6 @@ def _cmpkey(
dev: Optional[Tuple[str, int]],
local: Optional[LocalType],
) -> CmpKey:

# When we compare a release version, we want to compare it with all of the
# trailing zeros removed. So we'll use a reverse the list, drop all the now
# leading zeros until we come to something non zero, then take the rest
Expand Down
Loading