From 82826eba6d9461d3f9ab6209399bd2e9cee3ffea Mon Sep 17 00:00:00 2001 From: vvanglro Date: Wed, 1 Nov 2023 15:17:46 +0800 Subject: [PATCH 1/3] feat: use ruff-format replace black --- .pre-commit-config.yaml | 8 ++------ install-pdm.py | 5 +++-- pyproject.toml | 4 ---- src/pdm/compat.py | 3 +-- src/pdm/formats/poetry.py | 3 ++- src/pdm/models/candidates.py | 4 +++- src/pdm/models/repositories.py | 8 ++++---- tests/cli/test_install.py | 4 +--- tests/cli/test_use.py | 4 +--- 9 files changed, 17 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 941fb3a412..31adea5fd1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,11 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.292' + rev: 'v0.1.3' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] - - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black + - id: ruff-format - repo: https://github.com/codespell-project/codespell rev: v2.2.6 diff --git a/install-pdm.py b/install-pdm.py index c4fc2351c1..0ff071231e 100644 --- a/install-pdm.py +++ b/install-pdm.py @@ -137,8 +137,9 @@ def _add_to_path(target: Path) -> None: winreg.SetValueEx(env_key, "PATH", 0, type_, new_value) _echo( - "Post-install: {} is added to PATH env, please restart your terminal " - "to take effect".format(colored("green", value)) + "Post-install: {} is added to PATH env, please restart your terminal " "to take effect".format( + colored("green", value) + ) ) else: paths = [os.path.normcase(p) for p in os.getenv("PATH", "").split(os.pathsep)] diff --git a/pyproject.toml b/pyproject.toml index 7bf228eb89..e00c8b77eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,10 +125,6 @@ workflow = [ "pycomplete~=0.3" ] -[tool.black] -line-length = 120 -target-version = ["py37", "py38", "py39", "py310"] - [tool.ruff] line-length = 120 extend-select = [ diff --git a/src/pdm/compat.py b/src/pdm/compat.py index 1b8b0d6f87..0b6799076a 100644 --- a/src/pdm/compat.py +++ b/src/pdm/compat.py @@ -10,8 +10,7 @@ if ( - sys.version_info >= (3, 9) - and not (sys.version_info[:2] == (3, 9) and sys.platform == "win32") + sys.version_info >= (3, 9) and not (sys.version_info[:2] == (3, 9) and sys.platform == "win32") # a bug on windows+py39 that zipfile path is not normalized ): diff --git a/src/pdm/formats/poetry.py b/src/pdm/formats/poetry.py index 79a4d6157b..1dc8d2fa33 100644 --- a/src/pdm/formats/poetry.py +++ b/src/pdm/formats/poetry.py @@ -87,7 +87,8 @@ def _convert_req(name: str, req_dict: RequirementDict | list[RequirementDict]) - req_dict["marker"] = str(functools.reduce(operator.and_, markers)).replace('"', "'") if "rev" in req_dict or "branch" in req_dict or "tag" in req_dict: req_dict["ref"] = req_dict.pop( - "rev", req_dict.pop("tag", req_dict.pop("branch", None)) # type: ignore[arg-type] + "rev", + req_dict.pop("tag", req_dict.pop("branch", None)), # type: ignore[arg-type] ) yield Requirement.from_req_dict(name, req_dict).as_line() diff --git a/src/pdm/models/candidates.py b/src/pdm/models/candidates.py index 548ff106b2..513a727187 100644 --- a/src/pdm/models/candidates.py +++ b/src/pdm/models/candidates.py @@ -601,7 +601,9 @@ def get_dependencies_from_metadata(self) -> list[str]: """Get the dependencies of a candidate from metadata.""" extras = self.req.extras or () return filter_requirements_with_extras( - self.req.project_name, self.metadata.requires or [], extras # type: ignore[arg-type] + self.req.project_name, + self.metadata.requires or [], + extras, # type: ignore[arg-type] ) def should_cache(self) -> bool: diff --git a/src/pdm/models/repositories.py b/src/pdm/models/repositories.py index 6a2853344f..bb0c6e880a 100644 --- a/src/pdm/models/repositories.py +++ b/src/pdm/models/repositories.py @@ -234,7 +234,9 @@ def python_specifier(spec: str | PySpecSet) -> str: if not applicable_cans and allow_prereleases is None: # No non-pre-releases is found, force pre-releases now applicable_cans = LazySequence( - c for c in cans if requirement.specifier.contains(c.version, True) # type: ignore[arg-type, union-attr] + c + for c in cans + if requirement.specifier.contains(c.version, True) # type: ignore[arg-type, union-attr] ) applicable_cans_python_compatible = LazySequence(filter_candidates_with_requires_python(applicable_cans)) if applicable_cans_python_compatible: @@ -342,9 +344,7 @@ def get_hashes(self, candidate: Candidate) -> list[FileHash]: of a given package version. """ if ( - candidate.req.is_vcs - or candidate.req.is_file_or_url - and candidate.req.is_local_dir # type: ignore[attr-defined] + candidate.req.is_vcs or candidate.req.is_file_or_url and candidate.req.is_local_dir # type: ignore[attr-defined] ): return [] if candidate.hashes: diff --git a/tests/cli/test_install.py b/tests/cli/test_install.py index fd2f7d59a4..853b065923 100644 --- a/tests/cli/test_install.py +++ b/tests/cli/test_install.py @@ -110,9 +110,7 @@ def test_sync_with_index_change(project, index, pdm): project.pyproject.metadata["requires-python"] = ">=3.6" project.pyproject.metadata["dependencies"] = ["future-fstrings"] project.pyproject.write() - index[ - "/simple/future-fstrings/" - ] = b""" + index["/simple/future-fstrings/"] = b"""

future-fstrings

diff --git a/tests/cli/test_use.py b/tests/cli/test_use.py index 05316b7c88..ae75c2b43b 100644 --- a/tests/cli/test_use.py +++ b/tests/cli/test_use.py @@ -35,9 +35,7 @@ def test_use_python_by_version(project, pdm): def test_use_wrapper_python(project): wrapper_script = """#!/bin/bash exec "{}" "$@" -""".format( - sys.executable - ) +""".format(sys.executable) shim_path = project.root.joinpath("python_shim.sh") shim_path.write_text(wrapper_script) shim_path.chmod(0o755) From 88c4e9ccb09456eeba2b0a047eafb5af900d8871 Mon Sep 17 00:00:00 2001 From: vvanglro Date: Wed, 1 Nov 2023 15:28:33 +0800 Subject: [PATCH 2/3] fix: mypy arg-type --- src/pdm/models/candidates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pdm/models/candidates.py b/src/pdm/models/candidates.py index 513a727187..bd7213bb03 100644 --- a/src/pdm/models/candidates.py +++ b/src/pdm/models/candidates.py @@ -601,9 +601,9 @@ def get_dependencies_from_metadata(self) -> list[str]: """Get the dependencies of a candidate from metadata.""" extras = self.req.extras or () return filter_requirements_with_extras( - self.req.project_name, + self.req.project_name, # type: ignore[arg-type] self.metadata.requires or [], - extras, # type: ignore[arg-type] + extras, ) def should_cache(self) -> bool: From 63037bd3adca4ea0d31a9f3e138758768e0ce0cb Mon Sep 17 00:00:00 2001 From: vvanglro Date: Wed, 1 Nov 2023 15:35:29 +0800 Subject: [PATCH 3/3] fix: prompts style --- install-pdm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-pdm.py b/install-pdm.py index 0ff071231e..b13827592c 100644 --- a/install-pdm.py +++ b/install-pdm.py @@ -137,7 +137,7 @@ def _add_to_path(target: Path) -> None: winreg.SetValueEx(env_key, "PATH", 0, type_, new_value) _echo( - "Post-install: {} is added to PATH env, please restart your terminal " "to take effect".format( + "Post-install: {} is added to PATH env, please restart your terminal to take effect".format( colored("green", value) ) )