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 diff --git a/docs/source/conf.py b/docs/source/conf.py index a3007a04..1e64f57f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -46,10 +46,10 @@ # -- 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_HERE) 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_HERE ) diff --git a/src/lightning_utilities/docs/formatting.py b/src/lightning_utilities/docs/formatting.py index 32f616ac..881339b6 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 f"{adjust_linked_external_docs.__name__}(" 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)