Skip to content

Does not seem to work with Foreman .env files #28

seanbrant opened this Issue Jul 9, 2012 · 10 comments

8 participants


The docs claim that Foreman .env should work however the standard format of a .env file is KEY=VALUE pairs. It looks like autoenv just sources the .env file so these pairs are not being exported.

Am I doing something wrong or does autoenv need to be a bit smarter and know how to export these pairs?


Yea, I've had to put an export in front of each key value pair.


Same, I need to figure out why.


I believe I've figured it out. The .env is being sourced inside a function, making all it's variable appear under the function's local scope.

From what I understand, the only option in this case is eval.


For completeness, the issue here is that variable declarations and assignments don't affect the environment unless the variable was marked for export. The eval trick wouldn't have worked here (well it would've worked the same as not using eval).

uolot commented Jan 13, 2013

@igetgames I just tested the soution you provided and it works great, thanks!


Cool, glad it works for you. What system? I use it on Windows under msys, and I wanted to be sure it was portable.

uolot commented Jan 14, 2013

ElementaryOS (it's a fork of Ubuntu) + Zsh 4.3.17

ferrix commented Mar 12, 2013

Works on Debian as well.


Works on OSX too.

fcurella commented Jul 3, 2013

As of dotenv 0.8.0 (installed by foreman 0.63) the .env is required to be a list of key=values (or key: value).

I have my .env with just this:

workon myenv`

autoenv works great, but it breaks foreman with this error:

$ foreman start
/Users/flavio/Envs/myenv/gems/gems/dotenv-0.8.0/lib/dotenv/environment.rb:34:in `block in load': Line "exec `workon myenv`" doesn't match format (Dotenv::FormatError)
    from /Users/flavio/Envs/myenv/gems/gems/dotenv-0.8.0/lib/dotenv/environment.rb:27:in `each'
    from /Users/flavio/Envs/myenv/gems/gems/dotenv-0.8.0/lib/dotenv/environment.rb:27:in `load'
    from /Users/flavio/Envs/myenv/gems/gems/dotenv-0.8.0/lib/dotenv/environment.rb:23:in `initialize'
    from /Users/flavio/Envs/myenv/gems/gems/foreman-0.63.0/lib/foreman/engine.rb:172:in `new'
    from /Users/flavio/Envs/myenv/gems/gems/foreman-0.63.0/lib/foreman/engine.rb:172:in `load_env'
    from /Users/flavio/Envs/myenv/gems/gems/foreman-0.63.0/lib/foreman/cli.rb:136:in `load_environment!'
    from /Users/flavio/Envs/myenv/gems/gems/foreman-0.63.0/lib/foreman/cli.rb:38:in `start'
    from /Users/flavio/Envs/myenv/gems/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /Users/flavio/Envs/myenv/gems/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/flavio/Envs/myenv/gems/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /Users/flavio/Envs/myenv/gems/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/flavio/Envs/myenv/gems/gems/foreman-0.63.0/bin/foreman:7:in `<top (required)>'
    from /usr/local/bin/foreman:23:in `load'
    from /usr/local/bin/foreman:23:in `<main>'

A possible workaround is to create an empty .fakenv and call foreman start -e .fakeenv, but that feels wrong.

A more interesting solution would be to have autoenv honor some kind of environment variable that could have its value executed. This will allow creating a .env such as:

AUTOENV="workon myenv"

and have the virtualenv auto-activated without affecting foreman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.