rafi / workon-py

Simple pipenv alternative. Work and create python virtualenvs in a central directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

workon-py

Simple pipenv bash alternative, virtual-environment management helper.

Work and create python virtualenvs in a central directory, use sub-shell for activation and run arbitrary commands in envs.

workon-py visual demo

Install

Before, make sure you're using Python 3 and/or have virtualenv installed.

On macOS, you can simply use brew: brew install rafi/tap/workon-py

Otherwise, change directory to installation location, for example ~/.local/bin:

$ cd ~/.local/bin
$ curl -L https://github.com/rafi/workon-py/tarball/master | tar zx --strip-components=1

See shell completion for helpful shell completions.

Usage

usage: workon [arguments] <virtualenv>

arguments:
  -c, --create           create and activate a new virtualenv
      --no-install       when creating, don't install requirements
  -d, --delete           Delete virtualenv
  -r, --run <cmd>        Run a binary from virtualenv
  -h, --help             show this help message and exit

environment variables:
  WORKON_HOME            Path to create venvs, default: ${XDG_DATA_HOME}/python/envs
  WORKON_VIRTUALENV      Optional, set specific virtualenv path
                         Leave empty for interactive selection.

Examples

Create a New Virtualenv

To create a new virtualenv, use -c, you will be prompted which virtualenv to use, if more than one version is found:

$ workon -c foobar

1) python3 -m venv                3) /usr/local/bin/virtualenv
1) /usr/local/bin/virtualenv-3.7  4) /usr/local/bin/virtualenv-2.7
 :: Select virtualenv program to use:

Create a Unique Project Virtualenv

You can use paths when creating a new virtualenv, e.g.:

cd myproject
workon -c .

This will create a unique virtualenv name with the crc32 of path, i.e. myproject-8bfb376d.

Activate an Existing Virtualenv

Provide the name of a virtualenv, or without arguments and fzf/fzy will be used to interactively select a virtual-environment.

workon foobar

To deactivate, simply type exit or hit Ctrl+d

Run Arbitrary Commands

You can run "one-off" commands within the virtualenv's binary directory, for example list all pip installed packages:

workon -r myproject pip list

Shell Completion

bash

Add the completion script to your .bash_profile or .bashrc:

source "$HOME/.local/bin/workon-completion.bash"

zsh

None available currently, pull-requests are welcomed.

Similar Projects

License

Copyright (C) 2015-2019 Rafael Bodill

Distributed under the GNU General Public License, version 2.0.

About

Simple pipenv alternative. Work and create python virtualenvs in a central directory


Languages

Language:Shell 100.0%