Command-line entry point for the dataset viewer.
Starts a single self-contained trame server. There is no FastAPI backend
and no separate port: dataset discovery, sample loading, CGNS export and
the 3D view are all served by the same trame process.
plaid.viewer.cli.main
Run the viewer until interrupted.
Parameters:
-
argv
(list[str] | None, default:
None
)
–
Optional override of sys.argv[1:] for tests.
Returns:
Source code in plaid/viewer/cli.py
| def main(argv: list[str] | None = None) -> int:
"""Run the viewer until interrupted.
Args:
argv: Optional override of ``sys.argv[1:]`` for tests.
Returns:
Process exit code.
"""
args = _build_parser().parse_args(argv)
logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s"
)
# Permanently silence the process's file-descriptor 2 so the HDF5 /
# CGNS C libraries (used by both VTK's ``vtkCGNSReader`` and PLAID's
# pyCGNS loader) cannot pollute the console with messages like
# ``Mismatch in number of children and child IDs read``. Python's
# ``sys.stderr`` is preserved so tracebacks and the logger keep
# working. See ``_reroute_c_stderr`` for the details.
from plaid.viewer.trame_app.server import ( # noqa: PLC0415
_reroute_c_stderr,
)
_reroute_c_stderr()
# When no explicit ``--datasets-root`` is passed, fall back to the
# last local root the user selected in a previous session (persisted
# under ``$XDG_CONFIG_HOME/plaid/viewer.json``). This makes the
# viewer "remember" the last dataset directory without requiring the
# CLI flag on every launch.
effective_datasets_root = args.datasets_root
if effective_datasets_root is None:
effective_datasets_root = get_last_datasets_root()
if effective_datasets_root is not None:
logger.info("Using persisted datasets root: %s", effective_datasets_root)
browse_roots = tuple(args.browse_roots) if args.browse_roots else ()
config = ViewerConfig(
datasets_root=effective_datasets_root,
browse_roots=browse_roots,
allow_root_change=not args.disable_root_change,
initial_dataset_id=args.dataset_id,
allow_dataset_change=not args.disable_dataset_change,
)
with CacheRoot() as cache:
dataset_service = PlaidDatasetService(config)
for repo_id in args.hub_repo or []:
try:
dataset_service.add_hub_dataset(repo_id)
except ValueError as exc:
logger.warning("Ignoring --hub-repo %r: %s", repo_id, exc)
artifact_service = ParaviewArtifactService(dataset_service, cache.path)
# Deferred import so ``--help`` works without trame installed.
from plaid.viewer.trame_app.server import build_server # noqa: PLC0415
server = build_server(dataset_service, artifact_service)
server.start(host=args.host, port=args.port, open_browser=False)
return 0
|