MichaelAquilina/zsh-autoswitch-virtualenv

Option to remove `randstr` in `mkvenv`

stevenxxiu opened this issue · 5 comments

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

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

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.

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

@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.

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

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.

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