Skip to content

Commit 8039ad9

Browse files
authored
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.
1 parent f43a510 commit 8039ad9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

.github/workflows/ci-code.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ jobs:
126126
with:
127127
python-version: '3.12'
128128
from-lock: 'true'
129-
# NOTE: The `verdi devel check-undesired-imports` fails if
130-
# the 'tui' extra is installed.
131129
extras: ''
132130

133131
- name: Run verdi tests

src/aiida/cmdline/commands/cmd_devel.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ def devel_check_load_time():
6161
def devel_check_undesired_imports():
6262
"""Check that verdi does not import python modules it shouldn't.
6363
64-
Note: The blacklist was taken from the list of packages in the 'atomic_tools' extra but can be extended.
64+
This is to keep the verdi CLI snappy, especially for tab-completion.
6565
"""
6666
loaded_modules = 0
6767

68-
for modulename in [
69-
'asyncio',
68+
unwanted_modules = [
7069
'requests',
7170
'plumpy',
7271
'disk_objectstore',
@@ -78,7 +77,12 @@ def devel_check_undesired_imports():
7877
'spglib',
7978
'pymysql',
8079
'yaml',
81-
]:
80+
]
81+
# trogon powers the optional TUI and uses asyncio.
82+
# Check for asyncio only when the optional tui extras are not installed.
83+
if 'trogon' not in sys.modules:
84+
unwanted_modules += 'asyncio'
85+
for modulename in unwanted_modules:
8286
if modulename in sys.modules:
8387
echo.echo_warning(f'Detected loaded module "{modulename}"')
8488
loaded_modules += 1

0 commit comments

Comments
 (0)