-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Make loading of config lazy for improved responsiveness (#6140)
The `VerdiContext` class, which provides the custom context of the `verdi` commands, loads the configuration. This has a non-negligible cost and so slows down the responsiveness of the CLI. This is especially noticeable during tab-completion. The `obj` custom object of the `VerdiContext` is replaced with a subclass of `AttributeDict` that lazily populates the `config` key when it is called with the loaded `Config` class. In addition, the defaults of some options of the `verdi setup` command, which load a value from the config and so require the config, are turned into partials such that they also are lazily evaluated. These changes should give a reduction in load time of `verdi` of the order of ~50 ms. A test of `verdi setup` had to be updated to explicitly provide a value for the email. This is because now the default is evaluated lazily, i.e. when the command is actually called in the test. At this point, there is no value for this config option and so the default is empty. Before, the default would be evaluated as soon as `aiida.cmdline.commands.cmd_setup` was imported, at which point an existing config would still contain these values, binding them to the default, even if the config would be reset afterwards before the test.
- Loading branch information
1 parent
5ca609b
commit d533b7a
Showing
3 changed files
with
37 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,11 +205,12 @@ def test_setup_profile_uuid(self): | |
postgres.create_db(db_user, db_name) | ||
|
||
profile_name = 'profile-copy' | ||
user_email = '[email protected]' | ||
profile_uuid = str(uuid.uuid4) | ||
options = [ | ||
'--non-interactive', '--profile', profile_name, '--profile-uuid', profile_uuid, '--db-backend', | ||
self.storage_backend_name, '--db-name', db_name, '--db-username', db_user, '--db-password', db_pass, | ||
'--db-port', self.pg_test.dsn['port'] | ||
'--db-port', self.pg_test.dsn['port'], '--email', user_email | ||
] | ||
|
||
self.cli_runner(cmd_setup.setup, options, use_subprocess=False) | ||
|