Skip to content

Commit

Permalink
Update stager to use build. If it fails, use legacy setup to build sdist
Browse files Browse the repository at this point in the history
Fix mypy issue
  • Loading branch information
AnandInguva committed Oct 10, 2023
1 parent d59c260 commit 4c80183
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions sdks/python/apache_beam/runners/portability/stager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import glob
import hashlib
import importlib.util
import logging
import os
import shutil
Expand Down Expand Up @@ -771,13 +772,26 @@ def _build_setup_package(setup_file, # type: str
try:
os.chdir(os.path.dirname(setup_file))
if build_setup_args is None:
build_setup_args = [
Stager._get_python_executable(),
os.path.basename(setup_file),
'sdist',
'--dist-dir',
temp_dir
]
# 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'):
build_setup_args = [
Stager._get_python_executable(),
'-m',
'build',
'--sdist',
'--outdir',
temp_dir,
os.path.dirname(setup_file),
]
else:
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)
output_files = glob.glob(os.path.join(temp_dir, '*.tar.gz'))
Expand Down

0 comments on commit 4c80183

Please sign in to comment.