Skip to content

Commit

Permalink
Handle distribution.files being None
Browse files Browse the repository at this point in the history
  • Loading branch information
jace-ys committed Oct 21, 2022
1 parent 16046d9 commit e5c5bdc
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,25 +328,29 @@ def find_distribution_files_with_suffix(
for distribution in self.distributions(
name=distribution_name, writable_only=writable_only
):
assert distribution.files is not None
for file in distribution.files:
if file.name.endswith(suffix):
yield Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
if distribution.files is not None:
for file in distribution.files:
if file.name.endswith(suffix):
yield Path(
distribution.locate_file(
file
), # type: ignore[no-untyped-call]
)

def find_distribution_files_with_name(
self, distribution_name: str, name: str, writable_only: bool = False
) -> Iterable[Path]:
for distribution in self.distributions(
name=distribution_name, writable_only=writable_only
):
assert distribution.files is not None
for file in distribution.files:
if file.name == name:
yield Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
if distribution.files is not None:
for file in distribution.files:
if file.name == name:
yield Path(
distribution.locate_file(
file
), # type: ignore[no-untyped-call]
)

def find_distribution_nspkg_pth_files(
self, distribution_name: str, writable_only: bool = False
Expand All @@ -372,14 +376,14 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
for distribution in self.distributions(
name=distribution_name, writable_only=True
):
assert distribution.files is not None
for file in distribution.files:
path = Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
# We can't use unlink(missing_ok=True) because it's not always available
if path.exists():
path.unlink()
if distribution.files is not None:
for file in distribution.files:
path = Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
# We can't use unlink(missing_ok=True) as it's not always available
if path.exists():
path.unlink()

distribution_path: Path = distribution._path # type: ignore[attr-defined]
if distribution_path.exists():
Expand Down

0 comments on commit e5c5bdc

Please sign in to comment.