I like the idea though! From what I see so far the author makes a good argument for using a subshell rather than setting and resetting environment variables. At the same time though, I haven't enough experience with his suggestion yet to see the downsides... and there most definitely will be. Why? Because that's programming, man. There's no panacea, no perfect way to do things, no true "best" way to do anything.
So is this the "right" way? Probably not. Better is probably more like it and using that word instead makes you seem, you know, like not cocky asshole (not that I think that about the author at all, just generally speaking).
You clicked through to an article you wouldn't otherwise read. The meme persists because it works, and complaining about it just makes it more effective.
(I didn't click through because I don't really care if X is doing Y wrong.)
So is it possible to do something wrong, or is it only possible to do something that another person (or you) believes is not best?
"So is this the "right" way? Probably not. Better is probably more like it ..."
So this way is better, but the other way wasn't wrong? How could this way be better?
No, this is just bad. The whole paradigm of having build setup depend on local variables in an interactive shell (which is pervasive, virtualenv is hardly the only bad actor here) is just broken inherently. It's lazy programming. It creates all sorts of failure modes -- builds can magically stop working when people update their .bashrc files (e.g. set PATH explicitly, but OOPS the build system expects to source a script and then spawn you an interactive shell), etc...
Implicit configuration is bad, OK? Just don't do it.
#!/usr/bin/virtual-bash my-env
echo hello
Edit: in fact something like /usr/bin/virt-python my-env is much nicer than /var/lib/my-app/env/bin/python. Basically like virtualenvwrapper but for Python scripts that are not run interactively.https://groups.google.com/d/topic/python-virtualenv/XzI8GStv...
https://github.com/timtadh/swork
It basically figures out the pid of your shell and dumps the environment variables into a file in /tmp/swork. Then you make custom activate scripts for all of your projects. It has really helped me deal with a lot of projects. It also has convenience functions for quickly cd'ing to any project.
When you want to get back to the original configuration it simply restores the original environment vars.
$ cat run
#!/bin/sh
. venv/bin/activate
python main.py
Is this wrong? If so, what would work better?/path/to/env/bin/python main.py
will suffice. No need to create a separate shell script, start a new shell, and activate. Great for cronjobs.
I used to use `exec env $@` at the end of the script, so that I could `appenv > prod` for diffing, but I actually prefer this articles suggestion: `exec "${@:-$SHELL}"` since you can still `appenv env > prod`, but `appenv` provides an interactive shell by default.
Also, I don't like the prospect of having to hit Ctrl-D twice to logout.
The shells are actually fairly easy to recycle responsibly, it's fork()s I'm worried about.