-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Pipenv currently places all virtualenvs in ~/.local/share/virtualenvs/
within folders named after the hashed project path. This is great, since it ensures that the per-platform libraries in your virtualenvs aren't incorrectly shared or included in VCS by beginners. Experts can of course change the venv location manually.
However, the (good) default behavior leads to a lot of orphans if you delete, rename or move the project folders. And since pipenv is responsible for creating this situation, it is appropriate for it to take responsibility for all the orphans it's creating, since it's a heavy mind burden for users to try to manually clean the virtual environments.
I propose two commands to fix this situation.
pipenv move-project <oldpath> <newpath>
- Attempt to
shutil.move()
the project path. If it fails, such as due to Windows "file open/in use" errors, simply rollback the change and stop here. - If the project folder was successfully renamed, then rename the virtualenv to the new hashed location. If it fails, then rollback the entire process (move virtualenv and project back to their old locations).
- Next, update anything inside the virtualenv folder that needs to be updated (at least
.project
, and the absolute path to the venv insidebin/activate
script, and maybe more). If any of these edits fail, rollback everything. - Display the results to the user. Either the move of both folders and the file-edits succeeded, or something failed and everything was rolled back.
pipenv remove-orphans
- Scan every environment in
~/.local/share/virtualenvs/
. - Look at their
.project
file (which contains the path to the project folder). - If the path cannot be found on disk, ask the user
Do you want to remove the venv for "/home/foobar/projects/old-project"? [N/y]
(it's important that it's no by default since the path may simply be on a disk that's not yet mounted).
These two features would make pipenv a much "cleaner" tool. It wouldn't be such a hassle to move projects to new/renamed folders anymore, and any remaining orphans could be cleaned up manually.