Commit c6c68b2b authored by Jason R. Coombs's avatar Jason R. Coombs

Patch the PYTHONPATH when invoking subprocess commands that rely on setuptools...

Patch the PYTHONPATH when invoking subprocess commands that rely on setuptools under test. Fixes #884.
parent 5d4b2b69
from __future__ import absolute_import, unicode_literals
import os
import textwrap
......@@ -40,3 +41,15 @@ def make_site_dir(target):
target_str = str(target)
tmpl = '__import__("site").addsitedir({target_str!r})'
sc.write_text(tmpl.format(**locals()), encoding='utf-8')
def build_pythonpath(*paths):
"""
Create a PYTHONPATH value for the indicated paths, casting
them to strings, but also injecting the CWD ahead of the
values to ensure that this setuptools is used if the tests
are invoked without this setuptools being installed.
See #884.
"""
paths = (os.getcwd(),) + paths
return os.pathsep.join(map(str, paths))
......@@ -132,7 +132,7 @@ class TestNamespaces:
'develop',
'--install-dir', str(target),
]
env = dict(PYTHONPATH=str(target))
env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
with src_dir.as_cwd():
subprocess.check_call(develop_cmd, env=env)
......@@ -162,7 +162,7 @@ class TestNamespaces:
sys.executable,
'-c', 'import myns.pkgA; import myns.pkgB',
]
env = dict(PYTHONPATH=str(target))
env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
subprocess.check_call(try_import, env=env)
# additionally ensure that pkg_resources import works
......
......@@ -26,8 +26,7 @@ class TestNamespaces:
pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')
site_packages = tmpdir / 'site-packages'
path_packages = tmpdir / 'path-packages'
targets = site_packages, path_packages
python_path = os.pathsep.join(map(str, targets))
python_path = namespaces.build_pythonpath(site_packages, path_packages)
# use pip to install to the target directory
install_cmd = [
'pip',
......@@ -61,7 +60,7 @@ class TestNamespaces:
pkg = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')
target = tmpdir / 'packages'
target.mkdir()
env = dict(PYTHONPATH=str(target))
env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
install_cmd = [
sys.executable,
'-m', 'easy_install',
......@@ -100,5 +99,5 @@ class TestNamespaces:
sys.executable,
'-c', 'import pkg_resources; import myns.pkgA',
]
env = dict(PYTHONPATH=str(target))
env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
subprocess.check_call(pkg_resources_imp, env=env, cwd=str(pkg_A))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment