Skip to content
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
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ dependencies = [
"cleo (>=2.1.0,<3.0.0)",
"dulwich (>=0.24.0,<0.25.0)",
"fastjsonschema (>=2.18.0,<3.0.0)",
# <8.7 because .metadata() (and Distribution.metadata) can now return None,
# which requires some adaptions to our code.
"importlib-metadata (>=4.4,<8.7) ; python_version < '3.10'",
"importlib-metadata (>=4.4) ; python_version < '3.10'",
"installer (>=0.7.0,<0.8.0)",
"keyring (>=25.1.0,<26.0.0)",
# packaging uses calver, so version is unclamped
Expand Down
51 changes: 26 additions & 25 deletions src/poetry/repositories/installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ def is_vcs_package(cls, package: Path | Package, env: Env) -> bool:
return True

@classmethod
def create_package_from_distribution(
cls, distribution: metadata.Distribution, env: Env
def _create_package_from_distribution(
cls, path: Path, dist_metadata: metadata.PackageMetadata, env: Env
) -> Package:
# We first check for a direct_url.json file to determine
# the type of package.
path = Path(str(distribution._path)) # type: ignore[attr-defined]

if (
path.name.endswith(".dist-info")
and path.joinpath("direct_url.json").exists()
):
return cls.create_package_from_pep610(distribution)
return cls._create_package_from_pep610(path, dist_metadata)

is_standard_package = env.is_path_relative_to_lib(path)

Expand All @@ -128,9 +126,7 @@ def create_package_from_distribution(
source_subdirectory = None
if is_standard_package:
if path.name.endswith(".dist-info"):
paths = cls.get_package_paths(
env=env, name=distribution.metadata["name"]
)
paths = cls.get_package_paths(env=env, name=dist_metadata["name"])
if paths:
is_editable_package = False
for src in paths:
Expand Down Expand Up @@ -160,32 +156,33 @@ def create_package_from_distribution(
source_url,
source_reference,
) = cls.get_package_vcs_properties_from_path(
env.path / "src" / canonicalize_name(distribution.metadata["name"])
env.path / "src" / canonicalize_name(dist_metadata["name"])
)
elif is_python_project(path.parent):
source_type = "directory"
source_url = str(path.parent)

package = Package(
distribution.metadata["name"],
distribution.metadata["version"],
dist_metadata["name"],
dist_metadata["version"],
source_type=source_type,
source_url=source_url,
source_reference=source_reference,
source_resolved_reference=source_resolved_reference,
source_subdirectory=source_subdirectory,
)

package.description = distribution.metadata.get( # type: ignore[attr-defined]
package.description = dist_metadata.get( # type: ignore[attr-defined]
"summary",
"",
)

return package

@classmethod
def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Package:
path = Path(str(distribution._path)) # type: ignore[attr-defined]
def _create_package_from_pep610(
cls, path: Path, dist_metadata: metadata.PackageMetadata
) -> Package:
source_type = None
source_url = None
source_reference = None
Expand Down Expand Up @@ -222,8 +219,8 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack
source_subdirectory = url_reference.get("subdirectory")

package = Package(
distribution.metadata["name"],
distribution.metadata["version"],
dist_metadata["name"],
dist_metadata["version"],
source_type=source_type,
source_url=source_url,
source_reference=source_reference,
Expand All @@ -232,7 +229,7 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack
develop=develop,
)

package.description = distribution.metadata.get( # type: ignore[attr-defined]
package.description = dist_metadata.get( # type: ignore[attr-defined]
"summary",
"",
)
Expand Down Expand Up @@ -273,8 +270,13 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
if path in skipped:
continue

name = distribution.metadata.get("name") # type: ignore[attr-defined]
if name is None:
dist_metadata = distribution.metadata # type: ignore[attr-defined]
name = (
dist_metadata.get("name") # type: ignore[attr-defined]
if dist_metadata
else None
)
if not dist_metadata or name is None:
logger.warning(
"Project environment contains an invalid distribution"
" (<c1>%s</>). Consider removing it manually or recreate"
Expand All @@ -289,21 +291,20 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
if name in seen:
continue

package = cls.create_package_from_distribution(distribution, env)
package = cls._create_package_from_distribution(
path, dist_metadata, env
)

if with_dependencies:
for require in distribution.metadata.get_all("requires-dist", []):
for require in dist_metadata.get_all("requires-dist", []):
dep = Dependency.create_from_pep_508(require)
package.add_dependency(dep)

seen.add(package.name)
repo.add_package(
package,
is_system_site=bool(
base_env
and base_env.is_path_relative_to_lib(
Path(str(distribution._path)) # type: ignore[attr-defined]
)
base_env and base_env.is_path_relative_to_lib(path)
),
)

Expand Down
1 change: 1 addition & 0 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ def verify_installed_distribution(

distribution = distributions[0]
metadata = distribution.metadata
assert metadata
assert metadata["Name"] == package.name
assert metadata["Version"] == package.version.text

Expand Down