Code Monkey home page Code Monkey logo

zsh-autoswitch-virtualenv's Introduction

Autoswitch Python Virtualenv

CircleCI Release GPLv3

zsh-autoswitch-virtualenv is a simple and quick ZSH plugin that switches python virtualenvs automatically as you move between directories.

zsh-autoswitch-virtualenv also automatically detects and activates your Pipenv and Poetry projects without any setup necessary.

How it Works

Simply call the mkvenv command in the directory you wish to setup a virtual environment. A virtual environment specific to that folder will now activate every time you enter it.

zsh-autoswitch-virtualenv will detect python projects and remind you to create a virtual environment. This mainly occurs if one of the following is found in current the directory:

  • setup.py
  • requirements.txt
  • Pipfile
  • poetry.lock

To create a virtual environment for that project, simply run mkvenv. This command works as expected for all popular python project types (virtualenvs, pipenv and poetry).

See the Commands section below for more detail.

More Details

Moving out of the directory will automatically deactivate the virtual environment. However you can also switch to a default python virtual environment instead by setting the AUTOSWITCH_DEFAULTENV environment variable.

Internally this plugin simply works by creating a file named .venv which contains the name of the virtual environment created (which is the same name as the current directory but can be edited if needed). There is then a precommand hook that looks for a .venv file and switches to the name specified if one is found.

Autoswitch virtualenv also works automatically with projects which contains a .venv virtualenv directly created by the python -m venv command.

For the case of pipenv projects, the plugin will look for a Pipfile and activates pipenv if it detects an existing virtual environment for it.

For the case of poetry projects, the plugin will look for a pyproject.toml and activates poetry if it detects an existing virtual environment for it.

NOTE: you may want to add .venv to your .gitignore in git projects (or equivalent file for the Version Control you are using).

Installing

autoswitch-virtualenv requires virtualenv to be installed. You will also need to make sure that python (without a suffix; both Python 2 and 3 are supported) is available in your $PATH.

Once virtualenv is installed, add one of the following lines to your .zshrc file depending on the package manager you are using:

ZPlug

zplug "MichaelAquilina/zsh-autoswitch-virtualenv"

Antigen

antigen bundle "MichaelAquilina/zsh-autoswitch-virtualenv"

Zgen

zgen load "MichaelAquilina/zsh-autoswitch-virtualenv"

zinit

zinit wait lucid for MichaelAquilina/zsh-autoswitch-virtualenv

oh-my-zsh

Copy this repository to $ZSH_CUSTOM/plugins, where $ZSH_CUSTOM is the directory with custom plugins of oh-my-zsh (read more):

git clone "https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv.git" "$ZSH_CUSTOM/plugins/autoswitch_virtualenv"

Then add this line to your .zshrc. Make sure it is before the line source $ZSH/oh-my-zsh.sh.

plugins=(autoswitch_virtualenv $plugins)

Manual Installation

Source the plugin shell script in your ~/.zshrc profile. For example

source $HOME/zsh-autoswitch-virtualenv/autoswitch_virtualenv.plugin.zsh

Pipenv and Poetry Integration

This plugin will also detect and auto activate virtualenvs made with pipenv or poetry. No action needs to be performed in projects where a poetry/pipenv project has already been setup.

Commands

mkvenv

Setup a new python project with autoswitching using the mkvenv helper command.

$ cd my-python-project
$ mkvenv
Creating my-python-project virtualenv
Found a requirements.txt. Install? [y/N]:
Collecting requests (from -r requirements.txt (line 1))
  Using cached requests-2.11.1-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.11.1

This command also works as expected with both poetry and pipenv.

Optionally, you can specify the python binary to use for this virtual environment

$ mkvenv --python=/usr/bin/python3

In fact any parameters passed to mkvenv will be passed to the relevant setup command. The same applies to passing additional parameters to pipenv install and poetry install.

Autoswitching is smart enough to detect that you have traversed to a project subdirectory. So your virtualenv will not be deactivated if you enter a subdirectory.

$ cd my-python-project
Switching virtualenv: my-python-project  [Python 3.4.3+]
$ cd src
$ # Notice how this has not deactivated the project virtualenv
$ cd ../..
Switching virtualenv: mydefaultenv  [Python 3.4.3+]
$ # exited the project parent folder, so the virtualenv is now deactivated

rmvenv

You can remove the virtual environment for a directory you are currently in using the rmvenv helper function:

$ cd my-python-project
$ rmvenv
Switching virtualenv: mydefaultenv  [Python 2.7.12]
Removing myproject...

This will delete the virtual environment in .venv and remove the .venv file itself. The rmvenv command will fail if there is no .venv file in the current directory:

$ cd my-non-python-project
$ rmvenv
No .venv file in the current directory!

Similar to mkvenv, the rmvenv command also works as you would expect with removing poetry and pipenv projects.

disable_autoswitch_virtualenv

Temporarily disables autoswitching of virtualenvs when moving between directories.

enable_autoswitch_virtualenv

Re-enable autoswitching of virtualenvs (if it was previously disabled).

Customising Messages

By default, the following message is displayed in bold when an alias is found:

Switching %venv_type: %venv_name [%py_version]

Where the following variables represent:

  • %venv_type - the type of virtualenv being activated (virtualenv, pipenv, poetry)
  • %venv_name - the name of the virtualenv being activated
  • %py_version - the version of python used by the virtualenv being activated

This default message can be customised by setting the AUTOSWITCH_MESSAGE_FORMAT environment variable.

If for example, you wish to display your own custom message in red, you can add the following to your ~/.zshrc:

export AUTOSWITCH_MESSAGE_FORMAT="$(tput setaf 1)Switching to %venv_name 🐍 %py_version $(tput sgr0)"

$(tput setaf 1) generates the escape code terminals use for red foreground text. $(tput sgr0) sets the text back to a normal color.

You can read more about how you can use tput and terminal escape codes here: http://wiki.bash-hackers.org/scripting/terminalcodes

Options

The following options can be configured by setting the appropriate variables within your ~/.zshrc file.

Setting a default virtual environment

You can set a default virtual environment to switch to when not in a python project by setting the value of AUTOSWITCH_DEFAULTENV to the name of a virtualenv. For example:

export AUTOSWITCH_DEFAULTENV="mydefaultenv"

Setting a default python binary

You may specify a default python binary to use when creating virtualenvs by setting the value of AUTOSWITCH_DEFAULT_PYTHON. For example:

export AUTOSWITCH_DEFAULT_PYTHON="/usr/bin/python3"

You may still override this default as usual by passing the --python parameter to the mkvenv command.

Autoswitch file name

By default, the .venv file (or virtualenv directory) is searched for in each directory in order to tell if a virtualenv should be automatically activated.

If this needs to be changed (e.g. it conflicts with something else) then it may be changed by setting the value of AUTOSWITCH_FILE. For example:

export AUTOSWITCH_FILE=".autoswitch"

Default requirements file

You may specify a default requirements file to use when creating a virtualenv by setting the value of AUTOSWITCH_DEFAULT_REQUIREMENTS. For example:

export AUTOSWITCH_DEFAULT_REQUIREMENTS="$HOME/.requirements.txt"

If the value is set and the target file exists you will be prompted to install with that file each time you create a new virtualenv.

Set verbosity when changing environments

You can prevent verbose messages from being displayed when moving between directories. You can do this by setting AUTOSWITCH_SILENT to a non-empty value.

Choosing where virtualenvs are stored

By default, virtualenvs created are placed in $HOME/.virtualenvs - which is the same location that the virtualenvwrapper package uses.

If you wish to change this to another location, simply set the value of the environment variable AUTOSWITCH_VIRTUAL_ENV_DIR.

If you wish for virtual environments to be stored within each project directory then you can set the variable to use a relative path. For example:

export AUTOSWITCH_VIRTUAL_ENV_DIR=".virtualenv"

Customising pip install invocation

By default mkvenv will install setup.py via pip in editable (i.e. development) mode. To change this set AUTOSWITCH_PIPINSTALL to FULL.

Security Warnings

zsh-autoswitch-virtualenv will warn you and refuse to activate a virtual environment automatically in the following situations:

  • You are not the owner of the .venv file found in a directory.
  • The .venv file has weak permissions. I.e. it is writable by other users on the system.

In both cases, the warnings should explain how to fix the problem.

These are security measures that prevents other, potentially malicious users, from switching you to a virtual environment you did not want to switch to.

Running Tests

Install zunit. Run zunit in the root directory of the repo.

$ zunit
Launching ZUnit
ZUnit: 0.8.2
ZSH:   zsh 5.3.1 (x86_64-suse-linux-gnu)

βœ” _check_venv_path - returns nothing if not found
βœ” _check_venv_path - finds .venv in parent directories
βœ” _check_venv_path - returns nothing with root path
βœ” check_venv - Security warning for weak permissions

NOTE: It is required that you use a minimum zunit version of 0.8.2

zsh-autoswitch-virtualenv's People

Contributors

122131 avatar adamko147 avatar afeblot avatar brendanfalk avatar camdencheek avatar diceroll123 avatar gugu avatar hauntsaninja avatar iloveitaly avatar john-sandall avatar mattwilder avatar mejituu avatar michaelaquilina avatar moha-gh avatar nogweii avatar rnc avatar shaungarwood avatar stevenxxiu avatar sungminoh avatar unixorn avatar wookayin avatar wouterweerkamp avatar yut23 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zsh-autoswitch-virtualenv's Issues

Option to store virtualenv in a project directory?

this is not an "issue" but more like a feature request.

Currently, this plugin will store all the virtualenvs in one directory no matter where the project is located. Although it doesn't cause problems in many cases, in some rare cases, it does.

  1. The same project name in different directories.
  2. Forget to "rmenv" before deleting a project directory.

As a virtualenv is meant to be an environment which is specific to a project, it would make more sense and intuitive to have virtualenvs in a project directory.
If we finish working on a project and delete the directory, the virtualenv will also be deleted automatically together.

More importantly, if we move a project directory to another computer, then the virtualenv will be shipped together with the project. I think there are so many benefits of having a vitualenv in a project directory. Why not?

Incompatible with `virtualenvs.in-project=true`

Issue Details

Operating System (uname -a)

Linux Work 5.7.10-arch1-1 #1 SMP PREEMPT Wed, 22 Jul 2020 19:57:42 +0000 x86_64 GNU/Linux

zsh version (zsh --version)

zsh 5.8 (x86_64-pc-linux-gnu)

autoswitch-virtualenv version

3.0.2

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)
git clone <this-repo> $ZSH_CUSTOM/plugins

Steps to reproduce the issue

do one of the two following commands

poetry config virtualenvs.in-project true
poetry config --local virtualenvs.in-project true
mkdir autoswich-test
cd autoswitch-test
poetry init -n
poetry install
check_venv

Output

Unable to find .venv virtualenv
If the issue persists run rmvenv && mkvenv in this directory

Then

mkvenv

Output

Installing dependencies from lock file

No dependencies to install or update

Unable to find .venv virtualenv
If the issue persists run rmvenv && mkvenv in this directory

When looking into autoswitch_virtualenv.plugin.zsh, it seems _activate_poetry only looks in {Cache}/pypoetry/virtualenvs/.

command not found: mkvenv

Issue Details

After following installation guide for oh-my-zsh (cloning repo & adding plugins in ~/.zshrc), get error:
zsh: command not found: mkvenv
Please provide the following details when opening an issue:

Operating System (uname -a)

NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"

zsh version (zsh --version)

zsh 5.4.2 (x86_64-ubuntu-linux-gnu)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

empty

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

mkvenv

gist link to your zshrc

https://gist.github.com/glebmikulko/fcce11e0c5e0778fcafc7b784d87fe61

wrong prompt with new terminal directly drop into project

Issue Details

  1. prompt/PS1 was not set when create a new term directly drop into the python project
  2. after 1, change to another folder will pop an wrong theme (default theme)

Please provide the following details when opening an issue:

Operating System (uname -a)

Mac 10.15.2

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION")
<your version here>

1.15.0

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

gist link to your zshrc

Some more Info

virtualenv will remember previous PROMPT when "activate", but theme for oh my zsh will load later:

  1. load plugin
    1.1. load autoswitch-virtualenv
    1.2. load "activate"
    1.3. virtualenv's activate remember system default PS1
  2. load theme
    2.1 theme override "activate" PS1

//work on the project
//change folder

  1. deactivate
    3.1 deactivate restore wrong PS1

Add option to disable security warnings

Issue Details

When running on Kali, the only user is root. Thus, every time an venv needs to be activated, the security warning (about weak .venv permissions) is triggered.

How can I disable this behavior ?
Is there any means to disable these security warnings ?

Please provide the following details when opening an issue:

Operating System (uname -a)

Kali 2021.1

zsh version (zsh --version) :

5.8

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION"
3.1.1

How is zsh-autoswitch-virtualenv installed?

  • oh-my-zsh

Steps to reproduce the issue

Install this on a single root user system.

Not work with Pipenv

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Darwin jina 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin18.2.0)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.8.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

# `Pipfile` exists in `my-project` directory and already create virtualenv with `pipenv shell` command.
$ cd my_project
Unable to find .venv virtualenv
If the issue persists run rmvenv && mkvenv in this directory

gist link to your zshrc

### Plugin: Python Auto Switch Virtualenv {{{
  # Automatically switch python virtualenvs as you move between directories
  # Commands: mkvenv, rmvenv
  zplug "MichaelAquilina/zsh-autoswitch-virtualenv"
### }}}

Support pyproject.toml

Issue Details

Plugin currently looks for setup.py and requirements.txt to determine if folder contains a Python project. To allow other tools besides setuptools, we can also define a pyproject.toml file for building our project.

Desired functionality: Check folder also forpyproject.toml and ask to install dependencies from that file, similar to the current behavior on setup.py. Functionality can mainly be copied from how the plugin deals with setup.py.

Note: When pip install from pyproject.toml, you cannot use -e since that requires setuptools.

when switching between different venvs the $PS1 configuration is lost

Issue Details

when I open a new terminal window the $PS1 format is

%{$fg_bold[green]%}%~%{$reset_color%}$(git_prompt_info) ⌚ %{$fg_bold[red]%}%*%{$reset_color%}
$ 

when I cd to a different directory with a different .venv, the $PS1 is changed automatically to

%m%#

Operating System (uname -a)

Linux imubit-omer 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

zsh version (zsh --version)

zsh 5.8 (x86_64-ubuntu-linux-gnu)

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION"
3.1.1

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

gist link to your zshrc

  1. open a new terminal with existing virtualenv
  2. change dir to a different venv.

Fix and clean up tests

Current ones are a bit of a mess:

βœ” chpwd functions are loaded                                                                                                                                                     
βœ” _check_venv_path with non-existent path                                                                                                                                        
βœ” _check_venv_path with no venv                                                                                                                                                  
/tmp/tmp.nGzpoHzDoe/.venv                                                                                                                                                        
βœ” _check_venv_path with existing venv
/tmp/tmp.1mBLamk93N/.venvdirectory with parent venv                                                                                                                              
βœ” _check_venv_path in subdirectory with parent venv
No .venv file in the current directory!                                                                                                                                          
βœ” rmvenv with no .venv
Using real prefix '/usr'venv                                                                                                                                                     
New python executable in /home/michael/.virtualenvs/oranges/bin/python2
Also creating executable in /home/michael/.virtualenvs/oranges/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/michael/.virtualenvs/oranges/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/michael/.virtualenvs/oranges/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/michael/.virtualenvs/oranges/bin/preactivate
virtualenvwrapper.user_scripts creating /home/michael/.virtualenvs/oranges/bin/postactivate
virtualenvwrapper.user_scripts creating /home/michael/.virtualenvs/oranges/bin/get_env_details
run:10: command not found: deactivate
AUTOSWITCH WARNING: Virtualenv will not be activated

Reason: Found a .venv file with weak permission settings (644).
Run the following command to fix this: "chmod 600 .venv"
Removing oranges...
βœ” rmvenv with existing .venv
AUTOSWITCH WARNING: Virtualenv will not be activated                                                                                                                             

Reason: Found a .venv file with weak permission settings (644).
Run the following command to fix this: "chmod 600 .venv"
Removing idontexist...
Did not find environment /home/michael/.virtualenvs/idontexist to remove.
βœ” rmvenv with existing .venv with deleted virtualenv

Does automatically deactivating venv makes sense?

The README reads:

Moving out of the directory will automatically deactivate the virtual environment.

and indeed the plugin behaves so. However, I don't agree it does make sense. For example, suppose a project is structured as follows:

.venv
REAMDE.md
my_package/__init__.py
my_package/...

The virtualenv automatically gets activated according to .venv, but whenever we enter into another directory, including its subdirectories (my_package in this example), it gets deactivated. In most of use cases, one would expect working with these subpackages should be in the same virtualenv.

What would you think of this behavior?
Thank you,

Better error message when virtualenvwrapper is not setup correctly

If virtualenvwrapper is not setup correctly, a horribly confusing message is shown to the user:

Switching virtualenv: lyst _maybeworkon:6: command not found: workon

We should detect if workon is available as a function and display a nice message explaining how to setup virtualenvwrapper if not.

stat: bad file descriptor on execution of check_venv on OS X Mojave

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Darwin lewontinmadsenlaborg.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.5.1 (x86_64-apple-darwin17.5.0)

autoswitch-virtualenv version

1.14.0

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

check_venv fails because "stat -f %u "$venv_path"" fails.

Simply doing "stat -f %u .venv" at command line gives:

stat: bad file descriptor

whereas "stat .venv" gives full output. Something is apparently different about the "stat" version syntax on newish (Mojave?) versions of OS X.

Feature: support detection of existing virtual environments for a project

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.

Is it possible to reduce 600 permission check to 644?

Issue Details

Current check for 600 permission does not add additional security and breaks some software from working (for example - ubuntu snaps and circleci local cli).

Example:

====>> Checkout code
#!/bin/sh
mkdir -p /home/circleci/project && cp -r /tmp/_circleci_local_build_repo/. /home/circleci/project
cp: cannot open '/tmp/_circleci_local_build_repo/./.venv' for reading: Permission denied
Error: Exited with code 1
Step failed
====>> Uploading test results

How important is disabling reading a file? It does not contain anything secure.

Can I create a pull request for checking only write permissions for a file?

Operating System (uname -a)

Linux andriibook 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

zsh version (zsh --version)

zsh 5.4.2 (x86_64-ubuntu-linux-gnu)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

0.3.4

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

create .venv file

gist link to your zshrc

Environment pollution

( Fedora 30 ; ZSH 5.7.1 ; Manually installed from git )

This is not an issue as such, more of a discussion :-)

Currently colours such as RED etc are defined within the file. If this is sourced then these end up within the shell environment.

I am wondering whether it might be better to wrap them inside a function (used by the other functions) to avoid these 'polluting' the parent shell environment?

Nicer output when switching between pipenvs

The current output does not look great due to the way pipenv generates unique names:

E.g.

Python project detected. Run pipenv install to setup autoswitching
Deactivating: vms-E78vNopS

does not work with pyenv

Issue Details

I'm having trouble getting this to work with pyenv. Though everything works generally, when I open a new window in an existing directory (shown as ~/Desktop/tmp in GIF), the env doesn't seem to be loading properly (see GIF below).

Operating System (uname -a)

Darwin CSchillebeeckx-0589.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

autoswitch-virtualenv version

3.1.0

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

Using pyenv 1.2.21

Untitled

Empty $LANG causes test errors

Issue Details

Tests that depend on the comparison of "Switching virtualenv: foobar [🐍Python 3.7.4]" fail when $LANG is not set (or when not supporting UTF-8).

Reason: in autoswitch_virtualenv.plugin.zsh we check for $LANG, and if it does not support UTF-* (or is not set), we remove the 🐍 from the DEFAULT_MESSAGE_FORMAT. In some of the tests however, we do not take this into consideration and simply assume 🐍 is always there, causing tests to fail.

Specifically, these tests fail:

  • plugin - switches env when .venv found
  • plugin - runs default env on load
  • _maybeworkon - switches virtualenv if current virtualenv is different
  • _maybeworkon - switches virtualenv if nothing is activated
  • check_venv - works as intended with .venv available
  • check_venv - activate if .venv unavailable but pipenv available
  • check_venv - go to default if .venv unavailable
  • check_venv - No security warning for readable only by owner permission
  • check_venv - No security warning for readable by group permission
  • check_venv - No security warning for readable by everyone permission

Solution: Remove 🐍 from the default message to avoid confusion. It is useless anyway.

Operating System (uname -a)

MacOS Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.6.2 (x86_64-apple-darwin18.0.0)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.15.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

  • Set LANG to empty
  • echo "$LANG" to check if empty
  • zunit in main folder of autoswitch
  • 10 tests fail

Tab/Window title is set incorrectly due to MYOLDPWD

This is a weird bug report, but I don't think zsh-autoswitch-virtualenv is responsible for this. Let me explain what happens:

image

As shown in the figure, the tab/window title of zsh shell reads ~MYOLDPWD (see Tab 1), which shall be a valid path, ~/.zplug/repos/sorin-ionescu/.... Please note that this feature is from prezto's terminal module (or similar plugins from zsh frameworks). MYOLDPWD is definitely a thing from zsh-autoswitch-virtualenv.

In autoswitch_virtualenv.plugin.zsh, there is a line in which an env-var MYOLDPWD is being set. However, if we remove this line, this bug doesn't happen anymore (we have the correct title)!

 # Automatically switch virtualenv when .venv file detected
 function _check_venv()
 {
     if [ "$PWD" != "$MYOLDPWD" ]; then
-       MYOLDPWD="$PWD"

        SWITCH_TO=""

I think it is very weird! One interesting thing is that if we use another name, such as FOOBAR="$PWD" or CONSTANT=1, these name occur in the tab title instead.

It's more plausible that zsh or prezto is reponsible for this behavior (maybe conflicts?), but any recent versions of them didn't resolve the issue. Maybe we could find some workaround for this bug. Any idea why it does happen?

oh-my-zsh instructions not currently working

Issue Details

Followed oh-my-zsh instructions as given in README but utils like mkvenv were not being found on PATH. Installing by sourcing the plugin directly in .zshrc does seem to work.

Please provide the following details when opening an issue:

Operating System (uname -a)

Darwin Johns-MacBook-Pro.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin18.2.0)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.10.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

git clone "https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv.git" "$ZSH_CUSTOM/plugins/autoswitch_virtualenv"

# Added this to bottom of ~/.zshrc
plugins=(autoswitch_virtualenv $plugins)

# This shows the plugin name
echo $plugins

# But mkvenv isn't found on PATH, this gives me nothing
which mkvenv

# Tried commenting out this:
plugins=(autoswitch_virtualenv $plugins)
# and adding this
source $ZSH_CUSTOM/plugins/autoswitch_virtualenv/autoswitch_virtualenv.plugin.zsh
# and everything now works as documented.

gist link to your zshrc

https://gist.github.com/john-sandall/c75fb745ff01e695b52d48b0329c5f50

Pipenv installation in 'developer/editable' mode.

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Fedora 33

zsh version (zsh --version)

5.8

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION"
3.1.1

How is zsh-autoswitch-virtualenv installed?

  • Other (please specify)

Manually using checked out repository

Steps to reproduce the issue

Currently install_requirements will install in editable mode by default. However, the pipenv block in mkvenv does not just installs in dev mode. This is a mis-match and could be solved with

diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
index 87123c1..f715ddd 100644
--- a/autoswitch_virtualenv.plugin.zsh
+++ b/autoswitch_virtualenv.plugin.zsh
@@ -294,7 +294,7 @@ function mkvenv()
             return
         fi
         # TODO: detect if this is already installed
-        pipenv install --dev $params
+        pipenv install --dev --editable $params .
         _activate_pipenv
         return
     elif [[ "$venv_type" == "poetry" ]]; then

Command not found: virtualenv_deactivate

When entering a directory with a virtualenv I created with mkvenv I get the output:

Switching virtualenv: testdir  deactivate:12: command not found: virtualenv_deactivate
[Python 2.7.14]

I have virtualenvwrapper installed and added to .zshrc with source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

Activating and deactivating the virttualenv does work.

Multiple requirements and aliased rm

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

4.20.14-200.fc29.x86_64

zsh version (zsh --version)

5.6.2

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.9.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

  1. Calls to rm are non-qualified which means that if rm is aliased (e.g. alias rm='rm -i') the script won't complete. I think they should be fully qualified i.e. /bin/rm

  2. If a repository has multiple requirements.txt - for example a top level one for runtime dependencies and one in a subdirectory for e.g. documentation generation dependencies then it will only load one. If the loop was for requirements in **/requirements.txt then it would load them all.

  3. It may be useful to give an example of how extra arguments such as mkvenv --system-site-packages ; this is extremely handy as it prevents unnecessary duplication.

autoswitch-virtualenv creates superfluous 'venv' folders

Issue Details

When using autoswitch-virtualenv with a relative AUTOSWITCH_VIRTUAL_ENV_DIR an superfluous empty venv folders are created in subfolders of the project folder. This happens when you first cd into the subfolder.

Background:
I want to make autoswitch-virtualenv behave like the 'manual' pattern often given in blog posts, with a venv folder inside each subfolder. Luckily autoswitch-virtualenv provides the AUTOSWITCH_VIRTUAL_ENV_DIR variable. Although this makes another subfolder inside venv and an additional .venv file - I can live with that ;) - the issue at hand seems like a real bug.

Operating System (uname -a)

macOS 10.15.3 (Darwin Kernel Version 19.3.0)

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

autoswitch-virtualenv version

1.16.1

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

  • add the following line to .zshrc:
    export AUTOSWITCH_VIRTUAL_ENV_DIR="./venv"
  • create a new folder with venv
    mkdir test; cd test; mkvenv
  • create a subfolder and cd into it
    mkdir subfolder; cd subfolder

gist link to your zshrc

https://github.com/StudioProcess/zsh-config/blob/master/.zshrc#L53

virtualenvwrapper required message

After upgrading from 0.2.1 to 0.3.0, I see following message when I create new shell

zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed! If this is already installed but you are still seeing this message, add the following to your ~/.zshrc:
source =virtualenvwrapper.sh

And then my virtualenvs does not switch automatically if I change directory. The problem is that required line was there even before the update and was untouched after. My virtualenvwrapper works correctly. After downgrading to 0.2.1 everything works good.

Malicious scripts in untrusted directories are executed

git clone https://github.com/saleemrashid/evil-zsh-autoswitch-virtualenv.git
cd evil-zsh-autoswitch-virtualenv
cat evil.txt

The script evil_virtualenv/bin/activate will be sourced without any user interaction, which will:

  1. Erase the "Switching virtualenv" message from the terminal (so the user isn't even aware that anything has happened)
  2. Write the output of id; ls ~ to a file called evil.txt. Obviously this would be more malicious in practice

Setup.py and development

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

4.20.14-200.fc29.x86_64

zsh version (zsh --version)

5.6.2

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.9.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • [x ] Other (please specify)

Steps to reproduce the issue

Currently can install the local repository if it sees a setup.py. I have found its more useful for development to do pip install -e .. Should this be an option as well?

Instructions and prompt integration

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Fedora 29

zsh version (zsh --version)

5.6.2

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.8.0

How is zsh-you-should-use installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify) : Manual installation from source.

Steps to reproduce the issue

gist link to your zshrc

It would be useful if it also stated normal installation procedure e.g.

source .../zsh-autoswitch-virtualenv/autoswitch_virtualenv.plugin.zsh

I also use the venv name to provide a RPROMPT upon entry into a python workspace. However for deactivation I need to unset venv_dir venv_name venv_path venv_type after the deactivate command.

osx - readme fix - brew install pyenv-virtualenvwrapper?

brew install virtualenvwrapper
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (caskroom/cask).
No changes to formulae.

Error: No available formula with the name "virtualenvwrapper"
==> Searching for a previously deleted formula...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
This similarly named formula was found:
pyenv-virtualenvwrapper
To install it, run:
brew install pyenv-virtualenvwrapper

brew install pyenv-virtualenvwrapper?

feature: Provide the option to use system packages for poetry projects

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Fedora 32

zsh version (zsh --version)

5.8

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION")
<your version here>

3.0.0

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)
    Manual checkout

Steps to reproduce the issue

Would it be feasible to integrate ideas from

and provide an option to use system packages for poetry?

gist link to your zshrc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.