Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: do not replace link for self #245

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down
19 changes: 15 additions & 4 deletions src/lightning_utilities/docs/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading