Even lazier cli
The introduced lazy imports work well and are a great step forward. I also like that we simply declare the imports once and then use the normal import syntax. This is much less intrusive than I thought initially.
However, I think we can push this further ahead and get below 100ms startup time. Which I also think is necessary to actually work with autocompletion.
There are two issues to solve.
First, group functions and context objects
The issue is that click is running the command group functions when sub commands are requested, e.g. when run nomad admin uploads ls --help
it will run nomad.cli.cli.cli
, nomad.cli.admin.admin.admin
, nomad.cli.admin.uploads.uploads
. This is done, even if you do not run a command, but just want to have help or completion. Also the POPO
class is used as a context object. Loading it from the utils
module costs time. We need to avoid both things.
I think we should drop the POPO class (its stupid anyways and only used here). We should have a real CliContext
class as part of the cli code, i.e. in nomad.cli.cli.py
. It should be possible to move the code from the group functions into respective methods of this class. The group functions itself should just fill attributes of the context class with parameter values. Only the commands should then invoke the necessary functions on the context class. This should allow us to delay all imports until actual command execution. Most groups are doing nothing, its just about cli
, uploads
, entries
, and client
.
Second, python vs. nomad
When I strip down the cli to basically do nothing. I get <10ms with python -m nomad.cli
, but a 800ms nomad
. Please investigate.
Finally, testing the cli speed
Once we get the startup time below <100ms, could you add a test for the cli that measures the time and asserts a low value. I want to avoid that we bring the speed down by adding import accidentally.
Supplemental, the completion install script
Instead having a script it should be a cli command itself to perform the install. Furthermore, we I think it is less intrusive to put commands directly into the .rc-files and do not create additional ~/.nomad-*.sh
files.