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 have the virtual environment's directory name without hash (id) in it #3459
Comments
Personal point of view: |
Thanks! But I hope that I'm not the only developer who wants to have control and also the freedom to customise the directory name for the virtual environment (e. g. flag If that is not wanted then there should be an option like This would make it possible that the env name for the example in my initial post here would be Having
etc. for one and the same project that is just developed on different computers (e. g. at home and also at work) is really not helpful but producing efforts every time the machine is being switched. I mean the envs on the different computers that all belong to the same project are (except for the dir name) equal. It is not cool to be forced to have that hash in the middle of an env's dir name. :-) |
I do not see any reason why you would want to control the name of the virtual environment. The use case you showed, seems like a wrong use case for poetry, there are other tools better suited for this kind of use case, as I already mentioned. I am sure that hash serves a purpose, is not just here to annoy the users. If you insist on wanting to control the name of the virtual environment, you probably can create the environment beforehand and then let poetry use it. If I were in your situation I would try to experiment with something like the following (untested, some tweaking will be needed):
|
Ah... I guess you need to activate the virtual environment and use poetry inside it, instead of telling poetry to use that environment then. So maybe try a process like this:
But if it's integration with vscode that you are after, I guess there are better ways to do this. |
Tried that but it doesn't work: In the end I'd like to have the same and not very special freedom to control the env name completely as it is possible with other well-known environment/ dependency managers. What poetry offers in general is very helpful and cool. This is why I want to continue using it. Depending on additional tools just to be able to do something that the others (e. g. conda) offer is no option for me for now. This introduces more "complexity" and dependency/ risk where it should not be needed. |
I am not following why you say it does not work... Once you ran Also, please use copy paste of your console output, not screenshots. |
Yes, but
|
I am not following. On one hand you tell me you want to have total control over the name of the directory containing the virtual environment and on the other hand you tell me you need Again: nothing forces you to let poetry create the virtual environments. You can create them yourself with whatever names you want, so that the names are known in advance and the names are repeatable from machine to machine.
Which ones don't work? |
Sorry, but I expect that people assume positive intentions. I do serious software dev since more than 15 years and know what I do. To quickly answer the question respectively describe a quite common use case. There is a project with an according venv. The project has scripts (e. g. .sh, .py etc.) for tooling/ building project artifacts (e. g. a script to build Sphinx docs in a sub dir Now any of the project scripts can run Simple like that. Not overcomplicated and very common in toolsets. Think about variable substitutions in dev tools to keep dev toolsets runnable in a machine-independent manner. Example outlining that for the case of VS Code users: https://code.visualstudio.com/docs/editor/variables-reference Yes, the venv names are repeatable from machine to machine with your suggestion. But the needed absolute path to the venv is not.
In any case a work around that stops poetry commands to work properly is not acceptable. |
My bad, you already mentioned, you don't want to use the |
Yes, and there a couple of reasons:
|
I would need to look the exact code, and figure out why the hash is there exactly. I assume it is to differentiate multiple projects of the same name on the same machine. The hash might be a hash of the full path or something like that (the code seems to be here). In any case I doubt it would be possible to remove that hash, because otherwise I do not think poetry would be able to associate a Somewhat related:
Maybe this could be solved with an environment variable containing the base path for your virtual environments (value specific to each machine) and some light scripting to figure out the full path to the virtual environment based on 1. the environment variable, 2. the python interpreter version (major, minor), and 3. the name of the project. You could copy/paste some of the poetry code. You would call that script instead of |
Yes, thanks, that’s what I also thought of. Cheers, |
@jamilraichouni A dirty solution may be to 'just' replace the method Line 845 in 8312e3f
After that change, the virtual environment directory should be I initially felt such a feature would be a) messy, b) a source of future problems (due to the loss of a unique mapping from projects to their virtual environment directories) and c) only serve use cases which have better solutions. However, maybe the problems would be fixed if we just prohibit the creation of 2 projects with the same name and |
Thanks, I found a better workaround by using symbolic links.
Doing so, all configured paths to tools in virtal envs stay the same when switching the development computer. |
Hello, as @trianxy the hash is needed to find all venv's that belong to one project. (There could be more than one). So we cannot implement an option to deactivate the hash in the folder name, when using a central place for all venv managed by poetry. The symlink trick looks valid for your use case. Also you can try to find out, if it is really necessary the paths to the tools must be absolute paths in vscode config file. fin swimmer |
Sorry, but the hash is not a must-have but a design decision. Tell me why it works with system-wide central venvs and other well-known and used virtual env managers? |
If you tell me which one you have in mind I can have a look at it. So I can just guess :)
|
@finswimmer But honestly, all in all, I am not so sure this feature is required. There are ways to work around it (as already shown).
I am also curious to see what is meant here, and have a look, see if there is something to learn from those projects. |
A very famous example is Anaconda (here to see how environments are managed) with its comprehensive command line tool conda environments are stored in one central directory
Hence, one can
I think that covers every use case and lets the developer control everything. |
@jamilraichouni I just skimmed quickly, so I might have missed it, but... How would that help for poetry? There is no lesson here that I can. These seem to be free-standing virtual environment that are not attached to anything. There is no mapping between a conda virtual environment and a specific project. You always have to call a conda virtual environment by its name chosen by the user: On the other hand, poetry uses a different approach where there is no need to remember names of virtual environments. With poetry you can The design choices in the UX are very meaningful. I am not sure what kind of UX you are expecting? How to reconcile both approaches? How to modify poetry's UX so that it is possible to select the name of the virtual environment? How commands such as |
I'm not sure how relevant my experience is, but... I am just starting to try and use Poetry and I will have the same problem. I currently have all my virtualenvs in a single directory under HOME and I share my home directory across multiple environments (Windows using bash and Linux running with WSL on Windows, and even VMs) Using virtualenvwrapper it creates a .project file in each virtualenv to provide the project directory for that virtualenv. Thus virtualenvs are linked to their projects. Each virtual env is given a name during creation that can be anything because it isn't used to connect it to the project. As I have just started with Poetry, I haven't yet configured it to use VIRTUALENV_HOME yet. I wonder how much trouble that is going to create based on this issue? As an aside virtualenvwrapper uses WORKON_HOME for the venv directory. I would really like it if all tools would standardize on VIRTUALENV_HOME. Currently every tool seems to hard code the location, put it in the current project directory, or provide its own environment variable name. This means that in bashrc I have to keep setting more and more variables to point to my virtualenv dir. |
For anyone else stumbling upon this issue: One thing you can do is to not install Poetry globally, but instead install the python3 -m venv venv
. venv/bin/activate
python3 -m pip install poetry==some-version-here
poetry init # or copy a pyproject.toml file from somewhere
# edit your pyproject.toml file
poetry install # or poetry lock for only making the lock file This way you can have a named virtual environment, without having to deal with the unpredictability of Poetry's hash in the name. This is for example useful, when you want to automate things using |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature Request
Problem
People may have projects that are maintained and used on multiple computers where an according virtual env has been created for the project on every development computer.
Example:
My project is named
myproject
The project is maintained/ developed on multiple machines and on each machine
poetry install
command is executed but the developer doesn't want to store the env in the project at.venv
.Computer 1:
Project is at
/Users/user/repos/myproject
, virtual env is at/Users/user/repos/.venvs/myproject-ABC-py3.8
Computer 2:
Project is at
/Users/user/repos/myproject
, virtual env is at/Users/user/repos/.venvs/myproject-DEF-py3.8
One can see, the hashs in the env names differ!
This might be a one man show project on different computers.
In this case project settings controlling paths to dev tools are shared across the different machines.
An example is given via
myproject/.vscode/settings.json
(Visual Studio Code settings for the project)A cutout on computer 1 may look like this:
Now every time I switch to computer 2 and back I always have to manually adapt the synchronised project settings just because of the hash within the env name. That is not feasible and I never had that issue with
conda
,virtualenvwrapper
,venv
,pyenv
...Solution (feature request)
Make possible that the poetry user can customise/ control if there will be a hash in the environment name without being forced to have the env as
.venv
in the project.Every reader of this feature request
Click on the thumbs up of this initial post if you like that feature request so that it hopefully gets higher attention.
Thank you!
Jamil
Keywords for search hits:
Environment name, env name, hash, identifier, unique, customise environment name, customise env name, set environment name, set env name
The text was updated successfully, but these errors were encountered: