Coding 2022-02-06

By Max Woerner Chase

Okay, I've decided that if I want to get anywhere with the Flex concept, I need to do some prototyping.

So, let's see what I've got...

from __future__ import annotations

import typing

import attr

T_co = typing.TypeVar("T_co", covariant=True)

@attr.dataclass(frozen=True)
class FlexIn(typing.Generic[T_co]):
    input: Dynamic[Input[T_co]]

    def as_arg(self: FlexIn[PathStr], keys) -> Requirements[...]:
        ...

    def as_env_var(self: FlexIn[PathStr], keys) -> Requirements[...]:
        ...

    def as_extra(self: FlexIn[Target], keys) -> Requirements[...]:
        ...

@attr.dataclass(frozen=True)
class FlexOut(typing.Generic[T_co]):
    input: Dynamic[Input[PathStr]]
    map: typing.Callable[[PathStr], T_co]
    dynamic_output: Dynamic[typing.Sequence[str]]
    target_key: Key[FlexIn[T_co]]
    make_parent: bool = False

    def as_arg(
        self: FlexOut[PathStr],
        keys,
    ) -> Requirements[...]:
        ...

    def as_env_var(
        self: FlexOut[PathStr],
        keys,
    ) -> Requirements[...]:
        ...

    def as_extra(
        self: FlexOut[Target],
        keys,
    ) -> Requirements[...]:
        ...

FlexType = typing.Union[FlexIn[T_co], FlexOut[T_co]]

Flex = FlexIn, FlexOut

This should be the basic outline of the Flex types, although it does need some work to nail down many of the details.

I did give this a few iterations just now, so this should illustrate most of the issues I need to deal with.

For now, I'm glad to have thought some of this through, and I'll look into putting this together with some of my notes. If I can nail down the right type for the keys arguments, I should be able to prove out these interfaces by replacing the existing stuff with them.

Right now, I want to rest.

Good night.