diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5f06add1eb3..35d7aeb3418 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -16,16 +16,12 @@ repos:
- id: trailing-whitespace
exclude: .patch
-- repo: https://github.com/psf/black-pre-commit-mirror
- rev: 23.12.1
- hooks:
- - id: black
-
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.1.9
+ rev: v0.1.13
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
+ - id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
diff --git a/pyproject.toml b/pyproject.toml
index 7496a08ee2c..cd0ab008ba3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -149,6 +149,7 @@ ignore = [
"B020",
"B904", # Ruff enables opinionated warnings by default
"B905", # Ruff enables opinionated warnings by default
+ "ISC001", # Avoid conflict with ruff formatter
]
target-version = "py37"
line-length = 88
diff --git a/src/pip/_internal/cli/base_command.py b/src/pip/_internal/cli/base_command.py
index db9d5cc6624..97fb01807db 100644
--- a/src/pip/_internal/cli/base_command.py
+++ b/src/pip/_internal/cli/base_command.py
@@ -172,7 +172,7 @@ def _main(self, args: List[str]) -> int:
options.cache_dir = None
def intercepts_unhandled_exc(
- run_func: Callable[..., int]
+ run_func: Callable[..., int],
) -> Callable[..., int]:
@functools.wraps(run_func)
def exc_logging_wrapper(*args: Any) -> int:
diff --git a/src/pip/_internal/commands/freeze.py b/src/pip/_internal/commands/freeze.py
index fd9d88a8b01..9c194829c2d 100644
--- a/src/pip/_internal/commands/freeze.py
+++ b/src/pip/_internal/commands/freeze.py
@@ -71,8 +71,9 @@ def add_options(self) -> None:
dest="freeze_all",
action="store_true",
help=(
- "Do not skip these packages in the output:"
- " {}".format(", ".join(_dev_pkgs()))
+ "Do not skip these packages in the output: {}".format(
+ ", ".join(_dev_pkgs())
+ )
),
)
self.cmd_opts.add_option(
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
index e944bb95a50..c8b931b3d81 100644
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
@@ -306,8 +306,8 @@ def run(self, options: Values, args: List[str]) -> int:
options.target_dir = os.path.abspath(options.target_dir)
if (
# fmt: off
- os.path.exists(options.target_dir) and
- not os.path.isdir(options.target_dir)
+ os.path.exists(options.target_dir)
+ and not os.path.isdir(options.target_dir)
# fmt: on
):
raise CommandError(
diff --git a/src/pip/_internal/metadata/_json.py b/src/pip/_internal/metadata/_json.py
index 27362fc726c..8863fcf5bcb 100644
--- a/src/pip/_internal/metadata/_json.py
+++ b/src/pip/_internal/metadata/_json.py
@@ -64,7 +64,8 @@ def sanitise_header(h: Union[Header, str]) -> str:
key = json_name(field)
if multi:
value: Union[str, List[str]] = [
- sanitise_header(v) for v in msg.get_all(field) # type: ignore
+ sanitise_header(v)
+ for v in msg.get_all(field) # type: ignore
]
else:
value = sanitise_header(msg.get(field)) # type: ignore
diff --git a/src/pip/_internal/req/req_uninstall.py b/src/pip/_internal/req/req_uninstall.py
index 707fde1b2b9..6781f42c736 100644
--- a/src/pip/_internal/req/req_uninstall.py
+++ b/src/pip/_internal/req/req_uninstall.py
@@ -38,7 +38,7 @@ def _script_names(
def _unique(
- fn: Callable[..., Generator[Any, None, None]]
+ fn: Callable[..., Generator[Any, None, None]],
) -> Callable[..., Generator[Any, None, None]]:
@functools.wraps(fn)
def unique(*args: Any, **kw: Any) -> Generator[Any, None, None]:
diff --git a/tests/functional/test_build_env.py b/tests/functional/test_build_env.py
index 20cd181be07..0ad6be9237c 100644
--- a/tests/functional/test_build_env.py
+++ b/tests/functional/test_build_env.py
@@ -54,9 +54,7 @@ def run_with_build_env(
with global_tempdir_manager():
build_env = BuildEnvironment()
- """.format(
- scratch=str(script.scratch_path)
- )
+ """.format(scratch=str(script.scratch_path))
)
+ indent(dedent(setup_script_contents), " ")
+ indent(
diff --git a/tests/functional/test_completion.py b/tests/functional/test_completion.py
index 4be033583ca..f1c31b75a17 100644
--- a/tests/functional/test_completion.py
+++ b/tests/functional/test_completion.py
@@ -176,7 +176,7 @@ def test_completion_alone(autocomplete_script: PipTestEnvironment) -> None:
assert (
"ERROR: You must pass --bash or --fish or --powershell or --zsh"
in result.stderr
- ), ("completion alone failed -- " + result.stderr)
+ ), "completion alone failed -- " + result.stderr
def test_completion_for_un_snippet(autocomplete: DoAutocomplete) -> None:
@@ -251,10 +251,7 @@ def test_completion_files_after_option(
), "autocomplete function could not complete
after options in command"
assert not any(
out in res.stdout for out in (os.path.join("REPLAY", ""), "README.txt")
- ), (
- "autocomplete function completed or that "
- "should not be completed"
- )
+ ), "autocomplete function completed or that should not be completed"
if sys.platform != "win32":
return
assert (
diff --git a/tests/functional/test_install_user.py b/tests/functional/test_install_user.py
index 3cae4a467e9..e5faa9178a2 100644
--- a/tests/functional/test_install_user.py
+++ b/tests/functional/test_install_user.py
@@ -135,10 +135,7 @@ def test_install_user_conflict_in_usersite(
dist_info_folder = script.user_site / "INITools-0.1.dist-info"
initools_v3_file = (
# file only in 0.3
- script.base_path
- / script.user_site
- / "initools"
- / "configparser.py"
+ script.base_path / script.user_site / "initools" / "configparser.py"
)
result2.did_create(dist_info_folder)
assert not isfile(initools_v3_file), initools_v3_file
diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py
index afe07cbf3ec..1251619312f 100644
--- a/tests/functional/test_new_resolver.py
+++ b/tests/functional/test_new_resolver.py
@@ -414,9 +414,8 @@ def test_new_resolver_requires_python_error(script: PipTestEnvironment) -> None:
expect_error=True,
)
- message = (
- "Package 'base' requires a different Python: "
- "{}.{}.{} not in '<2'".format(*sys.version_info[:3])
+ message = "Package 'base' requires a different Python: {}.{}.{} not in '<2'".format(
+ *sys.version_info[:3]
)
assert message in result.stderr, str(result)
@@ -1148,9 +1147,8 @@ def test_new_resolver_no_deps_checks_requires_python(
expect_error=True,
)
- message = (
- "Package 'base' requires a different Python: "
- "{}.{}.{} not in '<2'".format(*sys.version_info[:3])
+ message = "Package 'base' requires a different Python: {}.{}.{} not in '<2'".format(
+ *sys.version_info[:3]
)
assert message in result.stderr
diff --git a/tests/lib/server.py b/tests/lib/server.py
index 96ac5930dc9..faeaa66eb1d 100644
--- a/tests/lib/server.py
+++ b/tests/lib/server.py
@@ -48,7 +48,7 @@ def make_environ(self) -> Dict[str, Any]:
def _mock_wsgi_adapter(
- mock: Callable[["WSGIEnvironment", "StartResponse"], "WSGIApplication"]
+ mock: Callable[["WSGIEnvironment", "StartResponse"], "WSGIApplication"],
) -> "WSGIApplication":
"""Uses a mock to record function arguments and provide
the actual function that should respond.
diff --git a/tests/unit/resolution_resolvelib/test_resolver.py b/tests/unit/resolution_resolvelib/test_resolver.py
index 87c2b5f3533..cab8b71225f 100644
--- a/tests/unit/resolution_resolvelib/test_resolver.py
+++ b/tests/unit/resolution_resolvelib/test_resolver.py
@@ -34,7 +34,7 @@ def resolver(preparer: RequirementPreparer, finder: PackageFinder) -> Resolver:
def _make_graph(
- edges: List[Tuple[Optional[str], Optional[str]]]
+ edges: List[Tuple[Optional[str], Optional[str]]],
) -> "DirectedGraph[Optional[str]]":
"""Build graph from edge declarations."""
diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py
index 1a0acb7b411..1876a5ec203 100644
--- a/tests/unit/test_configuration.py
+++ b/tests/unit/test_configuration.py
@@ -237,9 +237,12 @@ def test_user_modification(self) -> None:
# get the path to user config file
assert mymock.call_count == 1
- assert mymock.call_args[0][0] == (
- # Use new config file
- get_configuration_files()[kinds.USER][1]
+ assert (
+ mymock.call_args[0][0]
+ == (
+ # Use new config file
+ get_configuration_files()[kinds.USER][1]
+ )
)
def test_global_modification(self) -> None:
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 1352b766481..1caeaa008bc 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -249,8 +249,7 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None:
# Create directory without read permission
subdir_path = tmpdir / "subdir"
subdir_path.mkdir()
- path = str(subdir_path)
- os.chmod(path, stat.S_IWRITE)
+ os.chmod(subdir_path, stat.S_IWRITE)
mock_func = Mock()
@@ -264,7 +263,9 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None:
# Tuple[None, None, None]]"; expected "Tuple[Type[BaseException],
# BaseException, TracebackType]"
rmtree_errorhandler(
- mock_func, path, sys.exc_info() # type: ignore[arg-type]
+ mock_func,
+ subdir_path,
+ sys.exc_info(), # type: ignore[arg-type]
)
mock_func.assert_not_called()
diff --git a/tools/release/__init__.py b/tools/release/__init__.py
index ebd1b901414..442dacef0bf 100644
--- a/tools/release/__init__.py
+++ b/tools/release/__init__.py
@@ -105,13 +105,8 @@ def update_version_file(version: str, filepath: str) -> None:
def create_git_tag(session: Session, tag_name: str, *, message: str) -> None:
- session.run(
- # fmt: off
- "git", "tag", "-m", message, tag_name,
- # fmt: on
- external=True,
- silent=True,
- )
+ cmd = ["git", "tag", "-m", message, tag_name]
+ session.run(*cmd, external=True, silent=True)
def get_next_development_version(version: str) -> str:
@@ -173,12 +168,17 @@ def isolated_temporary_checkout(
git_checkout_dir = tmp_dir / f"pip-build-{target_ref}"
nox_session.run(
# fmt: off
- "git", "clone",
- "--depth", "1",
- "--config", "core.autocrlf=false",
- "--branch", str(target_ref),
+ "git",
+ "clone",
+ "--depth",
+ "1",
+ "--config",
+ "core.autocrlf=false",
+ "--branch",
+ str(target_ref),
"--",
- ".", str(git_checkout_dir),
+ ".",
+ str(git_checkout_dir),
# fmt: on
external=True,
silent=True,
@@ -191,9 +191,13 @@ def get_git_untracked_files() -> Iterator[str]:
"""List all local file paths that aren't tracked by Git."""
git_ls_files_cmd = (
# fmt: off
- "git", "ls-files",
- "--ignored", "--exclude-standard",
- "--others", "--", ".",
+ "git",
+ "ls-files",
+ "--ignored",
+ "--exclude-standard",
+ "--others",
+ "--",
+ ".",
# fmt: on
)
# session.run doesn't seem to return any output: