Skip to content

Commit

Permalink
Change the if condition to check if build is installed (#28992)
Browse files Browse the repository at this point in the history
* Change how we look for build module

* use try except instead of module check
  • Loading branch information
AnandInguva authored Oct 16, 2023
1 parent 420418c commit 9676fcc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sdks/python/apache_beam/runners/portability/stager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import glob
import hashlib
import importlib.util
import logging
import os
import shutil
Expand Down Expand Up @@ -774,7 +773,7 @@ def _build_setup_package(setup_file, # type: str
if build_setup_args is None:
# if build is installed in the user env, use it to
# build the sdist else fallback to legacy setup.py sdist call.
if importlib.util.find_spec('build'):
try:
build_setup_args = [
Stager._get_python_executable(),
'-m',
Expand All @@ -784,16 +783,18 @@ def _build_setup_package(setup_file, # type: str
temp_dir,
os.path.dirname(setup_file),
]
else:
_LOGGER.info('Executing command: %s', build_setup_args)
processes.check_output(build_setup_args)
except RuntimeError:
build_setup_args = [
Stager._get_python_executable(),
os.path.basename(setup_file),
'sdist',
'--dist-dir',
temp_dir
]
_LOGGER.info('Executing command: %s', build_setup_args)
processes.check_output(build_setup_args)
_LOGGER.info('Executing command: %s', build_setup_args)
processes.check_output(build_setup_args)
output_files = glob.glob(os.path.join(temp_dir, '*.tar.gz'))
if not output_files:
raise RuntimeError(
Expand Down

0 comments on commit 9676fcc

Please sign in to comment.