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.

[Bug] unable to use hydra with click module

See original GitHub issue

šŸ› Bug

I tried to use hydra with click module for creating CLI tools, but got an error.

To reproduce

import click
import hydra


@click.command()
@click.option('--foo', default='foo')
def main(**kwargs):
    my_app()
    print('hoge')
    print(kwargs)


@hydra.main(config_path='config.yml')
def my_app(cfg):
    print(cfg.pretty())


if __name__ == '__main__':
    main()

** Stack trace/error message **

hydra.errors.MissingConfigException: Cannot find primary config file: config.yml
Search path:
	pkg://hydra.conf (from hydra)
	pkg://click (from main)

Expected Behavior

System information

  • hydra-core==0.11.3
  • Click==7.0
  • python 3.6.10

Additional context

This error might be due to the arguement 3 of this line: https://github.com/facebookresearch/hydra/blob/2a9916133693247775472a4968904b7a05cca1c1/hydra/_internal/utils.py#L142

If I change this argument to -1, then it works well.

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
tasercakecommented, Apr 12, 2021

Does Hydra offer anything analogous to Clickā€™s group?

Iā€™m used to doing:

@click.group()
def main():
    pass

@main.command()
def sub_command_1():
    # Sub-functionality

@main.command()
def sub_command_2():
    # Sub-functionality

in Click and was hoping to do something similar with Hydra.

The workaround Iā€™m using for now involves setting a task key in my config and calling various functions according to its value, but that seems brittle compared to what Click offers.

6reactions
boweebcommented, Jul 29, 2021

For anyone late to the party (like me), there is a supported way to decouple the CLI and thus use click and hydra together. I just discovered this project this morning so this may not be the best answer but the the ā€œcompose apiā€ looks like the correct path.

Reference:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hydra returning error: "module option must start with http"
I am trying to brute force a web login password using hydra with the below command: hydra -s 8123 -x 2:8:aA1 -t 16...
Read more >
How to get a Hydra config without using @hydra.main()
This answer works for regular config files but lets say if you have different structures and paths/dirs/configs for stage/production/developmentĀ ...
Read more >
Hydra Logger - Fluke Calibration
clear the COM port for use with Hydra. Logger. Hydra n: RS-232. Communications Error. The selections for Baud Rate and Parity in Hydra...
Read more >
Problem with Bruteforce Using Hydra - Null Byte
Hi all, I started to learn using hydra recently and tried to brute force some web base login form which i already have...
Read more >
Hydra 1.0
After many months and a lot of hard work by many people, Hydra 1.0 is ... error reporting; Reduce nesting levels with config...
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