Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using relative config files in dicts and lists raises Unexpected import path format #557

Open
AlejandroBaron opened this issue Aug 8, 2024 · 3 comments
Labels

Comments

@AlejandroBaron
Copy link

Using relative config files in dicts doesn't work. It might be that I'm not using the correct syntax tho

To reproduce

3 files in the same directory

  1. cli.py
from jsonargparse import CLI
from typing import Dict, List

class MyObject:

    def __init__(self, x: int) -> None:
        self.x = x


class MyCLI:

    def __init__(self, d: Dict[str, MyObject]) -> None:
        self.d = d


CLI(MyCLI)

(If you use a List instead of Dict for d param, same error happens)

  1. main.yaml
d:
  obj1: ./my_obj.yaml
  1. my_obj.yaml
class_path: cli.MyObj
init_args:
  x: 3

Command: python cli.py --config main.yaml. Raises

error: Parser key "d":
  Unexpected import path format: ./my_obj.yaml

As I said it might not be a bug. I'm using python 3.8, but in the project that triggered this error I'm using python 3.9.

@AlejandroBaron AlejandroBaron added the bug Something isn't working label Aug 8, 2024
@mauvilsa
Copy link
Member

This is not a bug. Not everything can be parsed as a subconfig. A relative path to a subconfig inside another config only works if the parser has an action that would load it. Subconfigs are only available for top-level classes in a typehint, not nested like in a dict. Generally you can see which subconfigs can be loaded by printing the --help.

If not a bug, could this be added as a new feature? Might be, though most likely it would be technically quite complex and be low priority.

@AlejandroBaron
Copy link
Author

This is not a bug. Not everything can be parsed as a subconfig. A relative path to a subconfig inside another config only works if the parser has an action that would load it. Subconfigs are only available for top-level classes in a typehint, not nested like in a dict. Generally you can see which subconfigs can be loaded by printing the --help.

If not a bug, could this be added as a new feature? Might be, though most likely it would be technically quite complex and be low priority.

Yeah I assumed that it was not a bug but just not supported right now. Is there a way/plan to use resolvers like omegaconf does for this kind of situation?

@mauvilsa
Copy link
Member

omegaconf resolvers are able to load subconfigs? I don't see that here, but I am not an expert on that. If it is supported, then you can make jsonargparse to use omegaconf as the yaml loader.

@mauvilsa mauvilsa added enhancement New feature or request and removed bug Something isn't working labels Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants