Is there a way to go from a subsystem's class to a...
# development
c
Is there a way to go from a subsystem's class to an instantiated instance? example, given
class Black(PythonToolBase):
, if I have
Black
, can I get an instance
black
with all of the options filled in? I'm hoping to invoke
black.pex_requirements()
, but that's an instance method
w
Like, without running through the async rule graph?
Copy code
async def _run_black(
    request: AbstractFmtRequest.Batch,
    black: Black,
    interpreter_constraints: InterpreterConstraints,
) -> FmtResult:
    black_pex_get = Get(
        VenvPex,
        PexRequest,
        black.to_pex_request(interpreter_constraints=interpreter_constraints),
c
the problem I have is that I have
Copy code
@union
class ExportableTool:
    resolve_name: ClassVar[str]
    subsystem_cls: ClassVar[type]

class BlackExportableTool(ExportableTool):
    resolve_name = Black.options_scope
    subsystem_cls = Black
and in a rule I've got an instance of
BlackExportableTool
and would like to somehow get an instance of
black
It's not critical, I did some massaging and I only need the class
Black
in this case
c
You can reques it with a `Get`:
Get(Black, {})
but I guess the type is not known statically, no worries, you can leverage https://github.com/pantsbuild/pants/pull/16929 to provide the type dynamically.
oh, I hope that is dynamic enough for your case...
c
I finally had a chance to try this out. I don't think that works because I'd need to parametrise the output type, but that MR only allows the input type...
🤔 1