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

[Feature] Command to move project folder, and command to scan for and remove orphaned virtualenvs #4934

Open
Arcitec opened this issue Jan 27, 2022 · 3 comments
Labels
Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. Type: Enhancement 💡 This is a feature or enhancement request.

Comments

@Arcitec
Copy link

Arcitec commented Jan 27, 2022

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>

  1. 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.
  2. 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).
  3. Next, update anything inside the virtualenv folder that needs to be updated (at least .project, and the absolute path to the venv inside bin/activate script, and maybe more). If any of these edits fail, rollback everything.
  4. 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

  1. Scan every environment in ~/.local/share/virtualenvs/.
  2. Look at their .project file (which contains the path to the project folder).
  3. 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.

@matteius matteius added the Type: Enhancement 💡 This is a feature or enhancement request. label Jan 27, 2022
@oz123
Copy link
Contributor

oz123 commented Jan 28, 2022

Sound like a good feature. Just make sure to use shutil.move instead of os.rename.

@rob-hills
Copy link

I agree both of these proposed commands would be extremely useful.

@v3ss0n
Copy link

v3ss0n commented Feb 9, 2023

that is the problem i face as soon as i used pipenv. Any work around?

@matteius matteius added the Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. label Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. Type: Enhancement 💡 This is a feature or enhancement request.
Projects
None yet
Development

No branches or pull requests

5 participants