From b5a74c6d28a0e97abb2c8d83151a831bc14abcde Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:23:19 +0100 Subject: [PATCH 1/4] =?UTF-8?q?pyupgrade/black/isort/flake8=20=E2=86=92=20?= =?UTF-8?q?ruff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flake8 | 3 --- .pre-commit-config.yaml | 27 +++++---------------------- .ruff.toml | 31 +++++++++++++++++++++++++++++++ pyproject.toml | 5 ----- src/packaging/metadata.py | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) delete mode 100644 .flake8 create mode 100644 .ruff.toml 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/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000..a25fb575 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,31 @@ +src = ["src"] +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", +] +# according to the documentation, should not be needed with: +# requires-python = ">=3.7" +target-version = "py37" diff --git a/pyproject.toml b/pyproject.toml index 9fa0fb17..3c10eefe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,8 +55,3 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [[tool.mypy.overrides]] module = ["_manylinux"] ignore_missing_imports = true - - -[tool.isort] -profile = "black" -combine_as_imports = true diff --git a/src/packaging/metadata.py b/src/packaging/metadata.py index fb274930..6912cdb7 100644 --- a/src/packaging/metadata.py +++ b/src/packaging/metadata.py @@ -44,7 +44,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, From 10c6d2887499aa743590420e5b61c563b1acce44 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:24:22 +0100 Subject: [PATCH 2/4] Run ruff linter on existing code --- src/packaging/markers.py | 2 ++ src/packaging/metadata.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/packaging/markers.py b/src/packaging/markers.py index 8b98fca7..169493d3 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 diff --git a/src/packaging/metadata.py b/src/packaging/metadata.py index 6912cdb7..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 From f741ccee0f05619c55d79b0cadbb1265338ce310 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:25:23 +0100 Subject: [PATCH 3/4] Run ruff formatter on existing code --- src/packaging/markers.py | 1 - src/packaging/specifiers.py | 6 ------ src/packaging/version.py | 2 -- 3 files changed, 9 deletions(-) diff --git a/src/packaging/markers.py b/src/packaging/markers.py index 169493d3..c96d22a5 100644 --- a/src/packaging/markers.py +++ b/src/packaging/markers.py @@ -71,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/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 From 2d9e1b074bbee755fd12483f0a7cd22209f0a8c6 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:07:32 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Apply=20review=20suggestion:=20.flake8=20?= =?UTF-8?q?=E2=86=92=20.ruff.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ruff.toml | 31 ------------------------------- pyproject.toml | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 31 deletions(-) delete mode 100644 .ruff.toml diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index a25fb575..00000000 --- a/.ruff.toml +++ /dev/null @@ -1,31 +0,0 @@ -src = ["src"] -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", -] -# according to the documentation, should not be needed with: -# requires-python = ">=3.7" -target-version = "py37" diff --git a/pyproject.toml b/pyproject.toml index 3c10eefe..f115bb75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,3 +55,44 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [[tool.mypy.overrides]] module = ["_manylinux"] ignore_missing_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", +]