Skip to content

Commit

Permalink
bugfix: some jenkins builds not honoring virtualenv setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Aug 12, 2017
1 parent 1a1b300 commit 8873e78
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
./uranium/scripts/uranium_standalone --uranium-dir=. test ${ARGS} -v -sx
./uranium/scripts/uranium_standalone --uranium-dir=. test ${ARGS} -v -x

build:
./uranium/scripts/uranium_standalone --uranium-dir=.
Expand Down
30 changes: 30 additions & 0 deletions tests/test_packages_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,33 @@ def main(build):
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0


def test_executable_relocatable_after_install(tmpdir):
"""
an executable installed from a package should be
using the virtualenv relocatable version.
"""

UBUILD = """
import os
def main(build):
build.packages.install("tox")
nose_path = os.path.join(build.root, "bin", "tox")
with open(nose_path) as fh:
contents = fh.read()
print(contents)
assert build.root not in contents
""".strip()

# we need to create a virtualenv
tmpdir.join("ubuild.py").write(UBUILD)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0
3 changes: 2 additions & 1 deletion uranium/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, root, config=None, with_sandbox=True):
self._root = root
self._executables = Executables(root)
self._hooks = Hooks()
self._packages = Packages()
virtualenv_dir = root if with_sandbox else None
self._packages = Packages(virtualenv_dir=virtualenv_dir)
self._tasks = Tasks()
self._envvars = EnvironmentVariables()
self._options = None
Expand Down
11 changes: 10 additions & 1 deletion uranium/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..exceptions import PackageException
from .install_command import install, uninstall
from .versions import Versions
import virtualenv

p_assert = get_assert_function(PackageException)

Expand All @@ -16,7 +17,8 @@ class Packages(object):
mutable: updating them will take immediate effect.
"""

def __init__(self):
def __init__(self, virtualenv_dir=None):
self._virtualenv_dir = virtualenv_dir
self._versions = Versions()
self._index_urls = list(DEFAULT_INDEX_URLS)

Expand Down Expand Up @@ -90,6 +92,13 @@ def install(self, name, version=None, develop=False, upgrade=False, install_opti
for req in req_set.requirements.values():
if req.installed_version:
self.versions[req.name] = ("==" + req.installed_version)
# if virtualenv dir is set, we should make the environment relocatable.
# this will fix issues with commands not being usable by the
# uranium via build.executables.run
if self._virtualenv_dir:
return
virtualenv.make_environment_relocatable(self._virtualenv_dir)


def uninstall(self, package_name):
"""
Expand Down

0 comments on commit 8873e78

Please sign in to comment.