facebookresearch/hydra

[Feature Request] shell completion for Enum type

Open

#1.085 geöffnet am 21. Okt. 2020

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (1 zugewiesene Person)Python (608 Forks)batch import
enhancementhelp wantedtab_completionwishlist

Repository-Metriken

Stars
 (7.539 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 37T 6h) (25 gemergte PRs in 30 T)

Beschreibung

🚀 Feature Request

Tab completion suggesting all possible options when trying to set an Enum type config.

Motivation

Minimal example to illustrate the issue:

# example.py
import hydra
from hydra.core.config_store import ConfigStore
from dataclasses import dataclass
from enum import Enum


class AnEnum(Enum):
    OPTION_A = 1
    OPTION_B = 2


@dataclass
class AppConfig:
    an_enum_parameter: AnEnum = AnEnum.OPTION_A


# register config
cs = ConfigStore.instance()
cs.store(name="config", node=AppConfig)


@hydra.main(config_name="config")
def main(config: AppConfig):
    pass


if __name__ == "__main__":
    main()

With the above example, the tab completion only proposes the default option when trying to modify an_enum_parameter

python example.py an_enum_parameter=
# press TAB
python example.py an_enum_parameter=AnEnum.OPTION_A

Currently, one way to be aware of the available options is to enter an invalid option:

python example.py an_enum_parameter=INVALID
Error merging override an_enum_parameter=INVALID
Invalid value 'INVALID', expected one of [OPTION_A, OPTION_B]
        full_key: an_enum_parameter
        reference_type=Optional[AppConfig]
        object_type=AppConfig

Pitch

It would be great for hydra to suggest all possible values the same way it does for group config:

python example.py an_enum_parameter=
# press TAB
an_enum_parameter=AnEnum.OPTION_A an_enum_parameter=AnEnum.OPTION_B

Contributor Guide