Skip to content

Commit 8c7c2ac

Browse files
authored
Python Help Window Feature Addition - Use ConfigService for Docs Path (ornl-next merge) (#39226)
* Updates to enable config Service * Updates made based on comments. * Fix windows test failure. * Updates to handle file not found error
1 parent 4f1fcfd commit 8c7c2ac

File tree

5 files changed

+584
-268
lines changed

5 files changed

+584
-268
lines changed

qt/python/mantidqt/mantidqt/widgets/helpwindow/helpwindowbridge.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
1-
# Mantid Repository : https://github.com/mantidproject/mantid
2-
#
31
# Copyright © 2017 ISIS Rutherford Appleton Laboratory UKRI,
42
# NScD Oak Ridge National Laboratory, European Spallation Source,
53
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
64
# SPDX - License - Identifier: GPL - 3.0 +
7-
import os
85
import sys
9-
import argparse
106

117
from qtpy.QtWidgets import QApplication
128
from mantidqt.widgets.helpwindow.helpwindowpresenter import HelpWindowPresenter
139

1410
_presenter = None
1511

1612

17-
def show_help_page(relativeUrl, localDocs=None, onlineBaseUrl="https://docs.mantidproject.org/"):
13+
def show_help_page(relativeUrl, onlineBaseUrl="https://docs.mantidproject.org/"):
1814
"""
1915
Show the help window at the given relative URL path.
16+
Local docs path is now determined internally via ConfigService.
2017
"""
2118
global _presenter
2219
if _presenter is None:
23-
# Create a Presenter once. Re-use it on subsequent calls.
24-
_presenter = HelpWindowPresenter(localDocs=localDocs, onlineBaseUrl=onlineBaseUrl)
20+
_presenter = HelpWindowPresenter(onlineBaseUrl=onlineBaseUrl)
2521

26-
# Ask the Presenter to load the requested page
2722
_presenter.show_help_page(relativeUrl)
2823

2924

3025
def main(cmdargs=sys.argv):
3126
"""
3227
Run this script standalone to test the Python-based Help Window.
28+
Local docs path is determined from Mantid's ConfigService.
3329
"""
30+
import argparse
31+
3432
parser = argparse.ArgumentParser(description="Standalone test of the Python-based Mantid Help Window.")
3533
parser.add_argument(
3634
"relativeUrl", nargs="?", default="", help="Relative doc path (e.g. 'algorithms/Load-v1.html'), defaults to 'index.html' if empty."
3735
)
38-
parser.add_argument("--local-docs", default=None, help="Path to local Mantid HTML docs. Overrides environment if set.")
36+
3937
parser.add_argument(
4038
"--online-base-url",
4139
default="https://docs.mantidproject.org/",
42-
help="Base URL for online docs if local docs are not set or invalid.",
40+
help="Base URL for online docs if local docs path from config is invalid or not found.",
4341
)
4442
args = parser.parse_args(cmdargs or sys.argv[1:])
4543

46-
# If user gave no --local-docs, fall back to environment
47-
if args.local_docs is None:
48-
args.local_docs = os.environ.get("MANTID_LOCAL_DOCS_BASE", None)
44+
try:
45+
import mantid.kernel
46+
47+
log = mantid.kernel.Logger("HelpWindowBridge")
48+
log.information("Mantid kernel imported successfully.")
49+
except ImportError as e:
50+
print(f"ERROR: Failed to import Mantid Kernel: {e}", file=sys.stderr)
51+
print(
52+
"Ensure Mantid is built and PYTHONPATH is set correctly (e.g., export PYTHONPATH=/path/to/mantid/build/bin:$PYTHONPATH)",
53+
file=sys.stderr,
54+
)
55+
sys.exit(1)
4956

5057
app = QApplication(sys.argv)
5158

52-
# Show the requested help page
53-
show_help_page(relativeUrl=args.relativeUrl, localDocs=args.local_docs, onlineBaseUrl=args.online_base_url)
59+
show_help_page(relativeUrl=args.relativeUrl, onlineBaseUrl=args.online_base_url)
5460

5561
sys.exit(app.exec_())
5662

0 commit comments

Comments
 (0)