Skip to content

Commit

Permalink
added workaround for corrupted lib directory
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Mar 8, 2015
1 parent f9bd549 commit ab8fede
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contents:
indexes
inheritance
versions
caveats


Indices and tables
Expand Down
25 changes: 25 additions & 0 deletions scripts/uranium
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,35 @@ def _install_virtualenv(install_dir):
'--no-site-packages',
'--always-copy',
install_dir])
site_py_file = _get_site_file_path(install_dir)
_inject_to_site_py(site_py_file)
finally:
shutil.rmtree(temp_dir)


def _get_site_file_path(venv_directory):
executable = os.path.join(venv_directory, 'bin', 'python')
return subprocess.check_output(
[executable, "-c", "import site; print(site.__file__)"]
# we strip the last character because it is a .pyc file.
# want the .py
)[:-2]


def _inject_to_site_py(site_py_file):
"""
we inject modifications to the site.py
"""
with open(site_py_file, 'a') as fh:
fh.write("""
# reshuffling the paths to ensure that distributions in the sandbox
# always come first
paths_to_append = [p for p in sys.path if p.startswith(sys.real_prefix)]
sys.path = [p for p in sys.path if not p.startswith(sys.real_prefix)]
sys.path += paths_to_append
""".strip())


def _install_uranium(virtualenv_dir, uranium_dir=None, version=None):
if uranium_dir:
uranium_dir = os.path.expanduser(uranium_dir)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]

setup(name='uranium',
version='0.0.63',
version='0.0.64',
description='a build system for python',
long_description='a build system for python',
author='Yusuke Tsutsumi',
Expand Down
8 changes: 5 additions & 3 deletions uranium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from virtualenv import make_environment_relocatable
from .uranium import Uranium
from .virtualenv_manager import (
install_virtualenv, inject_into_activate_this
install_virtualenv, inject_into_activate_this,
inject_sitepy
)
from .config import Config
from .activate import generate_activate_this
Expand All @@ -43,7 +44,7 @@ def main(argv=sys.argv[1:]):

with in_virtualenv(uranium_dir):
uranium.run()
_inject_activate_this(uranium_dir, uranium)
_inject_uranium_into_venv(uranium_dir, uranium)


def _get_uranium(uranium_file):
Expand All @@ -68,9 +69,10 @@ def in_virtualenv(path):
make_environment_relocatable(path)


def _inject_activate_this(uranium_dir, uranium):
def _inject_uranium_into_venv(uranium_dir, uranium):
content = generate_activate_this(uranium)
inject_into_activate_this(uranium_dir, content)
inject_sitepy(uranium_dir)


def _activate_virtualenv(uranium_dir):
Expand Down
25 changes: 24 additions & 1 deletion uranium/virtualenv_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
import os
import re
import subprocess
from virtualenv import create_environment

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -38,6 +39,14 @@ def is_virtualenv(path):
{0}
""".format(INJECT_WRAPPER)

SITE_PY_INJECTION = """
# reshuffling the paths to ensure that distributions in the sandbox
# always come first
paths_to_append = [p for p in sys.path if p.startswith(sys.real_prefix)]
sys.path = [p for p in sys.path if not p.startswith(sys.real_prefix)]
sys.path += paths_to_append
"""


def inject_into_activate_this(venv_root, body):
"""
Expand All @@ -49,6 +58,20 @@ def inject_into_activate_this(venv_root, body):
inject_into_file(activate_this_file, body)


def inject_sitepy(venv_root):
site_py_file = _get_site_file_path(venv_root)
inject_into_file(site_py_file, SITE_PY_INJECTION)


def _get_site_file_path(venv_directory):
executable = os.path.join(venv_directory, 'bin', 'python')
return subprocess.check_output(
[executable, "-c", "import site; print(site.__file__)"]
# we strip the last character because it is a .pyc file.
# want the .py
)[:-2]


def inject_into_file(path, body):
""" inject into a file """
with open(path) as fh:
Expand Down

0 comments on commit ab8fede

Please sign in to comment.