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 from __future__ import absolute_import, unicode_literals
import os
import textwrap import textwrap
...@@ -40,3 +41,15 @@ def make_site_dir(target): ...@@ -40,3 +41,15 @@ def make_site_dir(target):
target_str = str(target) target_str = str(target)
tmpl = '__import__("site").addsitedir({target_str!r})' tmpl = '__import__("site").addsitedir({target_str!r})'
sc.write_text(tmpl.format(**locals()), encoding='utf-8') 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: ...@@ -132,7 +132,7 @@ class TestNamespaces:
'develop', 'develop',
'--install-dir', str(target), '--install-dir', str(target),
] ]
env = dict(PYTHONPATH=str(target)) env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
with src_dir.as_cwd(): with src_dir.as_cwd():
subprocess.check_call(develop_cmd, env=env) subprocess.check_call(develop_cmd, env=env)
...@@ -162,7 +162,7 @@ class TestNamespaces: ...@@ -162,7 +162,7 @@ class TestNamespaces:
sys.executable, sys.executable,
'-c', 'import myns.pkgA; import myns.pkgB', '-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) subprocess.check_call(try_import, env=env)
# additionally ensure that pkg_resources import works # additionally ensure that pkg_resources import works
......
...@@ -26,8 +26,7 @@ class TestNamespaces: ...@@ -26,8 +26,7 @@ class TestNamespaces:
pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB') pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')
site_packages = tmpdir / 'site-packages' site_packages = tmpdir / 'site-packages'
path_packages = tmpdir / 'path-packages' path_packages = tmpdir / 'path-packages'
targets = site_packages, path_packages python_path = namespaces.build_pythonpath(site_packages, path_packages)
python_path = os.pathsep.join(map(str, targets))
# use pip to install to the target directory # use pip to install to the target directory
install_cmd = [ install_cmd = [
'pip', 'pip',
...@@ -61,7 +60,7 @@ class TestNamespaces: ...@@ -61,7 +60,7 @@ class TestNamespaces:
pkg = namespaces.build_namespace_package(tmpdir, 'myns.pkgA') pkg = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')
target = tmpdir / 'packages' target = tmpdir / 'packages'
target.mkdir() target.mkdir()
env = dict(PYTHONPATH=str(target)) env = dict(PYTHONPATH=namespaces.build_pythonpath(target))
install_cmd = [ install_cmd = [
sys.executable, sys.executable,
'-m', 'easy_install', '-m', 'easy_install',
...@@ -100,5 +99,5 @@ class TestNamespaces: ...@@ -100,5 +99,5 @@ class TestNamespaces:
sys.executable, sys.executable,
'-c', 'import pkg_resources; import myns.pkgA', '-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)) 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