-
Notifications
You must be signed in to change notification settings - Fork 116
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
Support passing variable number of arguments to resolvers. #46
Support passing variable number of arguments to resolvers. #46
Conversation
BTW when do you plan to publish a new version to pypi? Would be nice to not have to run my fork |
Pull Request Test Coverage Report for Build 245
💛 - Coveralls |
I am planning to make a pass at the open issues first. In the mean time, you can install from master by putting something like this in your setup.py: install_requires=[
"omegaconf@git+ssh://[email protected]/omry/omegaconf.git@master",
], |
What do you think about extending the resolver to properly accept multiple arguments instead? |
9430abb
to
221d5c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Can you keep the value (new terminology: ${func:value} as a string until it's actually passed to the user's function?
not sure if this is possible, but it feels like touches a bit too much. -
handle and test escaping.
-
Update documentation.
553d882
to
a987662
Compare
Cool, will update later tomorrow, got the tokenizer in the right place, just having some pains dealing with escaping spaces - ideally something like this would work, but no clean solution comes to mind off the top of my head
i.e. only need to escape whitespace at the "boundaries" of the word [edit] d'oh, just realised this is what you wrote earlier |
Great, I will take a closer look later. Re:
I think something like this would be a good overall strategy:
The first part is a bit tricky, you can achieve that relatively cleanly by replacing ',' with an illegal character like *, then split by that, and then replace it back. |
a987662
to
658adef
Compare
Un-brainfarted myself. I think the current version makes sense. The strategy is as follows:
Also added a doc example |
658adef
to
e96e53d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
b81cd62
to
79f114a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two small comments.
@pytest.mark.parametrize('resolver,name,key,result', [ | ||
(lambda *args: args, 'arg_list', "${my_resolver:cat, dog}",("cat", "dog")), | ||
(lambda *args: args, 'escape_comma',"${my_resolver:cat\, do g}",("cat, do g",)), | ||
(lambda *args: args, 'escape_whitespace',"${my_resolver:cat\, do g}",("cat, do g",)), | ||
(lambda: 'zero', 'zero_arg',"${my_resolver:}",("zero")), | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not familiar with this syntex. Why do you need it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean? Would you prefer I passed in entire config dictionaries as opposed to pairs of key, string_to_resolve
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I was confused by the lambda being passed there, I get why you need this now.
OmegaConf's templating language allows very few characters. There are some use cases where you'd want to have special characters so that your custom resolver can handle resolution there (kind of like embedding a templating language inside of OmegaConfs). This allows such behaviour without seemingly breaking anything too majorly
79f114a
to
3c053c4
Compare
@pytest.mark.parametrize('resolver,name,key,result', [ | ||
(lambda *args: args, 'arg_list', "${my_resolver:cat, dog}",("cat", "dog")), | ||
(lambda *args: args, 'escape_comma',"${my_resolver:cat\, do g}",("cat, do g",)), | ||
(lambda *args: args, 'escape_whitespace',"${my_resolver:cat\, do g}",("cat, do g",)), | ||
(lambda: 'zero', 'zero_arg',"${my_resolver:}",("zero")), | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I was confused by the lambda being passed there, I get why you need this now.
Thanks a lot for this! |
General feedback: |
Cool no problem, I normally default to pull-rebase so that merge commits don't come through and I didn't want to spam history with a bunch of |
This PR adds the ability to pass in 0 or more arguments to resolvers: