MichaelAquilina / zsh-autoswitch-virtualenv

🐍 ZSH plugin to automatically switch python virtualenvs (including pipenv and poetry) as you move between directories
GNU General Public License v3.0
507 stars 80 forks source link

Option to remove `randstr` in `mkvenv` #174

Open stevenxxiu opened 2 years ago

stevenxxiu commented 2 years ago

When running mkvenv, recently there's a randstr suffix that is added at:

https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv/blob/c119ab9c539aa892e32e705144eae926ae44893b/autoswitch_virtualenv.plugin.zsh#L327

local venv_name="$(basename $PWD)-$(randstr)"

Can there be an option to exclude this? I often create projects that require an exact venv name, as specified in the .venv file under version control.

This suffix means I cannot rely on zsh-autoswitch-virtualenv, and instead rely on https://github.com/pypa/virtualenv.

MichaelAquilina commented 2 years ago

@stevenxxiu would you mind elaborating on this need? I want to make sure that we understand the problem first :)

stevenxxiu commented 2 years ago

@stevenxxiu would you mind elaborating on this need? I want to make sure that we understand the problem first :)

Sure. I have some projects with a .venv file pointing to the Virtualenv environment name.

Occasionally, Python gets a major version update. This means I need to recreate the Virtualenvs of my old projects.

In order to do this, I tried running mkenv under those project directories. But now this gives me a random Virtualenv name, that doesn't match the .venv file that's already under version control. I need a Virtualenv with the same name.

MichaelAquilina commented 2 years ago

Why do you need .venv under version control @stevenxxiu ? I would recommend keeping this outside of version control because it is specific to your local machine

stevenxxiu commented 2 years ago

That makes some sense. Another reason though is I want my Virtualenvs to have nice looking names. The suffix might make things rather confusing, if there are 2 Virtualenvs with the same name and different suffixes.

MegaBluejay commented 2 years ago

Seems like there are several separate parts to this.

For the use case of version-controlled .venv files, it might make sense to read the current value and offer to make an environment with that name, rather than the current behavior with an invalid .venv

The other issue is prettiness. I also dislike the randomized names in my prompt, but they make sense to make sure one venv doesn't get reused by accident, so I set the prompt variable in their pyenv.cfg instead. As far as I can tell, that's exactly what it was made for, and for me that achieves best of both worlds, although not all prompts support this option. While I don't think it's necessarily a good idea for mkvenv to set this automatically, since it could be confusing, I do recommend it to anyone else irked by the random names. image