Skip to content

Commit 1850872

Browse files
authored
Merge pull request #2530 from rohitshinde08/issue/2526
Fix broken relative links in README and CHANGELOG for both GitHub and Sphinx
2 parents 5e24c24 + b0fcc67 commit 1850872

6 files changed

Lines changed: 33 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ pyvenv.cfg
7878

7979
# Sphinx documentation build
8080
docs/_build/
81+
docs/generated/

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Changelog
22
=========
33

44
NOTE: isort follows the [semver](https://semver.org/) versioning standard.
5-
Find out more about isort's release policy [here](../docs/major_releases/release_policy.md).
5+
Find out more about isort's release policy [here](docs/major_releases/release_policy.md).
66

77
## Releases
88

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ editors](https://github.com/pycqa/isort/wiki/isort-Plugins) to
2727
quickly sort all your imports. It requires Python 3.10+ to run but
2828
supports formatting Python 2 code too.
2929

30-
- [Try isort now from your browser!](../docs/quick_start/0.-try.md)
31-
- [Using black? See the isort and black compatibility guide.](../docs/configuration/black_compatibility.md)
32-
- [isort has official support for pre-commit!](../docs/configuration/pre-commit.md)
30+
- [Try isort now from your browser!](docs/quick_start/0.-try.md)
31+
- [Using black? See the isort and black compatibility guide.](docs/configuration/black_compatibility.md)
32+
- [isort has official support for pre-commit!](docs/configuration/pre-commit.md)
3333

3434
![Example Usage](https://raw.github.com/pycqa/isort/main/example.gif)
3535

@@ -151,7 +151,7 @@ notified.
151151

152152
You will notice above the \"multi\_line\_output\" setting. This setting
153153
defines how from imports wrap when they extend past the line\_length
154-
limit and has [12 possible settings](../docs/configuration/multi_line_output_modes.md).
154+
limit and has [12 possible settings](docs/configuration/multi_line_output_modes.md).
155155

156156
## Indentation
157157

@@ -204,7 +204,7 @@ the `-e` option into the command line utility.
204204
isort provides configuration options to change almost every aspect of how
205205
imports are organized, ordered, or grouped together in sections.
206206

207-
[Click here](../docs/configuration/custom_sections_and_ordering.md) for an overview of all these options.
207+
[Click here](docs/configuration/custom_sections_and_ordering.md) for an overview of all these options.
208208

209209
## Skip processing of imports (outside of configuration)
210210

@@ -241,7 +241,7 @@ import a
241241

242242
isort can be ran or configured to add / remove imports automatically.
243243

244-
[See a complete guide here.](../docs/configuration/add_or_remove_imports.md)
244+
[See a complete guide here.](docs/configuration/add_or_remove_imports.md)
245245

246246
## Using isort to verify code
247247

@@ -272,7 +272,7 @@ project.
272272
isort provides a hook function that can be integrated into your Git
273273
pre-commit script to check Python code before committing.
274274

275-
[More info here.](../docs/configuration/git_hook.md)
275+
[More info here.](docs/configuration/git_hook.md)
276276

277277
## Spread the word
278278

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Changelog
22
=========
33

4-
.. include:: ../CHANGELOG.md
4+
.. include:: generated/CHANGELOG.md
55
:parser: myst_parser.sphinx_

docs/conf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import os
2+
import re
23
import sys
4+
from pathlib import Path
5+
6+
from sphinx.application import Sphinx
37

48
sys.path.insert(0, os.path.abspath(".."))
59

@@ -35,3 +39,21 @@
3539
"repo_name": "isort",
3640
"palette": {"primary": "deep-orange", "accent": "deep-orange"},
3741
}
42+
43+
44+
def _generate_includes(app: Sphinx) -> None:
45+
"""Create Sphinx-friendly copies of some files at build time."""
46+
# Use absolute paths based on this file's location
47+
root_dir = Path(__file__).parent.absolute().parent
48+
gen_dir = Path(__file__).parent.absolute() / "generated"
49+
gen_dir.mkdir(parents=True, exist_ok=True)
50+
51+
for file in ("CHANGELOG.md", "README.md"):
52+
content = (root_dir / file).read_text(encoding="utf-8")
53+
content = re.sub(r"\]\(docs/(.*?)\.md\)", r"](../\1)", content)
54+
(gen_dir / file).write_text(content, encoding="utf-8")
55+
56+
57+
def setup(app: Sphinx) -> None:
58+
"""Register build hooks."""
59+
app.connect("builder-inited", _generate_includes)

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Home
22
=====
33

4-
.. include:: ../README.md
4+
.. include:: generated/README.md
55
:parser: myst_parser.sphinx_
66

77
.. toctree::

0 commit comments

Comments
 (0)