From 872d1fb4f6359e601e89689404daf9d3eb43bc68 Mon Sep 17 00:00:00 2001 From: Piotr Rozyczko Date: Sun, 19 Apr 2026 09:19:47 +0200 Subject: [PATCH] check if the doc location is correct. Needs installer. --- src/sas/system/_help.py | 20 ++++++++++++++++---- test/system/utest_help.py | 31 ++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/sas/system/_help.py b/src/sas/system/_help.py index 086a62b5de..d5945c855d 100644 --- a/src/sas/system/_help.py +++ b/src/sas/system/_help.py @@ -2,6 +2,8 @@ import webbrowser from pathlib import Path +from packaging.version import parse + logger = logging.getLogger(__name__) @@ -10,12 +12,23 @@ def _release_version(version_string: str) -> str: Strips dev/pre-release suffixes so the version matches deployed documentation URLs. """ - from packaging.version import parse - version = parse(version_string) return f"{version.major}.{version.minor}.{version.micro}" +def _online_doc_base(version_string: str) -> str: + """Return the best online documentation base URL for a version string. + + Released documentation is archived under ``docs/old_docs/X.Y.Z``. + Development and pre-release builds should point at the current docs root. + """ + version = parse(version_string) + if version.is_devrelease or version.is_prerelease: + return "https://www.sasview.org/docs" + + return f"https://www.sasview.org/docs/old_docs/{_release_version(version_string)}" + + class _HelpSystem: """Extensible storage for help-system-related paths and configuration""" @@ -75,8 +88,7 @@ def _online_url(self, relative_path: Path, fragment: str = "") -> str: """Construct the online documentation URL for the current version.""" from sas.system.version import __version__ - version = _release_version(__version__) - base = f"https://www.sasview.org/docs/v{version}" + base = _online_doc_base(__version__) url = f"{base}/{relative_path.as_posix()}" if fragment: url += "#" + fragment diff --git a/test/system/utest_help.py b/test/system/utest_help.py index d56453397c..99d3b486b8 100644 --- a/test/system/utest_help.py +++ b/test/system/utest_help.py @@ -3,7 +3,7 @@ from pathlib import Path, PurePosixPath from unittest.mock import patch -from sas.system._help import _HelpSystem, _release_version +from sas.system._help import _HelpSystem, _online_doc_base, _release_version class PosixTestPath(PurePosixPath): @@ -29,6 +29,22 @@ def test_post_release_stripped(self): assert _release_version("6.1.2.post1") == "6.1.2" +class TestOnlineDocBase: + """Tests for online documentation base URL selection.""" + + def test_release_uses_archived_docs(self): + assert _online_doc_base("6.1.2") == "https://www.sasview.org/docs/old_docs/6.1.2" + + def test_post_release_uses_archived_docs(self): + assert _online_doc_base("6.1.2.post1") == "https://www.sasview.org/docs/old_docs/6.1.2" + + def test_dev_release_uses_current_docs(self): + assert _online_doc_base("6.1.2.dev159+g77be83657") == "https://www.sasview.org/docs" + + def test_pre_release_uses_current_docs(self): + assert _online_doc_base("6.2.0a1") == "https://www.sasview.org/docs" + + class TestHelpSystemOnlineUrl: """Tests for _HelpSystem._online_url()""" @@ -43,7 +59,7 @@ def test_online_url_basic(self, _mock): Path("user/qtgui/Perspectives/Fitting/fitting_help.html") ) assert url == ( - "https://www.sasview.org/docs/v6.1.2" + "https://www.sasview.org/docs/old_docs/6.1.2" "/user/qtgui/Perspectives/Fitting/fitting_help.html" ) @@ -52,7 +68,8 @@ def test_online_url_dev_version(self): url = self.hs._online_url( Path("user/qtgui/Perspectives/Fitting/fitting_help.html") ) - assert url.startswith("https://www.sasview.org/docs/v6.1.2/") + assert url.startswith("https://www.sasview.org/docs/") + assert "/old_docs/" not in url assert "+g77be83657" not in url assert ".dev159" not in url @@ -115,7 +132,7 @@ def test_online_fallback_when_local_missing(self, mock_wb, tmp_path): opened_url = mock_wb.open.call_args[0][0] assert opened_url == ( - "https://www.sasview.org/docs/v6.1.2/user/fitting.html" + "https://www.sasview.org/docs/old_docs/6.1.2/user/fitting.html" ) @patch("sas.system._help.webbrowser") @@ -138,7 +155,7 @@ def test_online_fallback_when_path_is_none(self, mock_wb): self.hs.show_help("user/fitting.html") opened_url = mock_wb.open.call_args[0][0] - assert opened_url.startswith("https://www.sasview.org/docs/v6.1.2/") + assert opened_url.startswith("https://www.sasview.org/docs/old_docs/6.1.2/") @patch("sas.system._help.webbrowser") def test_absolute_path_stripped_for_online(self, mock_wb, tmp_path): @@ -151,7 +168,7 @@ def test_absolute_path_stripped_for_online(self, mock_wb, tmp_path): opened_url = mock_wb.open.call_args[0][0] assert opened_url == ( - "https://www.sasview.org/docs/v6.1.2/user/fitting.html" + "https://www.sasview.org/docs/old_docs/6.1.2/user/fitting.html" ) @patch("sas.system._help.webbrowser") @@ -166,7 +183,7 @@ def test_posix_absolute_path_stripped_for_online(self, mock_wb): opened_url = mock_wb.open.call_args[0][0] assert opened_url == ( - "https://www.sasview.org/docs/v6.1.2/user/fitting.html" + "https://www.sasview.org/docs/old_docs/6.1.2/user/fitting.html" ) @patch("sas.system._help.webbrowser")