Skip to content

Latest commit

 

History

History
109 lines (64 loc) · 5.03 KB

README.org

File metadata and controls

109 lines (64 loc) · 5.03 KB

pipenv.el

https://circleci.com/gh/pwalsh/pipenv.el.svg?style=svg

https://melpa.org/packages/pipenv-badge.svg

A Pipenv porcelain inside Emacs.

Overview

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.

Contributing

Contributions to documentation and code are welcome. Open an issue for discussion, or submit a PR for consideration.

Installation

Melpa

pipenv.el is available on Melpa.

Spacemacs

pipenv.el has been integrated in the Python layer.

Manual

Download the code with git or as a zip, and then put pipenv.el on your Emacs load path.

Configuration

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))

Features

Pipenv coverage

pipenv.el wraps the majority of the Pipenv CLI. See all commands prefixed with pipenv- after installation (M-x pipenv-).

pipenv open

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.

Activate and Deactivate

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.

Minor mode

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 to pipenv-activate
  • C-c C-p d is bound to pipenv-deactivate
  • C-c C-p s is bound to pipenv-shell
  • C-c C-p o is bound to pipenv-open
  • C-c C-p i is bound to pipenv-install
  • C-c C-p u is bound to pipenv-uninstall

Integrations

Flycheck

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)

Projectile

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)

Pyvenv

pipenv.el relies on pyvenv to switch between different virtual environments (pipenv-activate and pipenv-deactivate).