From fd776e91dabd3e0b4f310ff91940450dd717566e Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 12:04:53 +0100 Subject: [PATCH 1/8] ci/docs: debug links --- docs/source/conf.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index a3007a04..453c2487 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -46,10 +46,12 @@ # -- Project documents ------------------------------------------------------- fetch_external_assets(docs_folder=_PATH_HERE) + +adjust_linked_external_docs( + "https://numpy.org/doc/stable/", "https://numpy.org/doc/{numpy.__version__}/", _PATH_ROOT +) adjust_linked_external_docs( - source_link="https://numpy.org/doc/stable/", - target_link="https://numpy.org/doc/{numpy.__version__}/", - browse_folder=_PATH_HERE, + "https://pytorch.org/docs/stable/", "https://pytorch.org/docs/{torch.__version__}/", _PATH_ROOT ) From 685de02b84c027fabfc2416507be2709936e04e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:06:27 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/conf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 453c2487..81f1ad98 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,9 +47,7 @@ fetch_external_assets(docs_folder=_PATH_HERE) -adjust_linked_external_docs( - "https://numpy.org/doc/stable/", "https://numpy.org/doc/{numpy.__version__}/", _PATH_ROOT -) +adjust_linked_external_docs("https://numpy.org/doc/stable/", "https://numpy.org/doc/{numpy.__version__}/", _PATH_ROOT) adjust_linked_external_docs( "https://pytorch.org/docs/stable/", "https://pytorch.org/docs/{torch.__version__}/", _PATH_ROOT ) From 3ae37cb41a77857931b363212af125482e941270 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 12:37:50 +0100 Subject: [PATCH 3/8] _PATH_HERE --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 81f1ad98..1e64f57f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,9 +47,9 @@ fetch_external_assets(docs_folder=_PATH_HERE) -adjust_linked_external_docs("https://numpy.org/doc/stable/", "https://numpy.org/doc/{numpy.__version__}/", _PATH_ROOT) +adjust_linked_external_docs("https://numpy.org/doc/stable/", "https://numpy.org/doc/{numpy.__version__}/", _PATH_HERE) adjust_linked_external_docs( - "https://pytorch.org/docs/stable/", "https://pytorch.org/docs/{torch.__version__}/", _PATH_ROOT + "https://pytorch.org/docs/stable/", "https://pytorch.org/docs/{torch.__version__}/", _PATH_HERE ) From ec43d524a391e2f5079413e9fcb85a18c620f4e5 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 12:43:28 +0100 Subject: [PATCH 4/8] skip itself --- src/lightning_utilities/docs/formatting.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lightning_utilities/docs/formatting.py b/src/lightning_utilities/docs/formatting.py index 32f616ac..8437b00a 100644 --- a/src/lightning_utilities/docs/formatting.py +++ b/src/lightning_utilities/docs/formatting.py @@ -157,10 +157,21 @@ def adjust_linked_external_docs( # replace the source link with target link for fpath in set(list_files): with open(fpath, encoding="UTF-8") as fopen: - body = fopen.read() - body_ = body.replace(source_link, target_link) - if body == body_: + lines = fopen.readlines() + found, skip = False, False + for i, ln in enumerate(lines): + # prevent the replacement its own function calls + if "adjust_linked_external_docs(" in ln: + skip = True + if not skip and source_link in ln: + # replace the link if any found + lines[i] = ln.replace(source_link, target_link) + # record the found link for later write file + found = True + if skip and ")" in ln: + skip = False + if not found: continue logging.debug(f'links adjusting in {fpath}: "{source_link}" -> "{target_link}"') with open(fpath, "w", encoding="UTF-8") as fw: - fw.write(body_) + fw.writelines(lines) From 588573c060664718f62cfa50836fb3454b335a48 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 13:47:34 +0100 Subject: [PATCH 5/8] fixme: remove this change before merge --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 1e64f57f..0a9bc22e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -253,7 +253,7 @@ def _convert_markdown(path_in: str, path_out: str, path_root: str) -> None: intersphinx_mapping = { "python": ("https://docs.python.org/3", None), "torch": ("https://pytorch.org/docs/stable/", None), - "numpy": ("https://numpy.org/doc/stable/", None), + "numpy": ("https://numpy.org/doc/1.26/", None), } # -- Options for todo extension ---------------------------------------------- From b0c61777ea8d1163898d2ee7bf61866f5a9e6046 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 13:49:42 +0100 Subject: [PATCH 6/8] Revert "fixme: remove this change before merge" This reverts commit 588573c060664718f62cfa50836fb3454b335a48. --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0a9bc22e..1e64f57f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -253,7 +253,7 @@ def _convert_markdown(path_in: str, path_out: str, path_root: str) -> None: intersphinx_mapping = { "python": ("https://docs.python.org/3", None), "torch": ("https://pytorch.org/docs/stable/", None), - "numpy": ("https://numpy.org/doc/1.26/", None), + "numpy": ("https://numpy.org/doc/stable/", None), } # -- Options for todo extension ---------------------------------------------- From 3bb0f380e7e50f261e910a93c09022f5b9c8eabc Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 13:53:50 +0100 Subject: [PATCH 7/8] self.name --- src/lightning_utilities/docs/formatting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_utilities/docs/formatting.py b/src/lightning_utilities/docs/formatting.py index 8437b00a..881339b6 100644 --- a/src/lightning_utilities/docs/formatting.py +++ b/src/lightning_utilities/docs/formatting.py @@ -161,7 +161,7 @@ def adjust_linked_external_docs( found, skip = False, False for i, ln in enumerate(lines): # prevent the replacement its own function calls - if "adjust_linked_external_docs(" in ln: + if f"{adjust_linked_external_docs.__name__}(" in ln: skip = True if not skip and source_link in ln: # replace the link if any found From 0fdbd48663b0b481c050bb07d2200cb4ba91cd56 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 25 Mar 2024 14:03:04 +0100 Subject: [PATCH 8/8] chlog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bca8b63b..4416e5fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - CI: enable setting python version for package build ([#244](https://github.com/Lightning-AI/utilities/pull/244)) +- docs: fix/use PyPI versions for pinning links ([#243](https://github.com/Lightning-AI/utilities/pull/243)) ### Deprecated @@ -26,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- docs: fix/use PyPI versions for pinning links ([#243](https://github.com/Lightning-AI/utilities/pull/243)) +- docs: do not replace external link for self ([#245](https://github.com/Lightning-AI/utilities/pull/245)) ## [0.11.0] - 2024-03-18