Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc cleanup #9225

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/poetry/console/commands/about.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from collections.abc import Callable


class AboutCommand(Command):
name = "about"

Expand All @@ -17,16 +11,12 @@ class AboutCommand(Command):
def handle(self) -> int:
from poetry.utils._compat import metadata

# The metadata.version that we import for Python 3.7 is untyped, work around
# that.
version: Callable[[str], str] = metadata.version

self.line(
f"""\
<info>Poetry - Package Management for Python

Version: {version('poetry')}
Poetry-Core Version: {version('poetry-core')}</info>
Version: {metadata.version('poetry')}
Poetry-Core Version: {metadata.version('poetry-core')}</info>

<comment>Poetry is a dependency manager tracking local dependencies of your projects\
and libraries.
Expand Down
10 changes: 3 additions & 7 deletions src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _get_info_from_metadata(self, link: Link) -> PackageInfo | None:
response = self.session.get(link.metadata_url)
if link.metadata_hashes and (
hash_name := get_highest_priority_hash_type(
set(link.metadata_hashes.keys()), f"{link.filename}.metadata"
link.metadata_hashes, f"{link.filename}.metadata"
)
):
metadata_hash = getattr(hashlib, hash_name)(
Expand Down Expand Up @@ -351,9 +351,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any]
file_hash = self.calculate_sha256(link)

if file_hash is None and (
hash_type := get_highest_priority_hash_type(
set(link.hashes.keys()), link.filename
)
hash_type := get_highest_priority_hash_type(link.hashes, link.filename)
):
file_hash = f"{hash_type}:{link.hashes[hash_type]}"

Expand All @@ -372,9 +370,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any]

def calculate_sha256(self, link: Link) -> str | None:
with self._cached_or_downloaded_file(link) as filepath:
hash_name = get_highest_priority_hash_type(
set(link.hashes.keys()), link.filename
)
hash_name = get_highest_priority_hash_type(link.hashes, link.filename)
known_hash = None
with suppress(ValueError, AttributeError):
# Handle ValueError here as well since under FIPS environments
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ def __init__(self, *, cache_dir: Path) -> None:
def get_cache_directory_for_link(self, link: Link) -> Path:
key_parts = {"url": link.url_without_fragment}

if hash_name := get_highest_priority_hash_type(
set(link.hashes.keys()), link.filename
):
if hash_name := get_highest_priority_hash_type(link.hashes, link.filename):
key_parts[hash_name] = link.hashes[hash_name]

if link.subdirectory_fragment:
Expand Down
13 changes: 0 additions & 13 deletions src/poetry/utils/env/site_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,6 @@ def find_distribution(
return distribution
return None

def find_distribution_files_with_suffix(
self, distribution_name: str, suffix: str, writable_only: bool = False
) -> Iterable[Path]:
for distribution in self.distributions(
name=distribution_name, writable_only=writable_only
):
files = [] if distribution.files is None else distribution.files
for file in files:
if file.name.endswith(suffix):
path = distribution.locate_file(file)
assert isinstance(path, Path)
yield path

def find_distribution_files_with_name(
self, distribution_name: str, name: str, writable_only: bool = False
) -> Iterable[Path]:
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Collection
from collections.abc import Iterator
from types import TracebackType

Expand Down Expand Up @@ -332,7 +333,7 @@ def get_file_hash(path: Path, hash_name: str = "sha256") -> str:


def get_highest_priority_hash_type(
hash_types: set[str], archive_name: str
hash_types: Collection[str], archive_name: str
) -> str | None:
if not hash_types:
return None
Expand Down
Loading