@@ -405,6 +405,10 @@ async def package_python_dist(
405
405
return BuiltPackage (rel_chroot , (BuiltPackageArtifact (dirname ),))
406
406
407
407
408
+ # We write .py sources into the chroot under this dir.
409
+ CHROOT_SOURCE_ROOT = "src"
410
+
411
+
408
412
SETUP_BOILERPLATE = """
409
413
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
410
414
# Target: {target_address_spec}
@@ -429,42 +433,23 @@ async def run_setup_py(req: RunSetupPyRequest, setuptools: Setuptools) -> RunSet
429
433
interpreter_constraints = req .interpreter_constraints ,
430
434
),
431
435
)
432
-
433
- # We prefix the entire chroot, and run with this prefix as the cwd, so that we can capture any
434
- # changes setup made within it (e.g., when running 'develop') without also capturing other
435
- # artifacts of the pex process invocation.
436
- chroot_prefix = "chroot"
437
-
438
436
# The setuptools dist dir, created by it under the chroot (not to be confused with
439
437
# pants's own dist dir, at the buildroot).
440
- dist_dir = "dist"
441
-
442
- prefixed_chroot = await Get (Digest , AddPrefix (req .chroot .digest , chroot_prefix ))
443
-
444
- # setup.py basically always expects to be run with the cwd as its own directory
445
- # (e.g., paths in it are relative to that directory). This is true of the setup.py
446
- # we generate and is overwhelmingly likely to be true for existing setup.py files,
447
- # as there is no robust way to run them otherwise.
448
- setup_script_reldir , setup_script_name = os .path .split (req .chroot .setup_script )
449
- working_directory = os .path .join (chroot_prefix , setup_script_reldir )
450
-
438
+ dist_dir = "dist/"
451
439
result = await Get (
452
440
ProcessResult ,
453
441
VenvPexProcess (
454
442
setuptools_pex ,
455
- argv = (setup_script_name , * req .args ),
456
- input_digest = prefixed_chroot ,
457
- working_directory = working_directory ,
443
+ argv = (req .chroot .setup_script , * req .args ),
444
+ input_digest = req .chroot .digest ,
458
445
# setuptools commands that create dists write them to the distdir.
459
446
# TODO: Could there be other useful files to capture?
460
- output_directories = (dist_dir ,), # Relative to the working_directory.
447
+ output_directories = (dist_dir ,),
461
448
description = f"Run setuptools for { req .exported_target .target .address } " ,
462
449
level = LogLevel .DEBUG ,
463
450
),
464
451
)
465
- output_digest = await Get (
466
- Digest , RemovePrefix (result .output_digest , os .path .join (chroot_prefix , dist_dir ))
467
- )
452
+ output_digest = await Get (Digest , RemovePrefix (result .output_digest , dist_dir ))
468
453
return RunSetupPyResult (output_digest )
469
454
470
455
@@ -550,6 +535,7 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
550
535
# specified `SetupKwargs(_allow_banned_keys=True)`.
551
536
setup_kwargs .update (
552
537
{
538
+ "package_dir" : {"" : CHROOT_SOURCE_ROOT , ** setup_kwargs .get ("package_dir" , {})},
553
539
"packages" : (* sources .packages , * (setup_kwargs .get ("packages" , []))),
554
540
"namespace_packages" : (
555
541
* sources .namespace_packages ,
@@ -609,8 +595,13 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
609
595
FileContent ("setup.py" , setup_py_content ),
610
596
FileContent ("MANIFEST.in" , "include *.py" .encode ()),
611
597
]
612
- extra_files_digest = await Get (Digest , CreateDigest (files_to_create ))
613
- chroot_digest = await Get (Digest , MergeDigests ((sources .digest , extra_files_digest )))
598
+ extra_files_digest , src_digest = await MultiGet (
599
+ Get (Digest , CreateDigest (files_to_create )),
600
+ # Nest the sources under the src/ prefix.
601
+ Get (Digest , AddPrefix (sources .digest , CHROOT_SOURCE_ROOT )),
602
+ )
603
+
604
+ chroot_digest = await Get (Digest , MergeDigests ((src_digest , extra_files_digest )))
614
605
return SetupPyChroot (
615
606
chroot_digest , "setup.py" , FinalizedSetupKwargs (setup_kwargs , address = target .address )
616
607
)
0 commit comments