Skip to content

Commit

Permalink
refactor: rename from_metadata to from_metadata_directory, rename…
Browse files Browse the repository at this point in the history
… `from_wheel_metadata` to `from_metadata`
  • Loading branch information
radoering committed Jan 4, 2024
1 parent c20b0ed commit 2e797c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
38 changes: 19 additions & 19 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,22 @@ def _find_dist_info(path: Path) -> Iterator[Path]:
yield Path(d)

@classmethod
def from_metadata(cls, path: Path) -> PackageInfo | None:
def from_metadata(cls, metadata: RawMetadata) -> PackageInfo:
"""
Create package information from core metadata.
:param metadata: raw metadata
"""
return cls(
name=metadata.get("name"),
version=metadata.get("version"),
summary=metadata.get("summary"),
requires_dist=metadata.get("requires_dist"),
requires_python=metadata.get("requires_python"),
)

@classmethod
def from_metadata_directory(cls, path: Path) -> PackageInfo | None:
"""
Helper method to parse package information from an unpacked metadata directory.
Expand Down Expand Up @@ -475,7 +490,7 @@ def from_directory(cls, path: Path, disable_build: bool = False) -> PackageInfo:
if project_package:
info = cls.from_package(project_package)
else:
info = cls.from_metadata(path)
info = cls.from_metadata_directory(path)

if not info or info.requires_dist is None:
try:
Expand Down Expand Up @@ -521,21 +536,6 @@ def from_wheel(cls, path: Path) -> PackageInfo:
except ValueError:
return PackageInfo()

@classmethod
def from_wheel_metadata(cls, metadata: RawMetadata) -> PackageInfo:
"""
Gather package information from metadata of a remote wheel.
:param metadata: metadata of the wheel.
"""
return cls(
name=metadata.get("name"),
version=metadata.get("version"),
summary=metadata.get("summary"),
requires_dist=metadata.get("requires_dist"),
requires_python=metadata.get("requires_python"),
)

@classmethod
def from_bdist(cls, path: Path) -> PackageInfo:
"""
Expand Down Expand Up @@ -599,7 +599,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
*PEP517_META_BUILD_DEPS,
)
venv.run_python_script(pep517_meta_build_script)
info = PackageInfo.from_metadata(dest_dir)
info = PackageInfo.from_metadata_directory(dest_dir)
except EnvCommandError as e:
# something went wrong while attempting pep517 metadata build
# fallback to egg_info if setup.py available
Expand All @@ -616,7 +616,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
os.chdir(path)
try:
venv.run("python", "setup.py", "egg_info")
info = PackageInfo.from_metadata(path)
info = PackageInfo.from_metadata_directory(path)
except EnvCommandError as fbe:
raise PackageInfoError(
path, e, "Fallback egg_info generation failed.", fbe
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _get_info_from_wheel(self, url: str) -> PackageInfo:
# or we don't know yet, we try range requests.
if self._lazy_wheel and self._supports_range_requests.get(netloc, True):
try:
package_info = PackageInfo.from_wheel_metadata(
package_info = PackageInfo.from_metadata(
metadata_from_wheel_url(link.filename, link.url, self.session)
)
except HTTPRangeRequestUnsupported:
Expand Down
6 changes: 3 additions & 3 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_info_from_wheel(demo_wheel: Path) -> None:


def test_info_from_wheel_metadata(demo_wheel_metadata: RawMetadata) -> None:
info = PackageInfo.from_wheel_metadata(demo_wheel_metadata)
info = PackageInfo.from_metadata(demo_wheel_metadata)
demo_check_info(info)
assert info.requires_python == ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
assert info._source_type is None
Expand All @@ -187,7 +187,7 @@ def test_info_from_wheel_metadata_incomplete() -> None:
it is important that the representation of missing fields does not change!
"""
metadata, _ = parse_email(b"Metadata-Version: 2.1\nName: demo\nVersion: 0.1.0\n")
info = PackageInfo.from_wheel_metadata(metadata)
info = PackageInfo.from_metadata(metadata)
assert info.name == "demo"
assert info.version == "0.1.0"
assert info.summary is None
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_info_from_poetry_directory_fallback_on_poetry_create_error(


def test_info_from_requires_txt(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_metadata(
info = PackageInfo.from_metadata_directory(
fixture_dir("inspection") / "demo_only_requires_txt.egg-info"
)
assert info is not None
Expand Down

0 comments on commit 2e797c7

Please sign in to comment.