Skip to content
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

Make command orion db setup ask for right arguments based on storage backend. #586

Merged
merged 13 commits into from
Apr 1, 2021

Conversation

notoraptor
Copy link
Collaborator

Description

Update command line orion db setup to ask for arguments depending of storage backend typed in first question.

To automate retrieval of storage backend arguments, a class method get_arguments() is added to base class AbstractDB.

Fixes #573

Checklist

Tests

  • I added corresponding tests for bug fixes and new features. If possible, the tests fail without the changes
  • All new and existing tests are passing ($ tox -e py38; replace 38 by your Python version if necessary)

Quality

  • I have read the CONTRIBUTING doc
  • My commits messages follow this format
  • My code follows the style guidelines ($ tox -e lint)

config = {"database": {"type": _type, "name": name, "host": host}}
# Get database type.
while True:
_type = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to push this loop into ask_question with a choice argument. If there is no choice, the loop breaks directly, otherwise it ensures the user input is valid. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ! Done !

db_class = Database.types[Database.typenames.index(_type)]
db_args = db_class.get_arguments()
arg_vals = {}
for arg_name, default_value in db_args.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would sort the arguments here to make sure the order is deterministic.

Suggested change
for arg_name, default_value in db_args.items():
for arg_name, default_value in sorted(db_args.items()):

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@@ -330,3 +330,13 @@ def _sanitize_attrs(self):
self.options["authSource"] = settings["options"].get(
"authsource", self.name
)

@classmethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rename this defaults instead and use it inside __init__ to make sure the defaults are coherent. Otherwise we are starting to duplicate the defaults and they may diverge. (defaults here vs defaults in orion.config.storage.database)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand here, what should be renamed to defaults ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, the name of the class method, get_defaults.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ! Renamed get_arguments() to get_defaults() (in derived classes, too).

How should I use it inside __init__ ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the init, if a value is set to None or is an empty string, replace with value in get_defaults. Also you will need to use the default values as currently set in config here: https://github.com/Epistimio/orion/blob/develop/src/orion/core/__init__.py#L91. This way we harmonize the defaults.
See @abergeron 's PR for the defaults on PickledDB: https://github.com/Epistimio/orion/pull/585/files#diff-f4fa1b61f95de078bc5673f3d914867b67cef706344b651be8ee5cbeb2d17ad7R102

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ! Done !

…nal list) and `ignore_case` (bool, default False).

- choice: a list of expected value to check user answer against.
- ignore_case: a boolean to tell if checking against choice should be case-insensitive.
break
if answer in choice or (ignore_case and answer.lower() in choice):
break
print("Unexpected value {}\n".format(answer))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add here 'must be one of {}' and then list the valid choices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@bouthilx bouthilx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!! :)

@bouthilx bouthilx merged commit 072a84e into Epistimio:develop Apr 1, 2021
@notoraptor notoraptor deleted the command-line-db-setup branch February 1, 2022 16:14
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.

Adjust orion db setup prompts based on the storage backend used.
2 participants