Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upremove virtualenv usage from mach, pep-370 is fine #11060
Conversation
highfive
commented
May 6, 2016
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
May 6, 2016
|
Heads up! This PR modifies the following files:
|
|
r? @frewsxcv |
highfive
commented
May 7, 2016
|
New code was committed to pull request. |
|
huh, an interesting breaking of trevis since it already uses a virtualenv (facepalm) |
highfive
commented
May 7, 2016
|
New code was committed to pull request. |
highfive
commented
May 7, 2016
|
New code was committed to pull request. |
1 similar comment
highfive
commented
May 7, 2016
|
New code was committed to pull request. |
|
Nice hack to use PYTHONUSERBASE. I may have to steal that idea. One of the nice things you lose by not using the virtualenv is you don't get pip and a nice Aside from concerns that this sacrifices isolation, I like. |
|
setting up PYTHONUSERBASE is just a one liner the same as activating the virtualenv. then you have the shell and pip. isolation: setting up PYTHONUSERBASE makes that path come before the system site-packages, and if you invoke |
|
if {when :)} the appveyor test passes, I'd like to squash those travis commits, and add small modification to |
| @@ -6,7 +6,11 @@ | |||
| # The beginning of this script is both valid shell and valid python, | |||
| # such that the script starts with the shell and is reexecuted with | |||
| # the right python. | |||
| '''which' python2.7 > /dev/null && exec python2.7 "$0" "$@" || exec python "$0" "$@" | |||
| '''true' | |||
| HERE=`readlink -f $0` | |||
This comment has been minimized.
This comment has been minimized.
frewsxcv
May 7, 2016
Member
This doesn't work for me on OSX:
coreyf@frewbook-pro ~/D/r/servo (remove-virtualenv-from-mach) [1]> ./mach build -d
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname path
This comment has been minimized.
This comment has been minimized.
gdamjan
May 7, 2016
Author
hm, I can make it simpler, I could use $PWD/python/_virtualenv or just remove the readlink altogether.
I've used the readlink/dirname recipe to find the absolute real directory where servo source code is.
$PWD would work if people only ever run ./mach from the source dir.
|
Related issue: #9046 |
|
Regarding isolation, the system site-packages will still be on sys.path. This can be problematic for a number of reasons. To understand why, we need to understand what happens when Python starts. When a Python process starts, it implicitly does an
Sadly, the built-in virtualenv works around this limitation by - get this: installing its own Anyway, my recollection is the path to The important takeaway is that by creating a new If you don't want to create your own The tl;dr is you can't easily isolate from the system |
|
All that being said, Firefox's |
use pep-370 and PYTHONUSERBASE env variable instead ./mach is modified so it sets PYTHONUSERBASE to python/_virtualenv also, it tries to import mach.main and if that fails it'll invoke pip install. when that finishes it re-execs itself (otherwise python won't pick up the PYTHONUSERBASE as a library path). all of the virtualenv supporting code is removed from python/mach_bootstrap.py Why: virtualenv is an ugly hack, it depends on a copy of the `python` executable, is very fragile, and also makes non-relocatable environments. pep-370 and PYTHONUSERBASE fix all of those, and is officially supported by the python interpreter.
highfive
commented
May 7, 2016
|
New code was committed to pull request. |
|
@indygreg I'm nost sure what situation you're thinking can get to conflicts? using
Now I agree this change would be a bit controversial. But "just use virtualenv" is not as harmless as it sounds. I'm on several python related irc channels, and virtualenv is incredibly common pain point cause it breaks badly as soon you have a bit more complicated python situation (not to mention upgrades of the system python). Even this PR was motivated because a person had these problems on #servo irc channel. |
|
I'm not sure if this is the proper place to start this discussion, but I don't think this would be a good change to make. Virtualenvs don't actually contain a copy of your system python, but a symlink to them (at least on unixes, not sure about what it does on Windows), and while it's true that you can't simply relocate a virtualenv by moving the directory somewhere else, relocating it is just a matter of Also, there's a certain advantage to not relying on environment variables, which are simply extra state. If you use a virtualenv, you can be sure that whenever you run PEP 370 is 8 years old now, and while some people (myself included) do use |
Do you remember which issue with virtualenv they were encountering? |
that's called cargo cult programming :)
there are some copies, and some symlinks. bin/python is a hard link or a copy (in the case when the virtualenv and /usr are on different filesystems).
well, the activate thing from virtualenv is the same thing - also doesn't make any difference for
what are those? |
|
@frewsxcv to be honest, I'm somewhat active on #python on freenode, and virtualenv is way more often a solution to someone's problem than it is the problem itself.
That's not really true. In the software world, the community is important, specially in open source. It's better if we use tools most people are familiar with, instead of fiddling with environment variables. Most experienced Python programmers know about it, and they don't use it.
bin/python is a symlink on Linux, at least. I think it's libraries that are hard links.
You don't have to use activate. afaik mach does not use it. You do have to set the environment variables if you use PYTHONUSERBASE |
it's a copy on Arch, Ubuntu 16.04 and Debian Jessie (standard distro virtualenv). at 4mb even.
it activates it by itself (look at the monstrocity that mach_bootstrap.py is) Anyway, |
|
@gdamjan I'm aware that some things are done suboptimally in mach_bootstrap. Some of them are due to the design and limitations of mach, and some of them could be improved. It's something I plan to work on. It's not really relevant, but on arch: |
and where is that |
|
@gdamjan it's on
Notice the inodes are different. My bad, you are right, python2 and python on the virtualenv just point to python2.7 in the virtualenv, which is indeed a copy. |
I asked this because I don't think there are any issues with virtualenv for Servo. From what I can tell, this pull request is trying to solve a problem that doesn't exist. The only legitimate issues surrounding virtualenv that I know of are related to handling of spaces and unicode characters in paths. |
|
@frewsxcv I don't know what the source issue was, and I don't think the person even found out in the end. |
|
I believe it was http://logs.glob.uno/?c=mozilla%23servo&s=6+May+2016&e=6+May+2016#c424332 |
|
The root cause of dherman's issue is that there was a |
|
|
|
We need to make a decision here. |
|
I believe that we are not ready to make this move at this time. We've only had two types of virtualenv issues:
Given the additional analysis in this thread, I'm not convinced that this change would solve any issues that our developers are hitting today, and it risks hitting on new failure paths. @gdamjan, thanks for opening this so that we could have the discussion! We may revisit this later as we continue to change our build tools stack. |
gdamjan commentedMay 6, 2016
•
edited by larsbergstrom
use pep-370 and PYTHONUSERBASE env variable instead
./mach is modified so it sets PYTHONUSERBASE to python/_virtualenv
also, it tries to import mach.main and if that fails it'll invoke
pip install. when that finishes it re-execs itself (otherwise python won't pick
up the PYTHONUSERBASE as a library path).
all of the virtualenv supporting code is removed from python/mach_bootstrap.py
Why:
virtualenv is an ugly hack, and most of the times a pain. it depends on a copy of the
pythonexecutable, isvery fragile, and also makes non-relocatable environments.
pep-370 and PYTHONUSERBASE fix all of those, and is officially supported by the
python interpreter.
This change is