-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fixing Example and Adding Keyword Arguments as option for parameters #37
Conversation
Thanks! An easy addition, so it seems like a no-brainer. I'll have a look at it soon. |
One issue which just came into my mind is that we would need to decide which configuration will override in case of assigning different values as cli arguments and keyword arguments. |
Ok, I have been playing with this and this looks nice. So currently the parameters you pass to the |
Yes thats right... I initially thought it wouldn't matter because the user has to decide which option to use, but by ranking cli Arguments higher, we actually add a feature for the App developer to set standard parameters which can be overwritten by the user if his settings are different. I will implement a fix. |
@koenvervloesem i think i fixed the priorities |
@JonahKr I missed that you use args_dict only to edit self.args, while my changed version creates a new dict |
@maxbachmann yes me too.... i guess its fixed now |
No it still creates a new object |
@JonahKr Here is a better solution: args = {**kwargs, **vars(parser.parse_args())}
self.args = argparse.Namespace(**args) I think this makes more clear, that it is changing this Namespace object aswell, which was really easy to miss in the initial solution |
Edit: Confusion intensifies.... BUT @koenvervloesem the standard values are a breaking issue |
maybe we should finish this thread afterwards, close the pull request and create a new one, or otherwise a ton of commits without content thrash up the history |
thats true (this should have already the same problem in your initial priority change) |
yes but i didn't have the environment to test it and tried to replicate the environment. but now i finished the setup off a rhasspy container on my laptop so i tried it |
Ok I haven't tried to fix this code yet, but because it seems more difficult than I initially thought, I have written some test cases, so we can see for sure which corner cases are failing while trying to fix this. I think I have covered all relevant cases in the test, feel free to add tests if you think I missed something. As the tests show, the default CLI arguments are indeed problematic:
By the way, @JonahKr:
Comments won't end up as commits, so no worries :-) |
Ok I have something that seems to work, but it's a bit ugly :-) Can you two review this? |
Wouldn't this break when someone passes a default argument value on purpose to the cli? |
You're right, I even thought about it this morning, but forgot this when working on the fix. I have covered this test case now in the tests:
Still thinking about the best way to fix this... Just to make sure we're on the same page: when someone passes a default argument value on purpose as a command-line argument, this should take precedence over the value passed to the HermesApp object, right? |
yes I think it would be totally confusing when some command-line arguments take precedence while others do not. |
So, apparently argparse can't distinguish between an argument that it assigns its default value because you don't supply it and the same argument that you assign its default value explicitly. At least I haven't found a way. Maybe one of you has more luck finding it? |
@koenvervloesem could you add another test for the case that the user provides his own parser, that might both include optional and required arguments, but should apparently follow the same system that cli arguments take precendence over the kwargs |
Thanks, @maxbachmann! I added another test for verifying that it still works when you supply your own argument parser. If @JonahKr can have a look at the result, I think this is ready to be merged and create a new release :-) |
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 cannot test it atm but the code looks good. If both of you tested it and it works, it's ready to merge in my opinion.
But maybe merge it as 1 commit.😂 Because this hellscape of wrong code should never see the light of day again... |
I agree this should probably simply be squashed when merging |
python app = HermesApp("AdviceApp", host = "192.168.178.123", port = 12183)
Not sure if it should be restricted to the existing parameters (or some parameters exclusively) or not. I'm leaning towards no restrictions.