HopkinsIDD / flepiMoP

The Flexible Epidemic Modeling Pipeline
https://flepimop.org
GNU General Public License v3.0
9 stars 4 forks source link

[Bug]: `gempyor.shared_cli.parse_config_files` Raises `ValueError` When Provided `$CONFIG_PATH` As Argument #389

Open TimothyWillard opened 1 week ago

TimothyWillard commented 1 week ago

Label

bug, config, gempyor

Priority Label

medium priority

Describe the bug/issue

If the $CONFIG_PATH environment variable is set this is treated as a config file being passed via the -c option and causes and error if the $CONFIG_PATH is provided as an argument. Not exactly sure what the correct treatment is here, I don't think we just want to take the union of the two generically, but maybe carve out this special case where only one config file is provided and it's the same? Could also check the $CONFIG_PATH env variable and if present in the arguments then remove from the options prior to this ValueError? I think the later is more robust.

To Reproduce

A bit contrived:

(flepimop-env) [twillard@longleaf-login4 flepimop_sample]$ echo $CONFIG_PATH
/work/users/t/w/twillard/flepimop_sample/config_sample_2pop_inference.yml
(flepimop-env) [twillard@longleaf-login4 flepimop_sample]$ flepimop patch $CONFIG_PATH
Traceback (most recent call last):
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/bin/flepimop", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nas/longleaf/home/twillard/.conda/envs/flepimop-env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/users/t/w/twillard/flepiMoP/flepimop/gempyor_pkg/src/gempyor/cli.py", line 27, in patch
    parse_config_files(config, ctx, **kwargs)
  File "/work/users/t/w/twillard/flepiMoP/flepimop/gempyor_pkg/src/gempyor/shared_cli.py", line 303, in parse_config_files
    raise ValueError(
ValueError: Exactly one config file source option must be provided; got {'config_files': (PosixPath('/work/users/t/w/twillard/flepimop_sample/config_sample_2pop_inference.yml'),), 'config_filepath': (PosixPath('/work/users/t/w/twillard/flepimop_sample/config_sample_2pop_inference.yml'),)}.

Although the same issue will appear when using gempyor.shared_cli.parse_config_files in other CLIs.

Environment, if relevant

dev branch, Python 3.11.10, R version 4.3.3

pearsonca commented 1 week ago

Hmm - I think there's a source check for options, and we can sniff for that and then issue a warning + ignore the environment variable