@@ -282,10 +282,12 @@ def create_job_resources(
282282 raise RuntimeError (
283283 'The file %s cannot be found. It was specified in the '
284284 '--setup_file command line option.' % setup_options .setup_file )
285- if os .path .basename (setup_options .setup_file ) != 'setup.py' :
285+ if os .path .basename (setup_options .setup_file ) not in ('setup.py' ,
286+ 'pyproject.toml' ):
286287 raise RuntimeError (
287288 'The --setup_file option expects the full path to a file named '
288- 'setup.py instead of %s' % setup_options .setup_file )
289+ 'setup.py or pyproject.toml instead of %s' %
290+ setup_options .setup_file )
289291 tarball_file = Stager ._build_setup_package (
290292 setup_options .setup_file , temp_dir , build_setup_args )
291293 resources .append (
@@ -786,11 +788,13 @@ def _build_setup_package(
786788 temp_dir : str ,
787789 build_setup_args : Optional [List [str ]] = None ) -> str :
788790 saved_current_directory = os .getcwd ()
791+
789792 try :
790793 os .chdir (os .path .dirname (setup_file ))
791794 if build_setup_args is None :
792795 # if build is installed in the user env, use it to
793- # build the sdist else fallback to legacy setup.py sdist call.
796+ # build the sdist else fallback to legacy
797+ # setup.py sdist call for setup.py file.
794798 try :
795799 build_setup_args = [
796800 Stager ._get_python_executable (),
@@ -805,15 +809,24 @@ def _build_setup_package(
805809 _LOGGER .info ('Executing command: %s' , build_setup_args )
806810 processes .check_output (build_setup_args )
807811 except RuntimeError :
808- build_setup_args = [
809- Stager ._get_python_executable (),
810- os .path .basename (setup_file ),
811- 'sdist' ,
812- '--dist-dir' ,
813- temp_dir
814- ]
815- _LOGGER .info ('Executing command: %s' , build_setup_args )
816- processes .check_output (build_setup_args )
812+ if setup_file .endswith ('setup.py' ):
813+ build_setup_args = [
814+ Stager ._get_python_executable (),
815+ os .path .basename (setup_file ),
816+ 'sdist' ,
817+ '--dist-dir' ,
818+ temp_dir
819+ ]
820+ _LOGGER .info ('Executing command: %s' , build_setup_args )
821+ processes .check_output (build_setup_args )
822+ else :
823+ # If it's pyproject.toml and `python -m build` failed,
824+ # there's no direct legacy fallback.
825+ raise RuntimeError (
826+ f"Failed to build package from '{ setup_file } ' using . "
827+ f"'python -m build'. Please ensure that the 'build' module "
828+ f"is installed and your project's build configuration is valid."
829+ )
817830 output_files = glob .glob (os .path .join (temp_dir , '*.tar.gz' ))
818831 if not output_files :
819832 raise RuntimeError (
0 commit comments