Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove autocomplete promise, use _defaults
Autocomplete seems to be incompatible with `choices`, so I'll ignore
that for now. We also use `config._defaults` instead of an explicit
list to avoid duplication.
  • Loading branch information
PGijsbers committed Apr 8, 2021
commit ef8434b88861cb305542157d2ce8f81700b4b2c8
14 changes: 2 additions & 12 deletions openml/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,10 @@ def main() -> None:
parser_configure.add_argument(
"field",
type=str,
choices=[
"apikey",
"server",
"cachedir",
"avoid_duplicate_runs",
"connection_n_retries",
"verbosity",
"all",
"none",
],
choices=[*config._defaults.keys(), "all", "none"],
default="all",
nargs="?",
help="The field you wish to edit, auto-completes the field name, "
"e.g. `openml configure cache` is equivalent to `openml configure cachedir`."
help="The field you wish to edit."
"Choosing 'all' lets you configure all fields one by one."
"Choosing 'none' will print out the current configuration.",
)
Expand Down
14 changes: 3 additions & 11 deletions openml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,14 @@ def _get(config, key):

def set_field_in_config_file(field: str, value: Any):
""" Overwrites the `field` in the configuration file with the new `value`. """
fields = [
"apikey",
"server",
"cache_directory",
"avoid_duplicate_runs",
"connection_n_retries",
"max_retries",
]
if field not in fields:
return ValueError(f"Field '{field}' is not valid and must be one of '{fields}'.")
if field not in _defaults:
return ValueError(f"Field '{field}' is not valid and must be one of '{_defaults.keys()}'.")

globals()[field] = value
config_file = determine_config_file_path()
config = _parse_config(str(config_file))
with open(config_file, "w") as fh:
for f in fields:
for f in _defaults.keys():
# We can't blindly set all values based on globals() because the user when the user
# sets it through config.FIELD it should not be stored to file.
value = config.get("FAKE_SECTION", f)
Expand Down