Skip to content

fix: remove import-time CLI output when loading TARDIS modules - #3497

Closed
xovishnukosuri wants to merge 2 commits into
tardis-sn:masterfrom
xovishnukosuri:fix-import-time-cli-output-3287
Closed

xovishnukosuri wants to merge 2 commits into
tardis-sn:masterfrom
xovishnukosuri:fix-import-time-cli-output-3287

Conversation

@xovishnukosuri

Copy link
Copy Markdown

Description

Type: bugfix

Fixes #3287

Loading TARDIS modules from a Python terminal produced unwanted output:

Iterations:                                                                                0/? [00:00<?, ?it/s]
Packets:                                                                                   0/? [00:00<?, ?it/s]
{'text/html': '...<plotly>...'}
<IPython.core.display.HTML object>
Initializing tabulator and plotly panel extensions for widgets to work

Four separate import-time side effects caused this:

  1. transport/montecarlo/progress_bars.py instantiated tqdm() bars at module level, which rendered them immediately in any environment including terminals.

  2. visualization/__init__.py called print() and pn.extension("tabulator", "plotly") unconditionally at import time. This fired whenever anything imported from tardis.visualization, including from tardis.visualization import ConvergencePlots in the workflow code.

  3. visualization/tools/convergence_plot.py called plotly.offline.init_notebook_mode(connected=True) and display(HTML(...)) at module level, emitting HTML to stdout.

  4. util/panel_init.py's auto() printed environment detection messages in every case, including terminals, and called pn.extension() in non-terminal unknown environments.

Changes:

  • progress_bars.py: Progress bars are now created lazily on first use via _get_iterations_pbar() / _get_packet_pbar(). A new close_progress_bars() function encapsulates cleanup.
  • visualization/__init__.py: Removed the unconditional print() and pn.extension("tabulator", "plotly").
  • panel_init.py: The tabulator and plotly extensions are now registered inside each environment-specific function (notebook, vscode, ssh_jh, sphinx), so they only run in widget-capable environments. Removed diagnostic print statements. In terminal environments, panel initialization is skipped entirely.
  • convergence_plot.py: Moved plotly.offline.init_notebook_mode and the MathJax display(HTML(...)) inside ConvergencePlots.build(), behind the display_plot=True guard where they only run when plots are actually being displayed.
  • conftest.py: Updated to use close_progress_bars() instead of importing the pbar globals directly.

Testing

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

AI Usage

I have read the checklist and the AI usage policy.
No AI or LLM tools were used in any part of the contribution.

Vishnu Kosuri and others added 2 commits March 14, 2026 11:46
In test_generate_plot_mpl and test_generate_plot_ply, the variable
named `expected` held a pd.HDFStore file handler, not plain data.
Rename it to `expected_fh` to make the type clear.

Closes tardis-sn#2864

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…s-sn#3287)

Loading TARDIS modules in a terminal caused unwanted output:
- tqdm progress bars rendered immediately on import of progress_bars.py
- Plotly HTML and a print() fired when importing tardis.visualization
- panel_init.auto() printed environment detection messages to stdout
- plotly.offline.init_notebook_mode() and display(HTML(...)) ran at
  module level in convergence_plot.py

Fix by deferring all initialization to first actual use:
- progress bars in progress_bars.py are created lazily via getter functions
- pn.extension("tabulator","plotly") and the print() are removed from
  visualization/__init__.py; the extensions are now registered inside
  panel_init.py so they only run in notebook/widget environments
- plotly.offline.init_notebook_mode and the MathJax display call are
  moved inside ConvergencePlots.build() behind the display_plot=True guard
- panel_init.auto() no longer prints environment detection messages;
  in terminal environments it skips panel initialization entirely
- conftest.py cleanup uses the new close_progress_bars() helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tardis-bot

Copy link
Copy Markdown
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot

Copy link
Copy Markdown
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and I noticed that your email is not associated with an ORCID ID in our database.

Please add your email and ORCID ID to the .orcid.csv file in your current branch and push the changes to this pull request.

If you don't have an ORCID ID yet, you can create one for free at orcid.org. ORCID IDs help ensure you get proper credit for your scientific contributions.

The format should be:

email,orcid
your.email@example.com,0000-0000-0000-0000

@tardis-bot

Copy link
Copy Markdown
Contributor

*beep* *bop*
Hi human,
I ran ruff on the latest commit (00a978b).
Here are the outputs produced.
Results can also be downloaded as artifacts here.
Summarised output:

Details
13	F401  	[ ] unused-import
3	I001  	[*] unsorted-imports
2	W293  	[*] blank-line-with-whitespace
1	W291  	[*] trailing-whitespace
1	F403  	[ ] undefined-local-with-import-star
1	F821  	[ ] undefined-name
1	PGH004	[ ] blanket-noqa
Found 22 errors.
[*] 9 fixable with the `--fix` option.

Complete output(might be large):

Details
tardis/conftest.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/conftest.py:14:1: F403 `from tardis.tests.fixtures.atom_data import *` used; unable to detect undefined names
tardis/conftest.py:16:36: F401 [*] `tardis.tests.test_util.monkeysession` imported but unused
tardis/conftest.py:19:12: F401 `tardisbase` imported but unused; consider using `importlib.util.find_spec` to test for availability
tardis/conftest.py:40:49: PGH004 Use specific rule codes when using `noqa`
tardis/conftest.py:42:9: F821 Undefined name `pytest_report_header`
tardis/conftest.py:330:1: W293 [*] Blank line contains whitespace
tardis/util/panel_init.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/util/panel_init.py:4:8: F401 [*] `os` imported but unused
tardis/util/panel_init.py:11:92: W291 [*] Trailing whitespace
tardis/util/panel_init.py:43:1: W293 [*] Blank line contains whitespace
tardis/visualization/__init__.py:3:57: F401 `tardis.visualization.tools.convergence_plot.ConvergencePlots` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:4:49: F401 `tardis.visualization.tools.liv_plot.LIVPlotter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:5:53: F401 `tardis.visualization.tools.rpacket_plot.RPacketPlotter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:6:50: F401 `tardis.visualization.tools.sdec_plot.SDECPlotter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:7:59: F401 `tardis.visualization.widgets.custom_abundance.CustomAbundanceWidget` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:8:51: F401 `tardis.visualization.widgets.grotrian.GrotrianWidget` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:9:52: F401 `tardis.visualization.widgets.line_info.LineInfoWidget` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:11:5: F401 `tardis.visualization.widgets.shell_info.shell_info_from_hdf` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/__init__.py:12:5: F401 `tardis.visualization.widgets.shell_info.shell_info_from_simulation` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/visualization/tools/convergence_plot.py:3:1: I001 [*] Import block is un-sorted or un-formatted
tardis/visualization/tools/convergence_plot.py:4:8: F401 [*] `warnings` imported but unused
Found 22 errors.
[*] 9 fixable with the `--fix` option.

@connor-mcclellan

Copy link
Copy Markdown
Contributor

The convergence plot fix has since been merged separately. Closing this because it would break a current progress bar test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loading TARDIS modules in the commandline causes Plotly and progress bar text to show

3 participants