question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Emulate conventional commandline args

See original GitHub issue

Hi, this is not a feature request and more a general usage question. I’d you really like to give hydra a try in one of my existing projects. I have a program that from the outside looks like this to the user:

python main.py --arg1="ABC" --arg2="DEF" 

I know that you can create required arguments using ??? (like described here ). A program using hydra would look like this:

python main.py arg1="ABC" arg2="DEF" 

Is it somehow possible to add the -- (minus minus)? This may not sound like a big deal, but it is somewhat of a big deal to me, because it not, I would have to change several interface, when I use hydra.

Thank you, Flo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jpmartineaucommented, Jul 15, 2021

hannw:

You need to write a arg-preprocessing function that remaps your “–args val” or “–args=val” parameters to “cfg.something.arg=val”. This can be done by accessing and rewriting sys.argv before calling main. If you need the mapping to be dynamic (I did), you can pass it as an argument to the function itself.

Since many real-life scenarios (e.g.: AzureML HyperDrive) require this, such a utility function should be included with hydra, but sadly isn’t, and probably won’t ever be from what I read. As I wrote earlier, it’s quite frustrating and time-consuming for everyone

I included some code here. This should help those who are stuck with legacy code, or third-party calling sites.

Disclaimer: It’s a stripped-down version of my code, and I haven’t tested this stripped down version, but the code it’s based on works well, so it should be somewhat ok.

hydra_argv_remapper.zip

1reaction
r0f1commented, Feb 26, 2020

Thanks for the elaborate response!

Read more comments on GitHub >

github_iconTop Results From Across the Web

argparse — Parser for command-line options, arguments and ...
The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv . The argparse module...
Read more >
Python Command Line Arguments
To use Python command line arguments in this tutorial, you'll implement some partial features of two utilities from the Unix ecosystem:.
Read more >
Command-line syntax overview for System.CommandLine
An introduction to the command-line syntax that the System.CommandLine library recognizes by default. Mentions exceptions where syntax in ...
Read more >
picocli - a mighty tiny command line interface
The converter annotation does not require a CommandLine instance so it can be used ... Positional parameters of type boolean or Boolean require...
Read more >
Passing command line arguments to VirtualUI apps
If you have defined command line arguments in the application profile and need to send new arguments to the application by url, don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found