I have a script trainmodel.py coming from an existing codebase (based on Hugginface ArgumentParsers) with almost 100 different arguments that is based on argparse. The script comes as a main() function that parses individually each argument, and when run with no arguments produces the entire help text.
I need to wrap this script coming from another codebase into my Click based CLI, but I have hard times figuring out a good way to wrap it. Specifically the my cli interface should inherit all the trainmodel.py accepted arguments and kind of replicate them within the Click cli subcommand.
Here is an example of trainmodel.py
def main():
parser = HfArgumentParser(
(ModelArguments, DataTrainingArguments, TrainingArguments)
)
... lot of code to train a deep learning model with almost 100 parameters
My existing CLI though needs to subclass the existing main() function into a group of arguments based on my existing library CLI group
@click.command()
def my_train_model():
from models.trainmodel import main
main(*sys.argv[3:])
The command train_model is itself part of a click group from the outside cli.py
cli.py
@click.group(name="model")
def model():
pass
model.add_command(my_train_model)
cli.add_command(model)
For example, when I need to call the original script help, my interface with this call
mylibrary-cli model my-train-model --help
should pass the --help argument to the trainmodel.main() function and reproduce the arguments as from it.
How can I override the click interface and make the entire list of arguments be passed to the trainmodel.py script with the same help without manually copying all arguments inside my click.command decorated function my_train_model?
I would like to avoid hardcoding all the arguments accepted from trainmodel.main().