• Stars
    star
    124
  • Rank 282,080 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An unintrusive environment manager

quickenv: An unintrusive environment manager

direnv is a manager for loading/unloading environment variables per-project. It achieves this by hooking into your shell and executing a shellscript called .envrc upon cd, loading environment variables generated by that shellscript into your current shell. It is useful for automatically activating virtualenvs, for example.

Unfortunately direnv can be a little bit "intrusive" to use. For a start, it runs its own code in your shell. This alone is not noticeable in terms of terminal responsiveness, but the various .envrcs that people end up writing sometimes are. direnv does not have a reliable, out-of-the-box way to cache the execution of .envrcs, as it is arbitrary code, and so it runs everytime you cd in and out of a project.

quickenv is a replacement for direnv. It works with existing .envrcs, and as such is a drop-in replacement, but how you interact with quickenv and how it loads environment variables is fundamentally different.

  • quickenv does not hook into your shell. It only requires an addition to your PATH.
  • quickenv does not load .envrc when changing directories. Instead you need to initialize quickenv per-project using quickenv reload, and rerun that command everytime the .envrc changes.
  • quickenv does not even load environment variables into your shell. Instead it creates shim binaries that dispatch to the right executable.

quickenv is heavily inspired by volta which achieves version management for nodejs by also providing "shim" binaries for the most common commands (yarn, npm, node).

Installation

quickenv is work in progress. that said, I use it daily at work

Download the latest binary and:

# Into your bashrc/zshrc. This should be at the front of your PATH, such that
# quickenv can shim/shadow binaries effectively.
export PATH=$HOME/.quickenv/bin/:$PATH

# You can remove "direnv hook" from your bashrc/zshrc, but the tool needs to
# stay installed.

Some notes:

  • quickenv currently assumes direnv is in your path, in order to load its "standard library".

  • quickenv also currently does not have pre-built binaries. You need to install Rust and install it using Rust's package manager, Cargo.

  • quickenv assumes a POSIX environment.

Installation from source

cargo install quickenv  # latest stable release
cargo install --git https://github.com/untitaker/quickenv  # latest git SHA

Usage

We're going to check out sentry, because that's one of the .envrcs I use. Note that Sentry's .envrc only works on MacOS.

git clone https://github.com/getsentry/sentry
cd sentry

# Execute the .envrc and cache the resulting environment variables in ~/.quickenv/envs/.
# Sentry will prompt you to create a virtualenv, install dependencies via homebrew, etc.
# Re-run this command manually everytime the .envrc changes.
quickenv reload

# As part of executing the .envrc, a virtualenv has been created at './.venv/'.
# There are multiple commands available in '.venv/bin/', such as 'pytest' (a test
# runner), or 'sentry' (the main application).

# 'quickenv shim' makes those commands available in your shell.
quickenv shim

# These commands will now run with the virtualenv enabled.
sentry devserver --workers
pytest tests/sentry/

Advanced usage

# Alternatively you can shim commands explicitly. Be careful: Any command you
# missed (such as 'python' or 'pip') would run outside of the virtualenv!
quickenv shim sentry pytest

# You can also run commands within the current .envrc without shimming them.
quickenv exec -- pytest

# Your git hooks don't execute in the virtualenv for some reason? Just replace
# git with a binary that itself loads the virtualenv.
quickenv shim git

# Actually activate the virtualenv in your current shell. `quickenv vars`
# prints all the extra environment variables with which each shimmed binary runs.
set -o allexport
eval "$(quickenv vars)"
set +o allexport

# Or alternatively, substitute your shell with one where your .envrc is loaded
exec quickenv exec $SHELL

# Or shim 'bash', so that when you open a subshell, the virtualenv is activated.
quickenv shim bash

# Or shim 'make', so your Makefile runs in the virtualenv.
quickenv shim make

# Curious which binary is actually being executed?
quickenv which make
# /home/user/.quickenv/bin/make

# Or for general debugging, increase the log level:
QUICKENV_LOG=debug make
# [DEBUG quickenv] argv[0] is "make"
# [DEBUG quickenv] attempting to launch shim
# [DEBUG quickenv] abspath of self is /home/user/.quickenv/bin/make
# [DEBUG quickenv] removing own entry from PATH: /home/user/.quickenv/bin
# [DEBUG quickenv] execvp /usr/bin/make
# ...

License

Licensed under MIT, see LICENSE.

More Repositories

1

python-atomicwrites

Powerful Python library for atomic file writes.
Python
315
star
2

html5gum

A WHATWG-compliant HTML5 tokenizer and tag soup parser
Rust
137
star
3

hyperlink

Very fast link checker for CI.
Rust
112
star
4

mysteryshack

A remoteStorage-server
Rust
112
star
5

rust-atomicwrites

Atomic file-writes.
Rust
81
star
6

spacemod

A easy to understand and powerful text search-and-replace tool
Rust
39
star
7

mastodon-bookmark-rss

A small app to let you connect your mastodon bookmarks to your RSS reader.
Rust
22
star
8

script-macro

Write simple proc-macros inline with other source code.
Rust
19
star
9

pytest-subtesthack

A hack to explicitly set up and tear down fixtures.
Python
17
star
10

shippai

Use Rust failures as Python exceptions
Python
16
star
11

rust-vobject

VObject parser and generator for Rust
Rust
15
star
12

pytest-fixture-typecheck

A pytest plugin to assert type annotations at runtime.
Python
12
star
13

python-sensitive-variables

strip local variables in tracebacks
Python
10
star
14

watdo

ABANDONED -- A task-manager for the command line.
Python
8
star
15

in-app-browser-framebreaker

HTML
6
star
16

taskrs

A tasks app
JavaScript
6
star
17

iron-login

ABANDONED Basic session management in Iron.
Rust
6
star
18

uberspace-deploy-scripts

Some deployment scripts for uberspace.de
Python
3
star
19

sentry-toolz

Python
3
star
20

python-structural-matching-benchmarks

Python
2
star
21

vdir

2
star
22

dotfiles

My dotfiles
Vim Script
2
star
23

rust-webicon

Favicon and apple-touch-icon scraper for Rust
Rust
2
star
24

fdwalk

Rust
2
star
25

memoria

A bad memory "profiler" for production.
Rust
2
star
26

facebook-delete-messages

Userscript for Facebook Messages to replace the archive button with a delete button. Based on http://userscripts.org/scripts/show/106261
JavaScript
1
star
27

bottom-import-demo

Python
1
star
28

diyrss

A simple feed generator website
Python
1
star
29

quicktype-markdown

Generate Markdown documentation from JSON schema, powered by quicktype
JavaScript
1
star
30

aoc2020

Python
1
star
31

firefox2pass

Migrate passwords from Firefox to passwordstore
Python
1
star
32

python-move-semantics

Python
1
star
33

gitgone

Rust
1
star
34

rust-fake-yield

Simple generators in Rust
Rust
1
star
35

untitaker

1
star
36

maildropper.py

Easy to use mail delivery agent
Python
1
star
37

serde-annotated

Rust
1
star