Skip to content

Commit

Permalink
docs: do not replace link for self (#245)
Browse files Browse the repository at this point in the history
* _PATH_HERE
* skip itself
* self.name
* chlog
  • Loading branch information
Borda authored Mar 25, 2024
1 parent 19332de commit c8544d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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)

0 comments on commit c8544d4

Please sign in to comment.