-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix environment #3243
Fix environment #3243
Changes from 13 commits
483621f
ff8d17f
5d8ac09
95c70c3
748d22b
df924d3
a8f52eb
915b3c1
32f5d85
6901eae
5e94bcb
e909d9b
52499df
e575f87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Environment variables are expanded correctly before running scripts on POSIX. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Correctly detect the virtualenv location inside an activated virtualenv. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed a bug that editable pacakges can't be uninstalled correctly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,12 @@ def is_quiet(threshold=-1): | |
return PIPENV_VERBOSITY <= threshold | ||
|
||
|
||
def is_in_virtualenv(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't like using globals everywhere to figure this out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the global environment variable is good and convenient but I need a way to get the right status when the environment is modified in runtime.(see the test case) It isn't a good idea to change the logic only for testing though, because in real case the environment is always decided before any command is launched. If you are not for this, I can revert these bits and consider using patching in test case. |
||
pipenv_active = os.environ.get("PIPENV_ACTIVE") | ||
virtual_env = os.environ.get("VIRTUAL_ENV") | ||
return (PIPENV_USE_SYSTEM or virtual_env) and not pipenv_active | ||
|
||
|
||
PIPENV_SPINNER_FAIL_TEXT = fix_utf8(u"✘ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}") | ||
|
||
PIPENV_SPINNER_OK_TEXT = fix_utf8(u"✔ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import pytest | ||
|
||
from pipenv._compat import TemporaryDirectory, Path | ||
from pipenv.exceptions import VirtualenvActivationException | ||
from pipenv.utils import temp_environ | ||
from pipenv.vendor import delegator | ||
from pipenv.vendor import requests | ||
from pipenv.vendor import toml | ||
|
@@ -111,6 +113,9 @@ def isolate(pathlib_tmpdir): | |
os.environ["GIT_AUTHOR_EMAIL"] = fs_str("[email protected]") | ||
mkdir_p(os.path.join(home_dir, ".virtualenvs")) | ||
os.environ["WORKON_HOME"] = fs_str(os.path.join(home_dir, ".virtualenvs")) | ||
# Ignore PIPENV_ACTIVE so that it works as under a bare environment. | ||
os.environ.pop("PIPENV_ACTIVE", None) | ||
os.environ.pop("VIRTUAL_ENV", None) | ||
global WE_HAVE_GITHUB_SSH_KEYS | ||
WE_HAVE_GITHUB_SSH_KEYS = check_github_ssh() | ||
|
||
|
@@ -239,3 +244,22 @@ def finalize(): | |
@pytest.fixture() | ||
def testsroot(): | ||
return TESTS_ROOT | ||
|
||
|
||
@pytest.fixture() | ||
def virtualenv(pathlib_tmpdir): | ||
virtualenv_path = pathlib_tmpdir / "venv" | ||
with temp_environ(): | ||
c = delegator.run("virtualenv {}".format(virtualenv_path), block=True) | ||
assert c.return_code == 0 | ||
for name in ("bin", "Scripts"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alternative fixture here is to use from pipenv.environment import Environment
@pytest.fixture()
def virtualenv(pathlib_tmpdir, PipenvInstance):
virtualenv_path = pathlib_tmpdir / "venv"
with temp_environ():
c = delegator.run("virtualenv {}".format(virtualenv_path), block=True)
assert c.return_code == 0
environment = Environment(prefix=virtualenv_path.as_posix(), is_venv=True, pipfile=PipenvInstance.pipfile)
with environment.activated():
yield virtualenv_path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P.s. I have no idea if this works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense for me. |
||
activate_this = virtualenv_path / name / "activate_this.py" | ||
if activate_this.exists(): | ||
with open(str(activate_this)) as f: | ||
code = compile(f.read(), str(activate_this), "exec") | ||
exec(code, dict(__file__=str(activate_this))) | ||
break | ||
else: | ||
raise VirtualenvActivationException("Can't find the activate_this.py script.") | ||
os.environ["VIRTUAL_ENV"] = str(virtualenv_path) | ||
yield virtualenv_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I think
os.execv
(which takes a sequence directly) is better thanexecl
.