-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline inject_init.py
into prepare_chrooted_python_sources.py
#9115
Conversation
from pants.rules.core.strip_source_roots import SourceRootStrippedSources | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ChrootedPythonSources: | ||
digest: Digest | ||
snapshot: Snapshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this because Snapshot
is generally much more useful to rule authors than Digest
.
address = Address(spec_path=PurePath(source_paths[0]).parent.as_posix(), target_name="target") | ||
return HydratedTarget(address=address, adaptor=adaptor, dependencies=()) | ||
|
||
def test_adds_missing_inits_and_strips_source_roots(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't stress test all the different combinations of source root stripping because that is already tested in strip_source_roots_test.py
.
Let me know if you can think of any further edge cases with injecting __init__.py
, though. One thing we could do is to ensure that a pre-existing file still keeps its original content. It would make the test setup a bit more complex, but is probably worth it? Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
#9115 inlined `inject_init.py` into `prepare_chrooted_python_sources.py` because it was the only call site at the time. Turns out, V2 coverage has a use case for `inject_init`. This makes several enhancements over the original `inject_init` implementation: * Uses `InputFilesContent` instead of `ExecuteProcessRequest` * The result merges the original with new `__init__.py`s, rather than returning only the newly added `__init__.py`s. * Returns a `Snapshot`, rather than `Digest`, which is more ergonomic. * More comprehensive tests, e.g. ensuring we aren't overriding the original `__init__.py`.
We were only using
inject_init.py
for the purpose ofprepare_chrooted_python_sources.py
. Inlining this simplifies things. If we ever end up needing the init logic to be used in another context, we can, of course, generalize it back out.More importantly, this stops using a hacky
ExecuteProcessRequest
to create the missing__init__.py
files to instead use engine intrinsics. This improves readability and performance.