From 8039ad9147d2a4bc61bc86845a1c82c2fd484eae Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 6 Feb 2025 14:02:16 +0000 Subject: [PATCH] Fix verdi devel check-undesired-imports when tui extra is installed (#6693) `verdi devel check-undesired-imports` makes sure that we don't have heavy imports during verdi startup to keep the CLI snappy (especially for tab completion). One of the expensive modules that it checks is `asyncio`. Unfortunately, when you install the tui extra, the trogon package that powers the tui functionality seems to use asyncio, and this makes the test fail. (indeed, one of the TUIs current downsides is that it makes all CLI interactions slower, even if you don't use the TUI subcommand). The PR makes the test more clever and don't check for `asyncio` import when `tui` extras is installed. --- .github/workflows/ci-code.yml | 2 -- src/aiida/cmdline/commands/cmd_devel.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-code.yml b/.github/workflows/ci-code.yml index 65bb5a0a19..77ecdc7a9c 100644 --- a/.github/workflows/ci-code.yml +++ b/.github/workflows/ci-code.yml @@ -126,8 +126,6 @@ jobs: with: python-version: '3.12' from-lock: 'true' - # NOTE: The `verdi devel check-undesired-imports` fails if - # the 'tui' extra is installed. extras: '' - name: Run verdi tests diff --git a/src/aiida/cmdline/commands/cmd_devel.py b/src/aiida/cmdline/commands/cmd_devel.py index f8c89d14c1..b311e5706e 100644 --- a/src/aiida/cmdline/commands/cmd_devel.py +++ b/src/aiida/cmdline/commands/cmd_devel.py @@ -61,12 +61,11 @@ def devel_check_load_time(): def devel_check_undesired_imports(): """Check that verdi does not import python modules it shouldn't. - Note: The blacklist was taken from the list of packages in the 'atomic_tools' extra but can be extended. + This is to keep the verdi CLI snappy, especially for tab-completion. """ loaded_modules = 0 - for modulename in [ - 'asyncio', + unwanted_modules = [ 'requests', 'plumpy', 'disk_objectstore', @@ -78,7 +77,12 @@ def devel_check_undesired_imports(): 'spglib', 'pymysql', 'yaml', - ]: + ] + # trogon powers the optional TUI and uses asyncio. + # Check for asyncio only when the optional tui extras are not installed. + if 'trogon' not in sys.modules: + unwanted_modules += 'asyncio' + for modulename in unwanted_modules: if modulename in sys.modules: echo.echo_warning(f'Detected loaded module "{modulename}"') loaded_modules += 1