Skip to content

Commit

Permalink
Merge pull request pypa#393 from qwcode/64bit
Browse files Browse the repository at this point in the history
64bit test that works for py25 as well.
  • Loading branch information
qwcode committed Jan 30, 2013
2 parents 49f4012 + b5811a7 commit 5c85788
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions tests/test_virtualenv.py
Expand Up @@ -121,3 +121,15 @@ def test_install_python_bin():
"exist in bin_dir" % pth)
finally:
shutil.rmtree(tmp_virtualenv)

def test_64bit_technique():
"""
Confirm the technique for determining 64bit in the embedded site.py
is returning an expected answer
"""
import struct
assert (
struct.calcsize("P") == 8 #64bit
or
struct.calcsize("P") == 4 #32bit
)
14 changes: 8 additions & 6 deletions virtualenv_embedded/site.py
Expand Up @@ -64,6 +64,7 @@
"""

import sys
import struct
import os
try:
import __builtin__ as builtins
Expand All @@ -83,6 +84,7 @@
USER_SITE = None
USER_BASE = None

_is_64bit = struct.calcsize("P") == 8
_is_pypy = hasattr(sys, 'pypy_version_info')
_is_jython = sys.platform[:4] == 'java'
if _is_jython:
Expand Down Expand Up @@ -236,9 +238,9 @@ def addsitepackages(known_paths, sys_prefix=sys.prefix, exec_prefix=sys.exec_pre
os.path.join(prefix, "lib", "site-python"),
os.path.join(prefix, "python" + sys.version[:3], "lib-dynload")]
lib64_dir = os.path.join(prefix, "lib64", "python" + sys.version[:3], "site-packages")
if (os.path.exists(lib64_dir) and
if (os.path.exists(lib64_dir) and
os.path.realpath(lib64_dir) not in [os.path.realpath(p) for p in sitedirs]):
if sys.maxsize > 2**32:
if _is_64bit:
sitedirs.insert(0, lib64_dir)
else:
sitedirs.append(lib64_dir)
Expand Down Expand Up @@ -580,7 +582,7 @@ def virtual_install_main_packages():
hardcoded_relative_dirs = paths[:] # for the special 'darwin' case below
lib64_path = os.path.join(sys.real_prefix, 'lib64', 'python'+sys.version[:3])
if os.path.exists(lib64_path):
if sys.maxsize > 2**32:
if _is_64bit:
paths.insert(0, lib64_path)
else:
paths.append(lib64_path)
Expand All @@ -594,7 +596,7 @@ def virtual_install_main_packages():
except AttributeError:
# This is a non-multiarch aware Python. Fallback to the old way.
arch = sys.platform
plat_path = os.path.join(sys.real_prefix, 'lib',
plat_path = os.path.join(sys.real_prefix, 'lib',
'python'+sys.version[:3],
'plat-%s' % arch)
if os.path.exists(plat_path):
Expand Down Expand Up @@ -626,14 +628,14 @@ def force_global_eggs_after_local_site_packages():
maintains the "least surprise" result that packages in the
virtualenv always mask global packages, never the other way
around.
"""
egginsert = getattr(sys, '__egginsert', 0)
for i, path in enumerate(sys.path):
if i > egginsert and path.startswith(sys.prefix):
egginsert = i
sys.__egginsert = egginsert + 1

def virtual_addsitepackages(known_paths):
force_global_eggs_after_local_site_packages()
return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
Expand Down

0 comments on commit 5c85788

Please sign in to comment.