Skip to content

Commit

Permalink
Update everything (#9569)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored Jul 31, 2024
1 parent 2e3a421 commit b6bad9c
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 319 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude: tests/repositories/fixtures/pypi.org/metadata/.*\.metadata
Expand All @@ -22,12 +22,12 @@ repos:
- id: check-docstring-first

- repo: https://github.com/pre-commit/pre-commit
rev: v3.6.2
rev: v3.7.1
hooks:
- id: validate_manifest

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
rev: v0.5.4
hooks:
- id: ruff
- id: ruff-format
570 changes: 283 additions & 287 deletions poetry.lock

Large diffs are not rendered by default.

34 changes: 30 additions & 4 deletions src/poetry/utils/env/site_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Literal
from typing import overload

from poetry.utils._compat import metadata
from poetry.utils.helpers import is_dir_writable
Expand Down Expand Up @@ -153,6 +155,28 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:

return paths

@overload
def _path_method_wrapper(
self,
path: Path,
method: str,
*args: Any,
return_first: Literal[False],
writable_only: bool = False,
**kwargs: Any,
) -> list[tuple[Path, Any]]: ...

@overload
def _path_method_wrapper(
self,
path: Path,
method: str,
*args: Any,
return_first: bool = True,
writable_only: bool = False,
**kwargs: Any,
) -> tuple[Path, Any]: ...

def _path_method_wrapper(
self,
path: Path,
Expand Down Expand Up @@ -181,13 +205,15 @@ def _path_method_wrapper(
raise OSError(f"Unable to access any of {paths_csv(candidates)}")

def write_text(self, path: Path, *args: Any, **kwargs: Any) -> Path:
paths = self._path_method_wrapper(path, "write_text", *args, **kwargs)
assert isinstance(paths, tuple)
paths: tuple[Path, Any] = self._path_method_wrapper(
path, "write_text", *args, **kwargs
)
return paths[0]

def mkdir(self, path: Path, *args: Any, **kwargs: Any) -> Path:
paths = self._path_method_wrapper(path, "mkdir", *args, **kwargs)
assert isinstance(paths, tuple)
paths: tuple[Path, Any] = self._path_method_wrapper(
path, "mkdir", *args, **kwargs
)
return paths[0]

def exists(self, path: Path) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions tests/console/commands/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def poetry_with_scripts(

def test_run_passes_all_args(app_tester: ApplicationTester, env: MockEnv) -> None:
app_tester.execute("run python -V")
assert [["python", "-V"]] == env.executed
assert env.executed == [["python", "-V"]]


def test_run_keeps_options_passed_before_command(
Expand All @@ -59,7 +59,7 @@ def test_run_keeps_options_passed_before_command(
assert app_tester.io.fetch_output() == app_tester.io.remove_format(
app_tester.application.long_version + "\n"
)
assert [] == env.executed
assert env.executed == []


def test_run_has_helpful_error_when_command_not_found(
Expand Down
8 changes: 4 additions & 4 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ def test_show_basic_with_installed_packages_single(

tester.execute("cachy")

assert [
assert [line.strip() for line in tester.io.fetch_output().splitlines()] == [
"name : cachy",
"version : 0.1.0",
"description : Cachy package",
] == [line.strip() for line in tester.io.fetch_output().splitlines()]
]


def test_show_basic_with_installed_packages_single_canonicalized(
Expand Down Expand Up @@ -337,11 +337,11 @@ def test_show_basic_with_installed_packages_single_canonicalized(

tester.execute("Foo_Bar")

assert [
assert [line.strip() for line in tester.io.fetch_output().splitlines()] == [
"name : foo-bar",
"version : 0.1.0",
"description : Foobar package",
] == [line.strip() for line in tester.io.fetch_output().splitlines()]
]


def test_show_basic_with_not_installed_packages_non_decorated(
Expand Down
2 changes: 1 addition & 1 deletion tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from build import BuildBackendException
from build import ProjectBuilder
from packaging.metadata import parse_email
from pkginfo.distribution import NewMetadataVersion # type: ignore[attr-defined]
from pkginfo.distribution import NewMetadataVersion

from poetry.inspection.info import PackageInfo
from poetry.inspection.info import PackageInfoError
Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
pip_install.assert_called_once_with(
extended_poetry.pyproject.file.path.parent, env, upgrade=True, editable=True
)
assert [] == env.executed
assert env.executed == []


@pytest.mark.network
Expand Down
34 changes: 17 additions & 17 deletions tests/publishing/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def test_publish_publishes_to_pypi_by_default(

publisher.publish(None, None, None)

assert [("foo", "bar")] == uploader_auth.call_args
assert [
assert uploader_auth.call_args == [("foo", "bar")]
assert uploader_upload.call_args == [
("https://upload.pypi.org/legacy/",),
{"cert": True, "client_cert": None, "dry_run": False, "skip_existing": False},
] == uploader_upload.call_args
]


@pytest.mark.parametrize("fixture_name", ["sample_project", "with_default_source"])
Expand Down Expand Up @@ -68,11 +68,11 @@ def test_publish_can_publish_to_given_repository(

publisher.publish("foo", None, None)

assert [("foo", "bar")] == uploader_auth.call_args
assert [
assert uploader_auth.call_args == [("foo", "bar")]
assert uploader_upload.call_args == [
("http://foo.bar",),
{"cert": True, "client_cert": None, "dry_run": False, "skip_existing": False},
] == uploader_upload.call_args
]
project_name = canonicalize_name(fixture_name)
assert f"Publishing {project_name} (1.2.3) to foo" in io.fetch_output()

Expand Down Expand Up @@ -104,11 +104,11 @@ def assert_publish_uses_token_if_it_exists(
publisher = Publisher(poetry, NullIO())
publisher.publish(None, None, None)

assert [("__token__", "my-token")] == uploader_auth.call_args
assert [
assert uploader_auth.call_args == [("__token__", "my-token")]
assert uploader_upload.call_args == [
("https://upload.pypi.org/legacy/",),
{"cert": True, "client_cert": None, "dry_run": False, "skip_existing": False},
] == uploader_upload.call_args
]


def test_publish_uses_token_if_it_exists(
Expand Down Expand Up @@ -144,16 +144,16 @@ def test_publish_uses_cert(

publisher.publish("foo", None, None)

assert [("foo", "bar")] == uploader_auth.call_args
assert [
assert uploader_auth.call_args == [("foo", "bar")]
assert uploader_upload.call_args == [
("https://foo.bar",),
{
"cert": Path(cert),
"client_cert": None,
"dry_run": False,
"skip_existing": False,
},
] == uploader_upload.call_args
]


def test_publish_uses_client_cert(
Expand All @@ -173,15 +173,15 @@ def test_publish_uses_client_cert(

publisher.publish("foo", None, None)

assert [
assert uploader_upload.call_args == [
("https://foo.bar",),
{
"cert": True,
"client_cert": Path(client_cert),
"dry_run": False,
"skip_existing": False,
},
] == uploader_upload.call_args
]


def test_publish_read_from_environment_variable(
Expand All @@ -200,8 +200,8 @@ def test_publish_read_from_environment_variable(

publisher.publish("foo", None, None)

assert [("bar", "baz")] == uploader_auth.call_args
assert [
assert uploader_auth.call_args == [("bar", "baz")]
assert uploader_upload.call_args == [
("https://foo.bar",),
{"cert": True, "client_cert": None, "dry_run": False, "skip_existing": False},
] == uploader_upload.call_args
]

0 comments on commit b6bad9c

Please sign in to comment.