Skip to content

Patching argparse for non-standard applications #2598

Answered by dkajtoch
dkajtoch asked this question in Q&A
Discussion options

You must be logged in to vote

The following did the job although modifying sys.argv which is not pretty

import argparse
import sys
from typing import Any, Callable, Dict, List, Tuple, Union

import hydra
import wrapt
from omegaconf import DictConfig


def _namespace_to_hydra_overrides(args: argparse.Namespace) -> List[str]:
    overrides = []
    for key, val in vars(args).items():
        if val is not None:
            overrides.append(f"{key}={val}")
    return overrides


@wrapt.decorator
def translate_gcloud_ai_platform_argparse_to_hydra_overrides(
    fn: Callable,
    instance: Union[None, Any],
    args: Tuple[Any, ...],
    kwargs: Dict[str, Any],
):
    parser = argparse.ArgumentParser()
    parser.add_argument

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dkajtoch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants