-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Refactor Task and Subsystem dependencies #1957
Comments
I like this, but I would go even further:
It would be nice to be able to do: def execute(self):
subsystem1 = self.subsystem(Subsystem1)
subsystem2 = self.subsystem(Subsystem2) or def execute(self):
subsystem1 = Subsystem1.instance_for(self)
subsystem2 = Subsystem2.instance_for(self) So the author of execute() doesn't even need to think about scoping. What do you think? |
I'd like that too, but even further - dependency injection. The subsystems should be injected in the Task/Subsystem constructor. You shouldn't even need to ask for the thing 2x. That's a few refactors off though, and folks tend to retch at the mention of DI ao it may be controversial. Back to your suggestion, it does not allow for mixed scope instances of the same type, but maybe its fine to not allow this. IE: no depending on both the global instance and a scoped on from the same dependee. Putting that aside and considering "normal" use cases, it does seem like Subsystem could hang on to a class-level registry of requestors -> requested Subsystem types. |
T thing I suggested could be a common shortcut, but we'd still allow your The latter would be used in the rare case when the author of execute() On Tue, Aug 11, 2015 at 10:20 PM, John Sirois notifications@github.com
|
Good point - I like that. |
As noted in pantsbuild slack #general - This change should support separating the global subsystems from those that have been scoped when examining a dependencies list. |
It's a bit of a detour, but I do need this for my last #docfixit change, so I'll see if I can do this quick-like. |
Introduces the concept of a subsystem client, which Task and Subsystem mix in (this is not in Optionable because the GlobalOptionsRegistrar must not depend on any subsystems). All subsystem dependencies are expressed by the client by implementing subsystem_dependencies(). That dependency consists of a subsystem type and a scope. This generalizes the previous concept of global and task-specific subsystem dependencies. Contains a temporary hack so that the old declarations still work. Those will be mopped up in a followup change, just to keep this one from spiraling out too much. Issue: pantsbuild#1957
Introduces the concept of a subsystem client, which Task and Subsystem mix in (this is not in Optionable because the GlobalOptionsRegistrar must not depend on any subsystems). All subsystem dependencies are expressed by the client by implementing subsystem_dependencies(). That dependency consists of a subsystem type and a scope. This generalizes the previous concept of global and task-specific subsystem dependencies. Contains a temporary hack so that the old declarations still work. Those will be mopped up in a followup change, just to keep this one from spiraling out too much. Issue: pantsbuild#1957 Testing Done: CI passes: https://travis-ci.org/pantsbuild/pants/builds/76136929. Bugs closed: 1957 Reviewed at https://rbcommons.com/s/twitter/r/2653/
Implemented in https://rbcommons.com/s/twitter/r/2653/. |
I discussed this with @benjyw offline, but the current fork in TaskBase.{global_subsystems,task_subsystems} presents a few challenges including requiring scope derivation by 3rdparties instead of the dependees themselves and not being uniform from TaskBase to Subsystem (Subsystem has a single Subsystem dependecies method). The desired 2 API changes are as follows, and the rest should flow from there:
The same mix of global and scoped Subsystems can be depended on by Subsystems themselves using this API with a single dependencies method and a single instance method. The new
Subsystem.scoped(optionable)
method will return a new Subsystem subclass with the qualified scope baked in such that no calculation of actual scopes in-play will be needed. Instead, theSubsystem.closure
can be gathered and theSubsystem
(Optionable
) types can be directly consulted for their full.options_scope
.The text was updated successfully, but these errors were encountered: