Skip to content

Commit

Permalink
Add condition for a virtual environment on Windows to contain a Pytho…
Browse files Browse the repository at this point in the history
…n executable
  • Loading branch information
mknorps committed Jan 8, 2024
1 parent a5af8be commit a5a6ad0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions fawltydeps/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,20 @@ class PyEnvSource(Source):
def __post_init__(self) -> None:
super().__post_init__()
assert self.path.is_dir() # sanity check
# Support vitualenvs, poetry2nix envs, system-wide installs, etc.
if self.path.match("lib/python?.*/site-packages"):
if (self.path.parent.parent.parent / "bin/python").is_file():
return # all ok
# Also support projects using __pypackages__ from PEP582:
elif self.path.match("__pypackages__/?.*/lib"):
return # also ok

# Support Windows projects
if sys.platform.startswith("win") and self.path.match(
os.path.join("Lib", "site-packages")
):
if sys.platform.startswith("win"):
if self.path.match(str(Path("Lib", "site-packages"))):
if (self.path.parent.parent / "Scripts" / "python.exe").is_file():
return # also ok
# Support vitualenvs, poetry2nix envs, system-wide installs, etc.
else:
if self.path.match("lib/python?.*/site-packages"):
if (self.path.parent.parent.parent / "bin/python").is_file():
return # all ok

# Also support projects using __pypackages__ from PEP582:
if self.path.match("__pypackages__/?.*/lib"):
return # also ok

raise ValueError(f"{self.path} is not a valid dir for Python packages!")
Expand Down

0 comments on commit a5a6ad0

Please sign in to comment.