-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python-setup: Handle poetry
virtualenvs.options.no-pip = true
Fixes #1425
- Loading branch information
Showing
5 changed files
with
36 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Print the path to the site-packages directory for the current Python environment. | ||
""" | ||
|
||
try: | ||
import pip | ||
import os | ||
print(os.path.dirname(os.path.dirname(pip.__file__))) | ||
except ImportError: | ||
import sys | ||
print("could not import pip", file=sys.stderr) | ||
# if you use poetry with `virtualenvs.options.no-pip = true` you might end up with a | ||
# virtualenv without pip, so the above trick doesn't actually work. See | ||
# https://python-poetry.org/docs/configuration/#virtualenvsoptionsno-pip | ||
# | ||
# A possible option is to install `pip` into the virtualenv created by poetry | ||
# (`poetry add pip`), but it turns out that doesn't always work :( for the test | ||
# poetry/requests-3, I was not allowed to install pip! So I did not pursue this | ||
# option further. | ||
# | ||
# Instead, local testing shows that first entry of `site.getsitepackages()` has the | ||
# right path, whereas `site.getusersitepackages()` is about the system python (very | ||
# confusing). | ||
# | ||
# We can't use the environment variable POETRY_VIRTUALENVS_OPTIONS_NO_PIP because it | ||
# does not work, see https://github.com/python-poetry/poetry/issues/5906 | ||
import site | ||
print(site.getsitepackages()[0]) |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[virtualenvs] | ||
in-project = true | ||
|
||
[virtualenvs.options] | ||
no-pip = true |
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