Repository: incubator-beam Updated Branches: refs/heads/python-sdk 753cc9c2e -> bb649061f
Add BEAM_PYTHON environment override to set the python executable Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/26eb336a Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/26eb336a Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/26eb336a Branch: refs/heads/python-sdk Commit: 26eb336ae63dceefae876d6bc8ff742d2670567b Parents: 753cc9c Author: Scott Wegner <sweg...@google.com> Authored: Mon Sep 26 10:05:01 2016 -0700 Committer: Robert Bradshaw <rober...@google.com> Committed: Mon Sep 26 10:58:11 2016 -0700 ---------------------------------------------------------------------- sdks/python/apache_beam/utils/dependency.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/26eb336a/sdks/python/apache_beam/utils/dependency.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/utils/dependency.py b/sdks/python/apache_beam/utils/dependency.py index e9d73ae..150b2fc 100644 --- a/sdks/python/apache_beam/utils/dependency.py +++ b/sdks/python/apache_beam/utils/dependency.py @@ -189,13 +189,23 @@ def _stage_extra_packages(extra_packages, staging_location, temp_dir, return resources +def _get_python_executable(): + # Allow overriding the python executable to use for downloading and + # installing dependencies, otherwise use the python executable for + # the current process. + beam_python = os.environ.get('BEAM_PYTHON') or sys.executable + if not python_bin: + raise ValueError('Could not find Python executable.') + return python_bin + + def _populate_requirements_cache(requirements_file, cache_dir): # The 'pip download' command will not download again if it finds the # tarball with the proper version already present. # It will get the packages downloaded in the order they are presented in # the requirements file and will not download package dependencies. cmd_args = [ - sys.executable, '-m', 'pip', 'install', '--download', cache_dir, + _get_python_executable(), '-m', 'pip', 'install', '--download', cache_dir, '-r', requirements_file, # Download from PyPI source distributions. '--no-binary', ':all:'] @@ -375,7 +385,7 @@ def _build_setup_package(setup_file, temp_dir, build_setup_args=None): os.chdir(os.path.dirname(setup_file)) if build_setup_args is None: build_setup_args = [ - sys.executable, os.path.basename(setup_file), + _get_python_executable(), os.path.basename(setup_file), 'sdist', '--dist-dir', temp_dir] logging.info('Executing command: %s', build_setup_args) processes.check_call(build_setup_args) @@ -461,7 +471,7 @@ def _download_pypi_sdk_package(temp_dir): version = pkg.get_distribution(GOOGLE_PACKAGE_NAME).version # Get a source distribution for the SDK package from PyPI. cmd_args = [ - sys.executable, '-m', 'pip', 'install', '--download', temp_dir, + _get_python_executable(), '-m', 'pip', 'install', '--download', temp_dir, '%s==%s' % (GOOGLE_PACKAGE_NAME, version), '--no-binary', ':all:', '--no-deps'] logging.info('Executing command: %s', cmd_args)