Skip to content

Commit

Permalink
fixing some bugs with uranium's sandboxing, and adding a warning for …
Browse files Browse the repository at this point in the history
…executing different versions of python.
  • Loading branch information
toumorokoshi committed Jan 20, 2016
1 parent e85811a commit d4251a2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]

setup(name='uranium',
version='0.2.24b',
version='0.2.26',
description='a build system for python',
long_description=open('README.rst').read(),
author='Yusuke Tsutsumi',
Expand Down
14 changes: 13 additions & 1 deletion uranium/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys
import virtualenv
from .config import Config
from .executables import Executables
Expand All @@ -21,6 +22,8 @@

LOGGER = logging.getLogger(__name__)

HISTORY_KEY = "_uranium"


class Build(object):
"""
Expand Down Expand Up @@ -106,6 +109,7 @@ def include(self, script_path):
get_remote_script(script_path, build=self)

def run(self, options):
self._warmup()
if not self._sandbox:
return self._run(options)

Expand All @@ -118,7 +122,6 @@ def _run(self, options):
self._options = options
code = 1
try:
self._warmup()
path = os.path.join(self.root, options.build_file)
u_assert(os.path.exists(path),
"build file at {0} does not exist".format(path))
Expand All @@ -128,6 +131,8 @@ def _run(self, options):
override_func=options.override_func)
except ScriptException as e:
log_multiline(LOGGER, logging.INFO, str(e))
except Exception as e:
LOGGER.exception("")
finally:
self._finalize()
log_multiline(LOGGER, logging.INFO, ENDING_URANIUM)
Expand Down Expand Up @@ -161,12 +166,19 @@ def _run_script(self, path, task_name, override_func=None):

def _warmup(self):
self.history.load()
current_version = "{0}.{1}".format(*sys.version_info[:2])
ran_version = self.history.get(HISTORY_KEY, {}).get("python_version", current_version)
if ran_version != current_version:
raise UraniumException("current version of python ({0}) is not the same version that was used before ({1}). Please use {1} to execute uranium, or clean the project.".format(
current_version, ran_version
))

def _finalize(self):
virtualenv.make_environment_relocatable(self._root)
activate_content = ""
activate_content += self.envvars.generate_activate_content()
write_activate_this(self._root, additional_content=activate_content)
self.history[HISTORY_KEY]["python_version"] = "{0}.{1}".format(*sys.version_info[:2])
self.history.save()


Expand Down
2 changes: 2 additions & 0 deletions uranium/lib/sandbox/venv/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def activate_virtualenv(root):
activate_this_path = os.path.join(root, 'bin', 'activate_this.py')
with open(activate_this_path) as fh:
exec(fh.read(), {'__file__': activate_this_path}, {})
sys.exec_prefix = sys.prefix
sys.base_exec_prefix = sys.prefix

# sys.path += [
# os.path.join(root, 'lib', 'python%s' % sys.version[:3], 'lib-dynload')
Expand Down
2 changes: 2 additions & 0 deletions uranium/lib/sandbox/venv/activate_this.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

INJECT_TEMPLATE = """
sys.executable = os.path.join(base, "bin", "python")
sys.exec_prefix = sys.prefix
sys.base_exec_prefix = sys.prefix
{0}
{{body}}
Expand Down
21 changes: 0 additions & 21 deletions uranium/lib/sandbox/venv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,13 @@


def install_virtualenv(install_dir):
_ensure_distutils_config(install_dir)
if is_virtualenv(install_dir):
return

create_environment(install_dir, no_setuptools=False,
no_pip=True, site_packages=False,
symlink=False)


DISTUTILS_TEMPLATE = """
[install]
prefix={install_dir}
""".strip()

def _ensure_distutils_config(install_dir):
"""
as a workaround around the fact that,
when uranium activates a virtualenv, it
chooses the wrong directory to install packages to
(due to the fact that the distutils loaded is the
one in the parent context),
we create a pydistutils.cfg file with the desired
directory.
"""
pydistutils_path = os.path.join(install_dir, ".pydistutils.cfg")
with open(pydistutils_path, "w") as fh:
fh.write(DISTUTILS_TEMPLATE.format(install_dir=install_dir))

VIRTUALENV_FILES = {
'activate file': os.path.join('bin', 'activate')
}
Expand Down

0 comments on commit d4251a2

Please sign in to comment.