From 9571d48a3b32e1b20cc0d4e98ba7a4e7ae4eedc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Fri, 31 Jan 2020 07:34:56 +0100 Subject: [PATCH 1/2] standalone: unset PYTHONPATH at startup In our normal operations, we are not using PYTHONPATH but using buildout to generate wrappers. We are still using python setup.py test to run tests, which sets PYTHONPATH to the eggs used by this python and this cause issues when this python starts subprocesses, especially when it starts another version of python which is supposed to use a different set of eggs. --- slapos/slap/standalone.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/slapos/slap/standalone.py b/slapos/slap/standalone.py index 8dbbdeda1..7cf2be6a6 100644 --- a/slapos/slap/standalone.py +++ b/slapos/slap/standalone.py @@ -643,7 +643,11 @@ class StandaloneSlapOS(object): debug_args = prog.get('debug_args', '') # pylint: disable=unused-variable command = prog['command'].format(**locals()) try: - return subprocess.check_call(command, shell=True) + return subprocess.check_call( + command, + shell=True, + env=self._getSubprocessEnvironment(), + ) except subprocess.CalledProcessError as e: if e.returncode == SLAPGRID_PROMISE_FAIL: self._logger.exception('Promise error when running %s', command) @@ -706,6 +710,7 @@ class StandaloneSlapOS(object): output = subprocess.check_output( ['supervisord', '--configuration', self._supervisor_config], cwd=self._base_directory, + env=self._getSubprocessEnvironment(), ) self._logger.debug("Started new supervisor: %s", output) @@ -736,3 +741,12 @@ class StandaloneSlapOS(object): return time.sleep(i * .01) raise RuntimeError("SlapOS not started") + + def _getSubprocessEnvironment(self): + # Running tests with `python setup.py test` sets a PYTHONPATH that + # is suitable for current python, but problematic when this process + # runs another version of python in subprocess. + if 'PYTHONPATH' in os.environ: + self._logger.warning("Removing $PYTHONPATH from environment for subprocess") + return {k:v for k, v in os.environ.items() if k != 'PYTHONPATH'} + return None -- 2.30.9 From e8b0ad1dc71868dc08aa71c4f75f4ae6491cca06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Fri, 31 Jan 2020 07:39:28 +0100 Subject: [PATCH 2/2] setup.py: declare test dependencies through extras_require This is what most of tools understand, test_requires is something that only python setup.py test uses. --- setup.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 853183620..74f6c3e26 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,20 @@ try: except ImportError: additional_install_requires.append('argparse') +extras_require = { + 'docs': ( + 'Sphinx', + 'repoze.sphinx.autointerface', + 'sphinxcontrib.programoutput', + ), + 'ipython_console': ('ipython',), + 'bpython_console': ('bpython',), + 'test': ( + 'pyflakes', + 'mock', + 'httmock', + ), +} setup(name=name, version=version, @@ -63,19 +77,8 @@ setup(name=name, 'uritemplate', # used by hateoas navigator 'subprocess32; python_version<"3"' ] + additional_install_requires, - extras_require={ - 'docs': ( - 'Sphinx', - 'repoze.sphinx.autointerface', - 'sphinxcontrib.programoutput' - ), - 'ipython_console': ('ipython',), - 'bpython_console': ('bpython',)}, - tests_require=[ - 'pyflakes', - 'mock', - 'httmock', - ], + extras_require=extras_require, + tests_require=extras_require['test'], zip_safe=False, # proxy depends on Flask, which has issues with # accessing templates entry_points={ -- 2.30.9