Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

Eric-Arellano
Copy link
Contributor

We were only using inject_init.py for the purpose of prepare_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.

from pants.rules.core.strip_source_roots import SourceRootStrippedSources


@dataclass(frozen=True)
class ChrootedPythonSources:
digest: Digest
snapshot: Snapshot
Copy link
Contributor Author

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:
Copy link
Contributor Author

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?

Copy link
Contributor

@codealchemy codealchemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Eric-Arellano Eric-Arellano merged commit 7136d9b into pantsbuild:master Feb 13, 2020
@Eric-Arellano Eric-Arellano deleted the inject-init branch February 13, 2020 04:49
Eric-Arellano added a commit that referenced this pull request Feb 25, 2020
#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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants