[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Solving the multiarch triplet once and for all



Today in #debian-python we discussed bug #695707, which describes a breakage
in virtualenv with Python 2.7 in experimental due to multiarch.  We explored a
few approaches for fixing this, centered around patching virtualenv itself,
but none of the solutions (including the one in PAPT svn :/ ) are entirely
satisfying.  Stefano made the observation that you really want the multiarch
triplet that Python was built with, not necessarily the triplet on the host
platform its installed on, which makes sense to my limited exposure to
multiarch.

In any case, fixing this in virtualenv is both problematic and rather
shortsighted, since this problem keeps coming up again and again in other
packages.  The other complication is that you generally have to shell-out to
get the right value, calling one of the following commands:

$ dpkg-architecture -qDEB_BUILD_MULTIARCH
$ gcc --print-multiarch

Stefano brought up the inefficiencies of doing this in virtualenv's site.py
every time you fire up your venv Python.  Doko suggested globbing sys.path
entries, but that seems error-prone, and someone else seemed to remember cases
where this was tried and didn't work very well.

Wouldn't it be nice if Python just told you what the values were?

We could calculate this once during Python's build, and now all Python code
just gets it for free with a simple import.

In Python 3.3 (and beyond) we have the perfect place to stash this
information.  PEP 421's sys.implementation allows for platform-specific
values, so we can squirrel this away as e.g. sys.implementation._architecture
for example.  (The exact name can be bikeshedded to death, but re: PEP 421
must start with an underscore.)

I now have a patch/branch that does this.

lp:~barry/ubuntu/raring/python3.3/multiarch

Yes, it's against Ubuntu Raring's Python 3.3 source branch, but that's
just a copy of experimental's 3.3.0-5, and bzr+lp was the most convenient
for this little bit of afternoon skunkworks.

$ ./configure
$ make
$ ./python -c "import sys; print(sys.implementation._architecture)"
x86_64-linux-gnu

It should only be a little more difficult to backport this to Python 2.7 (I
don't personally care about <=3.2 or <=2.7, and since this is all jessie-land
stuff, y'all shouldn't either :), since there's no PEP 421 sys.implementation.
Well, we can just hold our noses and stick the same thing in sys._architecture
for 2.7.

Notice the nice way this cleans up setup.py.  Bonus!

Feedback is most definitely welcome.  If everyone thinks this is a good thing
to pursue, I can clean up the patch, back port to 2.7, and Doko can sponsor it
into experimental.

Then I think we just hack our version of virtualenv to use sys._architecture
(since it's currently a 2.x program) and we're done <wink>.

Cheers,
-Barry

Attachment: signature.asc
Description: PGP signature


Reply to: