@@ -405,10 +405,6 @@ 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
-
412
408
SETUP_BOILERPLATE = """
413
409
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
414
410
# Target: {target_address_spec}
@@ -433,22 +429,40 @@ async def run_setup_py(req: RunSetupPyRequest, setuptools: Setuptools) -> RunSet
433
429
interpreter_constraints = req .interpreter_constraints ,
434
430
),
435
431
)
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
+
436
438
# The setuptools dist dir, created by it under the chroot (not to be confused with
437
439
# pants's own dist dir, at the buildroot).
438
- dist_dir = "dist/"
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
+
439
451
result = await Get (
440
452
ProcessResult ,
441
453
VenvPexProcess (
442
454
setuptools_pex ,
443
- argv = (req .chroot .setup_script , * req .args ),
444
- input_digest = req .chroot .digest ,
455
+ argv = (setup_script_name , * req .args ),
456
+ input_digest = prefixed_chroot ,
457
+ working_directory = working_directory ,
445
458
# setuptools commands that create dists write them to the distdir.
446
459
# TODO: Could there be other useful files to capture?
447
- output_directories = (dist_dir ,),
460
+ output_directories = (dist_dir ,), # Relative to the working_directory.
448
461
description = f"Run setuptools for { req .exported_target .target .address } " ,
449
462
level = LogLevel .DEBUG ,
450
463
),
451
464
)
465
+ # Note that output_digest paths are relative to the working_directory.
452
466
output_digest = await Get (Digest , RemovePrefix (result .output_digest , dist_dir ))
453
467
return RunSetupPyResult (output_digest )
454
468
@@ -535,7 +549,6 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
535
549
# specified `SetupKwargs(_allow_banned_keys=True)`.
536
550
setup_kwargs .update (
537
551
{
538
- "package_dir" : {"" : CHROOT_SOURCE_ROOT , ** setup_kwargs .get ("package_dir" , {})},
539
552
"packages" : (* sources .packages , * (setup_kwargs .get ("packages" , []))),
540
553
"namespace_packages" : (
541
554
* sources .namespace_packages ,
@@ -595,13 +608,8 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
595
608
FileContent ("setup.py" , setup_py_content ),
596
609
FileContent ("MANIFEST.in" , "include *.py" .encode ()),
597
610
]
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 )))
611
+ extra_files_digest = await Get (Digest , CreateDigest (files_to_create ))
612
+ chroot_digest = await Get (Digest , MergeDigests ((sources .digest , extra_files_digest )))
605
613
return SetupPyChroot (
606
614
chroot_digest , "setup.py" , FinalizedSetupKwargs (setup_kwargs , address = target .address )
607
615
)
0 commit comments