Skip to content
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

Option to remove randstr in mkvenv #174

Open
stevenxxiu opened this issue Mar 29, 2022 · 5 comments
Open

Option to remove randstr in mkvenv #174

stevenxxiu opened this issue Mar 29, 2022 · 5 comments

Comments

@stevenxxiu
Copy link
Contributor

stevenxxiu commented Mar 29, 2022

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.

@MichaelAquilina
Copy link
Owner

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

@stevenxxiu
Copy link
Contributor Author

@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
Copy link
Owner

MichaelAquilina commented Apr 4, 2022

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
Copy link
Contributor Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants