@@ -323,7 +323,19 @@ def _build_from_lock_file(
323323
324324 # Export lock file to requirements.txt for platform-specific install
325325 temp_requirements = os .path .join (scratch_dir , "lock_requirements.txt" )
326- export_args = ["export" , "--format" , "requirements-txt" , "--no-hashes" , "-o" , temp_requirements ]
326+ export_args = [
327+ "export" ,
328+ "--format" ,
329+ "requirements.txt" ,
330+ "--no-emit-project" , # Don't include the project itself, only dependencies
331+ "--no-hashes" , # Skip hashes for cleaner output (optional)
332+ "--output-file" ,
333+ temp_requirements ,
334+ # We want to specify the version because `uv export` might default to using a different one
335+ # This is important for dependencies that use different versions depending on python version
336+ "--python" ,
337+ python_version ,
338+ ]
327339
328340 rc , stdout , stderr = self ._uv_runner ._uv .run_uv_command (export_args , cwd = project_dir )
329341 if rc != 0 :
@@ -358,86 +370,23 @@ def _build_from_pyproject(
358370 LOG .info ("Building from pyproject.toml using UV lock and export" )
359371
360372 try :
361- # Use UV's native workflow: lock -> export -> install
362- temp_requirements = self ._export_pyproject_to_requirements (pyproject_path , scratch_dir , python_version )
363-
364- if temp_requirements :
365- self ._uv_runner .install_requirements (
366- requirements_path = temp_requirements ,
367- target_dir = target_dir ,
368- scratch_dir = scratch_dir ,
369- config = config ,
370- python_version = python_version ,
371- platform = "linux" ,
372- architecture = architecture ,
373- )
374- else :
375- LOG .info ("No dependencies found in pyproject.toml" )
376-
377- except Exception as e :
378- raise UvBuildError (reason = f"Failed to build from pyproject.toml: { str (e )} " )
379-
380- def _export_pyproject_to_requirements (
381- self , pyproject_path : str , scratch_dir : str , python_version : str
382- ) -> Optional [str ]:
383- """Use UV's native lock and export to convert pyproject.toml to requirements.txt.
384-
385- This conversion is necessary when pyproject.toml exists without a uv.lock file.
386- UV's pip install command provides better platform targeting capabilities
387- (--python-platform) compared to uv sync, which is essential for Lambda's
388- cross-platform builds (x86_64/ARM64). The workflow is:
389- 1. uv lock: Generate lock file from pyproject.toml
390- 2. uv export: Convert lock file to requirements.txt format
391- 3. Use requirements.txt with uv pip install for platform-specific builds
392- """
393- project_dir = os .path .dirname (pyproject_path )
394-
395- try :
396- # Step 1: Create lock file using UV
373+ # Generate lock file from pyproject.toml
397374 LOG .debug ("Creating lock file from pyproject.toml" )
398375 lock_args = ["lock" , "--no-progress" ]
399-
400376 if python_version :
401377 lock_args .extend (["--python" , python_version ])
402378
379+ project_dir = os .path .dirname (pyproject_path )
403380 rc , stdout , stderr = self ._uv_runner ._uv .run_uv_command (lock_args , cwd = project_dir )
404-
405381 if rc != 0 :
406- LOG .warning (f"UV lock failed: { stderr } " )
407- return None
382+ raise UvBuildError (reason = f"UV lock failed: { stderr } " )
408383
409- # Step 2: Export lock file to requirements.txt format
410- LOG .debug ("Exporting lock file to requirements.txt format" )
411- temp_requirements = os .path .join (scratch_dir , "exported_requirements.txt" )
412-
413- export_args = [
414- "export" ,
415- "--format" ,
416- "requirements.txt" ,
417- "--no-emit-project" , # Don't include the project itself, only dependencies
418- "--no-header" , # Skip comment header
419- "--no-hashes" , # Skip hashes for cleaner output (optional)
420- "--output-file" ,
421- temp_requirements ,
422- ]
423-
424- rc , stdout , stderr = self ._uv_runner ._uv .run_uv_command (export_args , cwd = project_dir )
425-
426- if rc != 0 :
427- LOG .warning (f"UV export failed: { stderr } " )
428- return None
429-
430- # Verify the requirements file was created and has content
431- if os .path .exists (temp_requirements ) and os .path .getsize (temp_requirements ) > 0 :
432- LOG .debug (f"Successfully exported dependencies to { temp_requirements } " )
433- return temp_requirements
434- else :
435- LOG .info ("No dependencies to export from pyproject.toml" )
436- return None
384+ # Reuse lock file build logic
385+ lock_path = os .path .join (project_dir , "uv.lock" )
386+ self ._build_from_lock_file (lock_path , target_dir , scratch_dir , python_version , architecture , config )
437387
438388 except Exception as e :
439- LOG .warning (f"Failed to export pyproject.toml using UV native workflow: { e } " )
440- return None
389+ raise UvBuildError (reason = f"Failed to build from pyproject.toml: { str (e )} " )
441390
442391 def _build_from_requirements (
443392 self ,
0 commit comments