Skip to content

Per-project environments for Conda, Julia, Perl, Python, Rust, and more

Notifications You must be signed in to change notification settings

ajmazurie/oh-my-dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

oh-my-dir

oh-my-dir is a set of configuration files for direnv that add high-level functions to create isolated, per-directory virtual environments for various software stacks such as programming languages and package managers.

oh-my-dir automatically set up your stack(s) whenever you enter your project directory, taking care of several otherwise time consuming steps:

  1. Installation of a stack-specific manager (if not already present)
  2. Installation of the requested version of the stack (if not already present)
  3. Creation of a named environment (if not already present)
  4. Modification of environment variables to use this stack and environment

If you are familiar with tools such as virtualenv, rbenv or perlbrew then oh-my-dir is a higher-level environment manager. In fact, it probably uses these tools behind the scene.

Installation

There are only three steps involved in the installation of oh-my-dir:

  1. Install direnv if not done already (various platform-specific binaries are available)
  2. Download and unzip the latest archive from the oh-my-dir repository, or clone it
  3. Once in the oh-my-dir source folder, run make install

Note: make install will overwrite any existing ~/.direnvrc file; if you want to manually merge your file with the oh-my-dir functions, you can run make build instead and copy all or part of the newly created file dist/direnvrc in your existing ~/.direnvrc.

Quickstart

  1. In your project directory, create a .envrc file with your favorite editor and add one or more use stack instructions, with stack being the name of the stack optionally followed by a version number and an environment name (not all stacks support these options; please refer to the table in the last section).
  2. Then tell direnv to use your file by typing direnv allow, and oh-my-dir will switch to your stack and environment (or install/create it if needed).

Note: a shortcut to the .envrc editing/allow cycle is to type direnv edit ., which will launch $EDITOR and automatically allow the resulting content.

For example if you want your project to use the version 2.7.10 of the Python interpreter just add use python 2.7.10 in your <project>/.envrc file. oh-my-dir will check (and install if needed) for a Python-specific manager (here pyenv), the specified version of the Python interpreter, and an environment named default in <project>/.env/ (default name for the environment if none provided). The relevant environment variables will be set for you to use this named environment:

$ cd my_project
$ direnv edit .  # added 'use python 2.7.10'
direnv: loading ~/.direnvrc                                                                         
direnv: loading .envrc
direnv: using python 2.7.10
preparing Python environment 'default'
New python executable in my_project/.env/pyenv-2.7.10-default/bin/python2.7
Also creating executable in my_project/.env/pyenv-2.7.10-default/bin/python
Installing setuptools, pip, wheel...
done.
direnv: export +PYENV_ROOT +PYENV_VERSION +PYENV_VIRTUALENV_DISABLE_PROMPT +VIRTUAL_ENV ~PATH
$ which python
my_project/.env/pyenv-2.7.10-default/bin/python

Note: while creating your environment direnv will likely complain that its initialization take too long, with a message such as direnv is taking a while to execute. Use CTRL-C to give up, which you can safely ignore.

If you want to maintain (and automatically switch to) multiple named environments in your project, just add a name (e.g., use python 2.7.10 production).

Note: the various oh-my-dir functions will use (and create if needed) a ~/.direnv folder to store the stack-specific managers, and a <project>/.env folder to store the various named environments you created.

Supported stacks

Stack Underlying
manager
Enforce
stack version?1
Allow named
environments?2
Relocatable?3 Supported
platforms
Status
Docker machine n/a ✔️ n/a Unix, OSX Stable
Julia playground.jl ✔️ ✔️ untested Unix, OSX Beta
Perl perlbrew ✔️ ✔️ untested Unix, OSX Stable
Python pyenv ✔️ ✔️ Unix, OSX Stable
Rust rsvm ✔️ ✔️ Unix, OSX Stable
Conda n/a ✔️ Unix, OSX Beta

1: means that the underlying manager can switch to, and install if necessary, a specific version of the stack

2: means that the underlying manager can switch to, and created if necessary, a named environment for the current stack and version

3: means that the project folder can be safely moved elsewhere without breaking the environments

About

Per-project environments for Conda, Julia, Perl, Python, Rust, and more

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published