-
-
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 bug where custom virtualenv can not be activated by pipenv shell #3340
Conversation
Actually they are different. #3299 is a behavior change but this one is merely fixing a bug. It looks like the CI for this PR is stuck. 😢 |
CI is set to batch run so it sometimes takes awhile to start while it waits to see if you will push more changes |
I think we can make a test for this, I’ll see before we merge |
That's what I'm thinking. It is better to have tests for this. But it looks like |
Hm I didn’t get a chance to try this yet but I’m guessing we need a fake tty wrapper to have it play nice. Possibly this is controlled via |
@techalchemy Thanks for sharing! I'm going to have look. Free free to contribute to it if you already have some solutions. |
I have a different approach to solving this: Detect whether we are in a virtualenv with |
I've updated the PR fixing another bug in |
@frostming What do you mean by showing a message? If that means show a warning or error message instead of re-activating it, I think this limits the usage of pipenv. For example, probably I'm already in an activated virtualenv by Another case is that even virtualenv is activated, |
To be honest I’m confused. If you’re in a virtualenv you made and activated yourself, pipenv should operate automatically as though you passes The only time we should be trying to look for pipenv-owned virtualenvs is if |
Yes, with this PR, pipenv wil use activated virtualenv automatically when This is for reproduce for
This is for reproduce for
|
I came up with an approach to testing against the subshell: c = p.pipenv("shell", block=False)
c.send("python -c 'import sys; print(sys.executable)'")
c.send("exit")
c.block()
# check output
assert c.out ... @jxltom Please tell me if it works. |
Thanks! @frostming , I'm going to have a look. |
Maybe you can write a contextmanager to hide the openning/ending bits. |
Ugh.. it doesn't work for posix.. |
@frostming We may need emulating a tty for testing this |
At one time I had a full test for this exact situation |
This isn't broken for me locally... |
the correct behavior is to use the activated virtualenv unless Seems like it works? ³ tempenv-6c963194107a0 ~/g/pythonfinder feature/add-typechecking pipenv --venv
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
/home/hawk/.virtualenvs/tempenv-6c963194107a0
³ tempenv-6c963194107a0 ~/g/pythonfinder feature/add-typechecking pipenv run which python
/home/hawk/.virtualenvs/pythonfinder-AjR26NJ2/bin/python
³ tempenv-6c963194107a0 ~/g/pythonfinder feature/add-typechecking cd /tmp/test
³ tempenv-6c963194107a0 /t/test pipenv run which python
Creating a Pipfile for this project…
/home/hawk/.virtualenvs/tempenv-6c963194107a0/bin/python |
Sounds like it is working for you @techalchemy Did you try this? It should output
|
Update, for reproducing this, you have to create a pipenv-owned virtualenv first...
Finally it will output |
so did we conclude here that things are mostly working OK? |
Yeah, it still a bug but only happens when |
and the bug is that they don't use pipenv's environment? or what is the bug |
The bug is that Please check this #3340 (comment) for reproducing. |
Update: I've added test for this PR. As for the tests for |
@jxltom For tests, you should create a pipenv project outside of the virtualenv, which may need to rewrite the |
07a51c6
to
16db36e
Compare
@frostming Yeah, but this bug can also be reproduced within an activated virtualenv at the beginning only if I can confirm this test can not pass without this PR's patch, so it is working anyway... |
Thanks for handling this bizarre edge case, definitely a confusing one but a lot more clear with a failing test |
scratch this comment, we just had a bug with warning on run, we are all set on this |
The issue
Closes #3339. This is because in
PIPENV_ACTIVE
is checked in project'svirtualenv_location
which is introduced in https://github.com/pypa/pipenv/pull/3243/files#diff-7c0c15ee4eba8c237e3318a395816a13R430. So setting upPIPENV_ACTIVE
indo_shell
has to be after finishing readingvirtualenv_location
which is a dynamic property.The checklist
news/
directory to describe this fix with the extension.bugfix
,.feature
,.behavior
,.doc
..vendor
. or.trivial
(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.