average-vr-56795
11/28/2019, 4:56 PMwitty-crayon-22786
12/03/2019, 4:30 AMsources = ..
for member in union_membership.members(Type):
sources = await Get[FormattedSources](Type, member.cls(sources))
...ie, execute a series of formatting @rules in the order they were declared in the union. The order would be stable, but not customizable without more complexity... probably fine.hundreds-father-404
12/03/2019, 4:44 AMwitty-crayon-22786
12/03/2019, 4:44 AMwitty-crayon-22786
12/03/2019, 4:45 AMaloof-angle-91616
12/03/2019, 6:45 AMaloof-angle-91616
12/03/2019, 6:47 AMThe order would be stable, but not customizable without more complexity... probably fine.agreed! and if it does need to be customizable, i feel like that won't be super difficult to extend
@union
(?) to dohundreds-father-404
12/11/2019, 8:14 PMTargetWithSources
is a union type and itās fulfilled(?) by nested unions, e.g. TargetWithSources
may be fulfilled by FormattablePythonTarget
and FormattableJavaTarget
Those are unions themselves. Then, tools define their own concrete dataclass like IsortFormattableTarget
. FormattablePythonTarget
would be fulfilled through union rules with IsortFormattableTarget
, BlackFormattableTarget
, etcwitty-crayon-22786
12/11/2019, 8:22 PMhundreds-father-404
12/11/2019, 8:23 PM--query
aloof-angle-91616
12/11/2019, 10:18 PMaloof-angle-91616
12/11/2019, 10:19 PM--query
is that you can use the UnionMembership
singleton to query all members of a specific @union
hundreds-father-404
12/11/2019, 10:19 PMhaving unions within unions is not supported, but could beAh okay, thatās why this prototype fails. Would my summary even work for this problem? Thereās still a path from
TargetWithSources->FormattablePythonTarget->IsortFormattableTarget
and also a path from TargetWithSources->FormattablePythonTarget->BlackFormattableTarget
. Thereās no way to disambiguate which of these two to use.aloof-angle-91616
12/11/2019, 10:19 PM--query
, thatās used to kind of āforward declareā those union members, so that the union members can be overloaded to also be used to create instances of themselves with a parse methodaloof-angle-91616
12/11/2019, 10:20 PMhundreds-father-404
12/11/2019, 10:20 PMlooking at the codelet me post my WIP! https://github.com/pantsbuild/pants/pull/8794
aloof-angle-91616
12/11/2019, 10:21 PM--query
this is handled by another level of indirectionaloof-angle-91616
12/11/2019, 10:22 PMwitty-crayon-22786
12/11/2019, 10:22 PMaloof-angle-91616
12/11/2019, 10:22 PMwitty-crayon-22786
12/11/2019, 10:23 PMhundreds-father-404
12/11/2019, 10:23 PMTo close the loop on this, I think that using ``UnionMembership`` as Danny was suggesting should work: it would look roughly like:
sources = ..
for member in union_membership.members(Type):
sources = await Get[FormattedSources](Type, member.cls(sources))
...ie, execute a series of formatting @rules in the order they were declared in the union. The order would be stable, but not customizable without more complexity... probably fine.
I didnāt followwitty-crayon-22786
12/11/2019, 10:23 PMwitty-crayon-22786
12/11/2019, 10:24 PMhundreds-father-404
12/11/2019, 10:25 PMIsortFormattableTarget
and BlackFormattableTarget
, right? Are those directly members of the TargetWithSources
union? Thereās no intermediate type PythonFormattableTarget
?witty-crayon-22786
12/11/2019, 10:25 PMType
in this example would probably be ... a union containing input types for various formatters... ie, ISortTarget and BlackTargetwitty-crayon-22786
12/11/2019, 10:27 PMwitty-crayon-22786
12/11/2019, 10:28 PMhundreds-father-404
12/11/2019, 10:53 PMBlackTarget
and IsortTarget
and those are direct members of the union rules.core.fmt.TargetWithSources
It fails with this message https://github.com/pantsbuild/pants/pull/8794#issuecomment-564769701, but maybe thatās resolvable by changing the implementation of the core fmt
and lint
rules as you suggested Stu?witty-crayon-22786
12/11/2019, 10:54 PMhundreds-father-404
12/11/2019, 10:55 PMthis is a new union that is not āTargetWithSourcesāWhy is that / does
TargetWithSources
have any role still or that should be deleted?witty-crayon-22786
12/11/2019, 10:55 PMwitty-crayon-22786
12/11/2019, 10:55 PMTargetWithSources
is used right now, but it's pretty abstract, and should likely be replaced with something as part of 4535witty-crayon-22786
12/11/2019, 10:57 PMPythonFormattableTarget
... unknown: sorry. not familiar with where the unions are right nowhundreds-father-404
12/11/2019, 10:57 PMrules/core/fmt.py
or somewhere else? I donāt think fmt.py
can have any knowledge that the language Python even existswitty-crayon-22786
12/11/2019, 10:58 PMhundreds-father-404
12/11/2019, 10:59 PMTargetWithSources
, which is used by both the core fmt
and lint
rules. python/targets/formatabble_python_target.py
implements FormattablePythonTarget
and registers that as a member of TargetWithSources
. That file also registers the Python target adaptors as members of TargetWithSources
and it registers rules going from each target adaptor to FormattablePythonTarget
. Then, the Python linters ask for a FormattablePythonTarget
in their rule signatureswitty-crayon-22786
12/11/2019, 11:00 PMhundreds-father-404
12/11/2019, 11:00 PMFormattableTarget
and then PythonFormattableTarget
witty-crayon-22786
12/11/2019, 11:01 PMhundreds-father-404
12/11/2019, 11:01 PMFormattableTarget -> PythonFormattableTarget -> BlackTarget|Flake8Target|IsortTarget
, but it failed because we canāt have nested unionswitty-crayon-22786
12/11/2019, 11:02 PMTarget(v2)
) more useful so that not everything needs to be in unionswitty-crayon-22786
12/11/2019, 11:03 PM@rule
in the python backend. but yea.hundreds-father-404
12/11/2019, 11:04 PMFormattableTarget -> BlackTarget|Flake8Target|IsortTarget
wrong? https://github.com/pantsbuild/pants/pull/8794witty-crayon-22786
12/11/2019, 11:06 PMwitty-crayon-22786
12/11/2019, 11:06 PMwitty-crayon-22786
12/11/2019, 11:06 PMaloof-angle-91616
12/11/2019, 11:38 PMTransitiveHydratedTargets
into ThriftableTargetCollection
aloof-angle-91616
12/11/2019, 11:39 PMHydratedTarget -> Optional[ThriftableTarget]
or somethingwitty-crayon-22786
12/12/2019, 2:05 AMsources = ...
for member in union_membership.members(FormattablePythonTypes):
sources = await Get[FormattedSources](FormattablePythonTypes, member.cls(sources))
hundreds-father-404
12/12/2019, 6:09 AMaverage-vr-56795
12/12/2019, 11:51 AMwitty-crayon-22786
12/12/2019, 10:09 PMhundreds-father-404
12/12/2019, 10:13 PMlint-v2
because none are satisfied with the union_membership.is_member(LintTarget)
. Removing that check, then we get a runtime exception
Exception: WithDeps(Inner(InnerEntry { params: {Specs, Console, OptionsBootstrapper}, rule: Task(Task { product: Lint, clause: [Select { product: Console }, Select { product: HydratedTargets }, Select { product: UnionMembership }], gets: [Get { product: LintResults, subject: LintPythonTarget }], func: lint(), cacheable: false, display_info: Some("lint-v2") }) })) did not declare a dependency on JustGet(Get { product: LintResults, subject: PythonTargetAdaptor })
I unfortunately wonāt be able to finish the issue before leaving for Panama. I think Daniel may be right that we need to change the engine to allow unions within unionswitty-crayon-22786
12/12/2019, 10:14 PMwitty-crayon-22786
12/12/2019, 10:15 PMGet
that is claiming a particular type, but not wrapping in itwitty-crayon-22786
12/12/2019, 10:15 PMwitty-crayon-22786
12/13/2019, 4:28 AMhundreds-father-404
12/13/2019, 4:33 AMhundreds-father-404
12/13/2019, 4:40 AMwitty-crayon-22786
12/13/2019, 4:41 AMhundreds-father-404
12/13/2019, 5:50 AMfmt
from lint
! Yay!witty-crayon-22786
12/13/2019, 5:28 PM