Skip to content

Conversation

@PGijsbers
Copy link
Collaborator

@PGijsbers PGijsbers commented Apr 8, 2021

Closes #1045

Adding a CLI which can be used to configure the fields in the configuration file.
This is a draft PR because it's feature incomplete (some fields are missing), but I wanted some input to see if this is an acceptable way to do it.

Installing openml with pip install openml will also add a cli script openml. It'll expect something like openml ROUTINE ROUTINE_ARGS, the current routine is only configure, but I figured some day we might use it for e.g. dataset download.
The signature of openml configure looks like this:

usage: openml configure [-h] [{apikey,server,cachedir,avoid_duplicate_runs,connection_n_retries,max_retries,all,none}]

Set or read variables in your configuration file. For more help also see 'https://openml.github.io/openml-
python/master/usage.html#configuration'.

positional arguments:
  {apikey,server,cachedir,avoid_duplicate_runs,connection_n_retries,max_retries,all,none}
                        The field you wish to edit.Choosing 'all' lets you configure all fields one by one.Choosing
                        'none' will print out the current configuration.

optional arguments:
  -h, --help            show this help message and exit

Video of current functionality.
I'm also planning for a direct option that avoids the explanation/interactive routine (e.g. openml config apikey 1234567890abcdef1234567890abcdef).
Update: It's also possible to use a non-interactive direct command, e.g.: openml configure apikey 1234567890abcdef1234567890abcdef.

 - Add function to set any field in the configuration file
 - Add function to read out the configuration file
 - Towards full configurability from CLI
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.
@PGijsbers PGijsbers requested a review from mfeurer April 8, 2021 09:34
@PGijsbers
Copy link
Collaborator Author

PGijsbers commented Apr 8, 2021

I do notice some downsides to using the configparser, e.g. you can't see which values are explicitly set or which are default (if the explicitly set value matches the default value). It also seems to complicate the code (e.g. having to create a virtual file with FAKE_SECTION). Considering our configurations haven't gotten any more complicated for years, I think we should be safe to assume the simple field = value format will last us a while longer, and it might be more easily readable to just write a custom parser for it. It should not take more than a few lines of codes, e.g.

set_fields ={}
with open(file, 'r') as fh:
    for line in fh.readlines():
        field, value = line.split('=', 1)
        set_fields[field.strip()] = value.strip()
config = {**_defaults, **set_fields}

Not entirely sure if I want to do that right now (I'd like this CLI done before my leave next week, and while simple I feel it should have extensive testing), but do you think we should consider that?

With the `openml configure FIELD VALUE` command.
Otherwise you have to duplicate all checks in the error message
function.
Max_retries is excluded because it should not be user configurable, and
will most likely be removed.
Verbosity is configurable but is currently not actually used.
And extend it to the bool inputs.
@PGijsbers PGijsbers marked this pull request as ready for review April 9, 2021 13:40
@PGijsbers
Copy link
Collaborator Author

Remarks while working on this:

  • max_retries is contained in _defaults but seems like it should be set by developers only. After discussing we probably want to avoid having such a number at all as long as we employ a decent retry policy (that waits increasingly long times).
  • the configparser note from above.
  • verbosity is currently not used in openml-python, I think this is a bug introduced by Rework local openml directory #987.

@PGijsbers PGijsbers merged commit dafe5ac into develop Apr 20, 2021
@PGijsbers PGijsbers deleted the configuration_ci branch April 20, 2021 07:49
github-actions bot pushed a commit that referenced this pull request Apr 20, 2021
PGijsbers added a commit to Mirkazemi/openml-python that referenced this pull request Feb 23, 2023
* Add a non-functional entry point

* Allow setting of API key through CLI

 - Add function to set any field in the configuration file
 - Add function to read out the configuration file
 - Towards full configurability from CLI

* 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.

* Add server configuration

* Allow fields to be set directly non-interactively

With the `openml configure FIELD VALUE` command.

* Combine error and check functionalities

Otherwise you have to duplicate all checks in the error message
function.

* Share logic about setting/collecting the value

* Complete CLI for other fields.

Max_retries is excluded because it should not be user configurable, and
will most likely be removed.
Verbosity is configurable but is currently not actually used.

* Bring back sanitizing user input

And extend it to the bool inputs.

* Add small bit of info about the command line tool

* Add API key configuration note in the introduction

* Add to progress log

* Refactor flow of wait_until_valid_input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a command line interface for (API key) configuration

3 participants