Repository navigation
Commit 64111ab
CLI: Make loading of config lazy
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.1 parent 5ca609b commit 64111ab
3 files changed
Lines changed: 34 additions & 12 deletions
File tree
- aiida/cmdline
- groups
- params/options/commands
- tests/cmdline/commands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
37 | 64 | | |
38 | 65 | | |
39 | 66 | | |
40 | 67 | | |
41 | 68 | | |
42 | | - | |
43 | 69 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 70 | + | |
50 | 71 | | |
51 | 72 | | |
52 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | | - | |
| 213 | + | |
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| |||
0 commit comments