Skip to content

Commit 9f5ff78

Browse files
Revert "Prefix the entire setup.py chroot. (#12359)" (#12370)
This was causing CI to fail with: > Exception: String("Cannot strip prefix chroot/dist from root directory (Digest with hash Fingerprint<0e3f69284c886c8b9b330122c22ed47e469e2f9020c9938fdf6d15c24471aeae>) - root directory didn't contain a directory named chroot but did contain directory named: dist") [ci skip-rust] [ci skip-build-wheels]
1 parent da780e2 commit 9f5ff78

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

src/python/pants/backend/python/goals/setup_py.py

+17-26
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ async def package_python_dist(
405405
return BuiltPackage(rel_chroot, (BuiltPackageArtifact(dirname),))
406406

407407

408+
# We write .py sources into the chroot under this dir.
409+
CHROOT_SOURCE_ROOT = "src"
410+
411+
408412
SETUP_BOILERPLATE = """
409413
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
410414
# Target: {target_address_spec}
@@ -429,42 +433,23 @@ async def run_setup_py(req: RunSetupPyRequest, setuptools: Setuptools) -> RunSet
429433
interpreter_constraints=req.interpreter_constraints,
430434
),
431435
)
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-
438436
# The setuptools dist dir, created by it under the chroot (not to be confused with
439437
# 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/"
451439
result = await Get(
452440
ProcessResult,
453441
VenvPexProcess(
454442
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,
458445
# setuptools commands that create dists write them to the distdir.
459446
# TODO: Could there be other useful files to capture?
460-
output_directories=(dist_dir,), # Relative to the working_directory.
447+
output_directories=(dist_dir,),
461448
description=f"Run setuptools for {req.exported_target.target.address}",
462449
level=LogLevel.DEBUG,
463450
),
464451
)
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))
468453
return RunSetupPyResult(output_digest)
469454

470455

@@ -550,6 +535,7 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
550535
# specified `SetupKwargs(_allow_banned_keys=True)`.
551536
setup_kwargs.update(
552537
{
538+
"package_dir": {"": CHROOT_SOURCE_ROOT, **setup_kwargs.get("package_dir", {})},
553539
"packages": (*sources.packages, *(setup_kwargs.get("packages", []))),
554540
"namespace_packages": (
555541
*sources.namespace_packages,
@@ -609,8 +595,13 @@ async def generate_chroot(request: SetupPyChrootRequest) -> SetupPyChroot:
609595
FileContent("setup.py", setup_py_content),
610596
FileContent("MANIFEST.in", "include *.py".encode()),
611597
]
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)))
614605
return SetupPyChroot(
615606
chroot_digest, "setup.py", FinalizedSetupKwargs(setup_kwargs, address=target.address)
616607
)

src/python/pants/backend/python/goals/setup_py_test.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ def test_generate_chroot(chroot_rule_runner: RuleRunner) -> None:
285285
assert_chroot(
286286
chroot_rule_runner,
287287
[
288-
"files/README.txt",
289-
"foo/qux/__init__.py",
290-
"foo/qux/qux.py",
291-
"foo/qux/qux.pyi",
292-
"foo/resources/js/code.js",
293-
"foo/__init__.py",
294-
"foo/foo.py",
288+
"src/files/README.txt",
289+
"src/foo/qux/__init__.py",
290+
"src/foo/qux/qux.py",
291+
"src/foo/qux/qux.pyi",
292+
"src/foo/resources/js/code.js",
293+
"src/foo/__init__.py",
294+
"src/foo/foo.py",
295295
"setup.py",
296296
"MANIFEST.in",
297297
],
@@ -300,6 +300,7 @@ def test_generate_chroot(chroot_rule_runner: RuleRunner) -> None:
300300
"name": "foo",
301301
"version": "1.2.3",
302302
"plugin_demo": "hello world",
303+
"package_dir": {"": "src"},
303304
"packages": ("foo", "foo.qux"),
304305
"namespace_packages": ("foo",),
305306
"package_data": {"foo": ("resources/js/code.js",)},
@@ -377,12 +378,13 @@ def test_binary_shorthand(chroot_rule_runner: RuleRunner) -> None:
377378
)
378379
assert_chroot(
379380
chroot_rule_runner,
380-
["project/app.py", "setup.py", "MANIFEST.in"],
381+
["src/project/app.py", "setup.py", "MANIFEST.in"],
381382
"setup.py",
382383
{
383384
"name": "bin",
384385
"version": "1.1.1",
385386
"plugin_demo": "hello world",
387+
"package_dir": {"": "src"},
386388
"packages": ("project",),
387389
"namespace_packages": (),
388390
"install_requires": (),

0 commit comments

Comments
 (0)