-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace (most) global state in cli/__init__.py (#9678)
* Rewrite helpful_test to appease the linter * Use public interface to access argparse sources dict * HelpfulParser builds ArgumentSources dict, stores it in NamespaceConfig After arguments/config files/user prompted input have been parsed, we build a mapping of Namespace options to an ArgumentSource value. These generally come from argparse's builtin "source_to_settings" dict, but we also add a source value representing dynamic values set at runtime. This dict is then passed to NamespaceConfig, which can then be queried directly or via the "set_by_user" method, which replaces the global "set_by_cli" and "option_was_set" functions. * Use NamespaceConfig.set_by_user instead of set_by_cli/option_was_set This involves passing the NamespaceConfig around to more functions than before, removes the need for most of the global state shenanigans needed by set_by_cli and friends. * Set runtime config values on the NamespaceConfig object This'll correctly mark them as being "runtime" values in the ArgumentSources dict * Bump oldest configargparse version We need a version that has get_source_to_settings_dict() * Add more cli unit tests, use ArgumentSource.DEFAULT by default One of the tests revealed that ConfigArgParse's source dict excludes arguments it considers unimportant/irrelevant. We now mark all arguments as having a DEFAULT source by default, and update them otherwise. * Mark more argument sources as RUNTIME * Removes some redundant helpful_test.py, moves one to cli_test.py We were already testing most of these cases in cli_test.py, only with a more complete HelpfulArgumentParser setup. And since the hsts/no-hsts test was manually performing the kind of argument adding that cli already does out of the box, I figured the cli tests were a more natural place for it. * appease the linter * Various fixups from review * Add windows compatability fix * Add test ensuring relevant_values behaves properly * Build sources dict in a more predictable manner The dict is now built in a defined order: first defaults, then config files, then env vars, then command line args. This way we eliminate the possibility of undefined behavior if configargparse puts an arg's entry in multiple source dicts. * remove superfluous update to sources dict * remove duplicate constant defines, resolve circular import situation
- Loading branch information
1 parent
b5661e8
commit a5d223d
Showing
22 changed files
with
494 additions
and
554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.