A Pipenv porcelain inside Emacs.
Pipenv is a tool that aims to bring the best of all packaging worlds to the Python world. It manages virtual environments, adds and removes packages, and enables deterministic build dependencies.
pipenv.el
makes Pipenv a first-class citizen in your Emacs-driven Python development workflow with a range of interactive commands wrapping the Pipenv, a minor mode to accompany python-mode
with a keymap for the most useful commands, and a high-level pipenv-activate
/ pipenv-deactivate
interface for virtual environment integration with your Emacs session.
Contributions to documentation and code are welcome. Open an issue for discussion, or submit a PR for consideration.
pipenv.el
is available on Melpa.
pipenv.el
has been integrated in the Python layer.
Download the code with git or as a zip, and then put pipenv.el
on your Emacs load path.
Once installed, all Pipenv commands are available to be called interactively, and are prefixed with pipenv-
. To add the minor mode for buffers with a Python major mode, use (add-hook 'python-mode-hook #'pipenv-mode)
.
Here is an example of configuration with use-package
.
(use-package pipenv
:hook (python-mode . pipenv-mode)
:init
(setq
pipenv-projectile-after-switch-function
#'pipenv-projectile-after-switch-extended))
pipenv.el
wraps the majority of the Pipenv CLI. See all commands prefixed with pipenv-
after installation (M-x pipenv-
).
pipenv.el
reimplements Pipenv’s open
command in Emacs Lisp as pipenv-open
, rather than shelling out to Pipenv for the logic. This is a design decision, ensuring that modules are opened in the current Emacs session, rather than in $EDITOR
as per the Python implementation of pipenv open
.
In addition to providing the majority of Pipenv commands, there are several custom functions available in pipenv.el
. The most useful are pipenv-activate
and pipenv-deactivate
, which are used to manage the Python virtual environment for the current Emacs session.
pipenv-activate
calls pyvenv-activate
and sets the variable python-shell-virtualenv-root
to that of the Pipenv project currently being visited, and pipenv-deactivate
sets it back to the Emacs default and also calls pyvenv-deactivate
.
The Pipenv minor mode is activated for buffers with a Python major mode. The minor mode exposes a number of key bindings for pipenv.el
commands, prefixed by M-p
.
C-c C-p a
is bound topipenv-activate
C-c C-p d
is bound topipenv-deactivate
C-c C-p s
is bound topipenv-shell
C-c C-p o
is bound topipenv-open
C-c C-p i
is bound topipenv-install
C-c C-p u
is bound topipenv-uninstall
Integration with Flycheck is enabled by default, if Flycheck is installed. The integration customises Flycheck’s flycheck-executable-find
function to search for executables in an activate Pipenv virtual environment.
Disable Flycheck integration with:
(setq pipenv-with-flycheck nil)
Integration with Projectile is enabled by default, if Projectile is installed. The integration adds a hook to projectile-after-switch-project-hook
, being pipenv-projectile-after-switch-function
, which can be customized.
Disable Projectile integration with:
(setq pipenv-with-projectile nil)
The default value for pipenv-projectile-after-switch-function
is the function pipenv-projectile-after-switch-default
, which simply activates the Pipenv virtual environment, if a Pipenv project is detected.
You can set your own function to pipenv-projectile-after-switch-function
to customise this behaviour. An example function for this is included, called pipenv-projectile-after-switch-extended
, which, in addition to setting the virtual environment, opens a Pipenv shell, and opens a Python interpreter with run-python
.
(setq pipenv-projectile-after-switch-function #'pipenv-projectile-after-switch-extended)
pipenv.el
relies on pyvenv to switch between different virtual environments (pipenv-activate
and pipenv-deactivate
).