From cb8fd38ef4c4189142702951b89dee1f09e4d71f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 10 Mar 2024 10:46:07 +0100 Subject: [PATCH] =?UTF-8?q?pyupgrade/black/isort/flake8=20=E2=86=92=20ruff?= =?UTF-8?q?=20(#769)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flake8 | 3 --- .pre-commit-config.yaml | 27 +++++------------------- pyproject.toml | 42 ++++++++++++++++++++++++++++++++++--- src/packaging/markers.py | 3 ++- src/packaging/metadata.py | 5 +++-- src/packaging/specifiers.py | 6 ------ src/packaging/version.py | 2 -- 7 files changed, 49 insertions(+), 39 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b5a35be9..00000000 --- a/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 88 -ignore = E203,W503,W504 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c03c4d43..8dc94e9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 9fa0fb17..f115bb75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", +] diff --git a/src/packaging/markers.py b/src/packaging/markers.py index 8b98fca7..c96d22a5 100644 --- a/src/packaging/markers.py +++ b/src/packaging/markers.py @@ -14,6 +14,8 @@ Op, Value, Variable, +) +from ._parser import ( parse_marker as _parse_marker, ) from ._tokenizer import ParserSyntaxError @@ -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 diff --git a/src/packaging/metadata.py b/src/packaging/metadata.py index fb274930..80f46d19 100644 --- a/src/packaging/metadata.py +++ b/src/packaging/metadata.py @@ -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 @@ -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, diff --git a/src/packaging/specifiers.py b/src/packaging/specifiers.py index 2d015bab..6d4066ae 100644 --- a/src/packaging/specifiers.py +++ b/src/packaging/specifiers.py @@ -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 @@ -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. @@ -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) @@ -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) diff --git a/src/packaging/version.py b/src/packaging/version.py index 5faab9bd..cda8e999 100644 --- a/src/packaging/version.py +++ b/src/packaging/version.py @@ -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. @@ -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