Skip to content

Commit

Permalink
Fix verdi devel check-undesired-imports when tui extra is installed (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
danielhollas authored Feb 6, 2025
1 parent f43a510 commit 8039ad9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/aiida/cmdline/commands/cmd_devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down

1 comment on commit 8039ad9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'pytest-benchmarks:ubuntu-22.04,psql_dos'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 8039ad9 Previous: f43a510 Ratio
tests/benchmark/test_json_contains.py::test_deep_json[4-4] 308.5108931248128 iter/sec (stddev: 0.00015841) 693.306739203038 iter/sec (stddev: 0.000085426) 2.25

This comment was automatically generated by workflow using github-action-benchmark.

CC: @giovannipizzi @agoscinski @GeigerJ2 @khsrali @unkcpz

Please sign in to comment.