-
-
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
explore running 'pipenv shell' automatically #378
Comments
this would have to be a 5.0 release, if we do it at all... i think it would be too magical, but at the same time, it might be really nice. i'd like to prototype it out maybe. |
If I'm understanding the description correctly, I have a use case for this. pytest-watch is a tool that reruns
Related patch to make pytest-watch work with pipenv: joeyespo/pytest-watch#72 |
I use a cheat to activate pipenv on cd. Not sure if its relevant here. I hack the bash
|
And for fish shell, we have a plugin now! https://github.com/fisherman/pipenv |
Anyone who wants such fanciness should be using fish anyway. Closing :) |
Just stumbled upon this issue while trying out pipenv. The reason for closing it is... weird, to put it nicely. It'd be like saying "if you want better packaging tools don't use python, use some other language" instead of developing pipenv. |
I use https://github.com/pyenv/pyenv-virtualenv to automatically activate a virtualenv - maybe this project can leverage and integrate the work there? Not real inclined to switch to fish - I've been messing with https://github.com/xonsh/xonsh more |
@jcrben That's kinda where my train of thought was heading towards towards as well... wouldn't be too much of a stretch to modify it for pipenv by the looks of it. |
@kennethreitz are you completely against this one? Should we open a new issue, continue the the discussion here and re-opening this one, or something else? I think the rationale has been explained properly, but I want to bring one more example: this was extremely handy, especially when you deal with a lot of different projects in different status with different codes: you don't have to switch on the "right" environment, it is done for you, and it's one command less to run. I think this should be done automatically by pipenv, as in the |
How is automatically activating venv's "fanciness"? It's a basic operation that I don't want to be performing over and over, seems a bit flippant to just close this issue with what is effectively a "just migrate shell's LOL". |
@JohnVonNeumann Well you would think this is a mundane and required feature, until you actually try to implement it. This is very difficult to implement without some terrible hacks (I consider pyenv’s shims terrible, in case you wonder). The operation may be basic (I don’t think so, in fact), but the work involved isn’t. Try it yourself first, and we can have a discussion after you come up with something. :) |
@uranusjr Thinking and believing this is a mundane and required feature, and then also believing it should be in the product, shouldn't be impacted by the difficulty required to implement. We can agree on the usefulness of a proposed something before working out how to build it. This, I would imagine, is common engineering, you figure out what you want then build it, you don't create features because based on their ease of creation, you create features based on the benefits of them. In saying this, if something is difficult to build, then so be it, that's the fact. What I find a little disconcerting however is that if this is the case, then people should say this. Not just "Ahh this would be hard, wouldn't be useful anyway". If I did this everytime I got handed a difficult ticket at work I wouldn't have a job. And whilst I can appreciate the point you're trying to make here with your comments, and I would 100% love to help out with a feature like this because I'd get a lot of good practical use out of it, I'm a little chafed by your comment because it's like because I haven't built the thing myself, I'm not allowed an opinion. I'm not the only person to have brought this up, and in fact, from what I can see, we appear to be in the majority in our opinion. I thought OS was about community consensus? If help is required on a feature, ask for it, don't just veto it and act as if it wouldn't be useful. |
This is out of scope for design reasons whether the implementation is easy or not. We have no plans of forcing people into subshells, that’s why we have |
Just improved @Blue-Dog-Archolite's suggestion for my case. Here's my function auto_pipenv_shell {
if [ ! -n "${PIPENV_ACTIVE+1}" ]; then
if [ -f "Pipfile" ] ; then
pipenv shell
fi
fi
}
function cd {
builtin cd "$@"
auto_pipenv_shell
}
auto_pipenv_shell |
Hey thanks for the snippet @caioariede, I'm using it atm and its great. I made some slight modifications to it for my particular use case, I'm posting them here just in case someone else may find them useful. Also added a couple of methods for managing of virtualenvs as I still cannot completely switch over to pipenv ( # Activate current folder's pipenv virtualenv
# or accept an explicit virtualenv name
workon() {
if [ $# -eq 0 ]
then
source $(pipenv --venv)/bin/activate
else
source ~/.virtualenvs/$1/bin/activate
fi
}
# Making virtualenv alias
mkvenv() {
cd ~/.virtualenvs
virtualenv "$@"
cd -
workon "$1"
}
# Automatic virtualenv sourcing
function auto_pipenv_shell {
if [ ! -n "$VIRTUAL_ENV" ]; then
if [ -f "Pipfile" ] ; then
workon
fi
fi
}
function cd {
builtin cd "$@"
auto_pipenv_shell
}
auto_pipenv_shell |
It would be great if someone could add a wiki entry for these! |
Maybe https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv could be inspiration for someone. |
Might I suggest the following (works in .zshrc and maybe .bashrc?):
|
@ethanj |
Fixed—really sorry about that. |
I'm not sure if this is the right place, but I'm trying to switch to pipenv and finding it painful to have to switch to a subshell or prefix every command that might use python with "pipenv run". Using zsh, I have a fair amount of state in my shell -- history, dir stack, and other stuff, not to mention having to double-exit to exit the terminal or switch to a new virtualenv. Having to pop into a subshell to work normally is a lot worse than "source $(pipenv shell-vars)" would be. Has there been any thought given to implementing a "pipenv shell-vars" command so people can switch around in the same shell? |
This looks like it does the job quite nicely, as it "will also detect and auto activate virtualenvs made with pipenv". @uranusjr please could you add this to the wiki? In this case I prefer a well-documented community made solution to the custom bash/zsh solutions currently there. |
Since I was not satisfy with the solutions proposed on the wiki page, I have created
Unlike Similar to
It can be used as a plugin for oh-my-zsh and oh-my-bash. It is used daily at Intersec by 60+ people without any issues. It would be great to add it to the wiki page. |
Thanks @nicopauss! I’ve added |
No description provided.
The text was updated successfully, but these errors were encountered: