forked from python-poetry/poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils/env: better support system site packages dir
This change improves handling of site-packages under system env, by gracefully handling fallbacks to user site when required and possible. Resolves: python-poetry#3079
- Loading branch information
Showing
8 changed files
with
218 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import uuid | ||
|
||
from poetry.utils._compat import Path | ||
from poetry.utils._compat import decode | ||
from poetry.utils.env import SitePackages | ||
|
||
|
||
def test_env_site_simple(tmp_dir): | ||
site_packages = SitePackages(Path("/non-existent"), fallbacks=[Path(tmp_dir)]) | ||
candidates = site_packages.make_candidates(Path("hello.txt"), writable_only=True) | ||
hello = Path(tmp_dir) / "hello.txt" | ||
|
||
assert len(candidates) == 1 | ||
assert candidates[0].as_posix() == hello.as_posix() | ||
|
||
content = decode(str(uuid.uuid4())) | ||
site_packages.write_text(Path("hello.txt"), content, encoding="utf-8") | ||
|
||
assert hello.read_text(encoding="utf-8") == content | ||
|
||
assert not (site_packages.path / "hello.txt").exists() | ||
|
||
|
||
def test_env_site_select_first(tmp_dir): | ||
path = Path(tmp_dir) | ||
fallback = path / "fallback" | ||
fallback.mkdir(parents=True) | ||
|
||
site_packages = SitePackages(path, fallbacks=[fallback]) | ||
candidates = site_packages.make_candidates(Path("hello.txt"), writable_only=True) | ||
|
||
assert len(candidates) == 2 | ||
assert len(site_packages.find(Path("hello.txt"))) == 0 | ||
|
||
content = decode(str(uuid.uuid4())) | ||
site_packages.write_text(Path("hello.txt"), content, encoding="utf-8") | ||
|
||
assert (site_packages.path / "hello.txt").exists() | ||
assert not (fallback / "hello.txt").exists() | ||
|
||
assert len(site_packages.find(Path("hello.txt"))) == 1 |