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: support detection of existing virtual environments for a project #140

Open
LordFlashmeow opened this issue Aug 8, 2020 · 5 comments

Comments

@LordFlashmeow
Copy link

I use pycharm for development, so my virtual environments are created automatically when I make a new project. It would be really convenient if there was a function—maybe addvenv which created the .venv file instead of prompting to create a whole new virtual environment.

I know I can make the file myself, but it seems a little odd that the plugin is smart enough to detect a virtualenv, but won't allow you to add it.

@MichaelAquilina
Copy link
Owner

Hi there! I don't use pycharm so I'm not very aware of how it creates/stores its virtualenvs.

Would you mind providing some information about the virtualenvs it creates? The following would definitely be useful:

  • Name of the virtual environment in relation to the project / directory
  • Location of the virtual environment on the file system

@MichaelAquilina MichaelAquilina changed the title Add support for existing virtual environments Feature: support detection of existing virtual environments for a project Aug 9, 2020
@LordFlashmeow
Copy link
Author

LordFlashmeow commented Aug 10, 2020

With pycharm, the default is to create the virtual environment in a folder named venv (although it can be changed to whatever). Inside the venv folder, there is not a folder with the project name, only the venv files.

For example:

$ tree -L 2
.
├── main.py
└── venv
    ├── bin
    ├── include
    ├── lib
    ├── pyvenv.cfg
    ├── share
    └── src

When running mkvenv with AUTOSWITCH_VIRTUAL_ENV_DIR="venv", this is the directory structure I end up with where test was the name of the folder I made the venv in:

$ tree -L 3
.
├── main.py
└── venv
    └── test
        ├── bin
        ├── lib
        └── pyvenv.cfg

@escaped
Copy link

escaped commented Sep 2, 2020

I kind of have the same issue as I use python -m venv .venv instead of creating the environment using virtualenv. To support this, we could "simply" check whether $AUTOSWITCH_FILE is already a virtual environment (eg. does ${venv_path}/bin/activate exists or similar). If it is, we can simply load it by running source .venv/bin/activate and use deactivate to disable it again, once we leave the directory.

As a workaround, I currently use https://github.com/RobertDeRose/virtualenv-autodetect, but I would prefer using this plugin as it supports poetry and pipenv. 👍

@afeblot
Copy link
Contributor

afeblot commented Feb 25, 2022

@MichaelAquilina, if I spend time trying to implement @escaped request and submit a PR, will you consider it, or is this something you don't want to see implemented in your script because it alters its current logic?

@MichaelAquilina
Copy link
Owner

@afeblot feel free to open a PR :) At the very least it provides us a better way of discussing the changes while also providing a branch for other users to test it out

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

No branches or pull requests

4 participants