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

Tweak DescendantAddresses so that call sites can no-op when no matches #10012

Merged

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jun 10, 2020

For dep inference, we need to use DescendantAddress(src_root) for every source root, but this will sometimes fail. For example, Pants has a source root 3rdparty/protobuf, but doesn't have any BUILD files in it.

We may end up wanting to change the overall CI behavior so that ./pants list :: would stop failing when no targets exist, but we do not yet want to change the CI behavior until further discussion.

So, this adds an optional field to DescendantAddresses so that call sites can determine the behavior they want.

[ci skip-rust-tests]
[ci skip-jvm-tests]

# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]
# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]
@jsirois
Copy link
Contributor

jsirois commented Jun 10, 2020

This is good behavior when using the more specific : or :target

I can't see why erroring for any glob is good behavior. How about fixing : too?

@Eric-Arellano
Copy link
Contributor Author

I can't see why erroring for any glob is good behavior. How about fixing : too?

I think the idea is that you are being specific enough that we want to yell loudly when it doesn't resolve. For example, when you put src/../utiil: instead of src/../util.

I'm happy to fix, but are you sure we want to? I bias towards keeping the error, but I do not have a strong opinion here.

@jsirois
Copy link
Contributor

jsirois commented Jun 10, 2020

OK, how about side-stepping taste / precedent altogether. Presumably the motivating code uses DescendantAddress directly via Get? If so can the appropriate rule be parameterized to allow the desired behavior as determined by the call site? Not dissimilar to path glob handling.

@Eric-Arellano
Copy link
Contributor Author

Sure. To confirm, this means that the CLI will behave the same before that it will error, but the rule can now no-op?

@jsirois
Copy link
Contributor

jsirois commented Jun 10, 2020

Sure. To confirm, this means that the CLI will behave the same before that it will error, but the rule can now no-op?

Yes.

I still think having globs not fail when used on the CLI is better behvior (for some goals anyhow, like list) - but changing behavior of all goals to support an internal use case had a smell.

@Eric-Arellano
Copy link
Contributor Author

Eric-Arellano commented Jun 10, 2020

Okay I'm stumped on how to implement this without multiple Param support (#7490).

The call site in my draft PR looks like:

await Get[Targets](AddressSpecs([DescendantAddresses(..)])

We would either need to add a second param like AddressGlobMatchErrorBehavior or add a new wrapper type like TargetsRequest so it's await Get[Targets](TargetsRequest(..)). The first isn't possible till #7490, and the second seems undesirable because it makes call sites so much more clunky.

(Note that this isn't an issue with GlobMatchErrorBehavior because that param is not specified at call sites - it's determined by the global option.)

--

So I think two paths forward to resolving my issue of the Pants repo complaining that DescendantAddresses("3rdparty/protobuf") does not match:

  1. Continue with this PR.
  2. Fix Pants repo, e.g. add an empty BUILD file to 3rdparty/protobuf. Dep inference is feature-gated, so this won't break things for end users.

@stuhood
Copy link
Member

stuhood commented Jun 10, 2020

It seems like it could be a field of AddressSpecs ?

@Eric-Arellano
Copy link
Contributor Author

Ah. Yep. I thought AddressSpecs was a Collection, but it's a normal dataclass. Thanks Stu!

@jsirois
Copy link
Contributor

jsirois commented Jun 10, 2020

Ah. Yep. I thought AddressSpecs was a Collection, but it's a normal dataclass.

If that would have been true there is nothing preventing adding fields to a Collection by overriding __{init,hash,eq}__ right?

@Eric-Arellano
Copy link
Contributor Author

If that would have been true there is nothing preventing adding fields to a Collection by overriding {init,hash,eq} right?

Correct. At that point, it should probably go back to being a normal dataclass, though.

…error behavior

# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]
# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]
@Eric-Arellano Eric-Arellano changed the title Do not error when :: does not match any targets Tweak DescendantAddresses so that call sites can no-op when no matches Jun 10, 2020
@Eric-Arellano
Copy link
Contributor Author

Okay, ready to go. I adding the field to DescendantAddresses, rather than AddressSpecs. The error is defined in a method of DescendantAddresses, so it is much simpler to parametrize there.

@Eric-Arellano Eric-Arellano merged commit a38bd7d into pantsbuild:master Jun 10, 2020
@Eric-Arellano Eric-Arellano deleted the descendant-addresses-no-fail branch June 10, 2020 23:36
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.

3 participants