Skip to content

Commit 33bb476

Browse files
committed
Use a metadata hook to provide absolute links on PyPI
1 parent 0638547 commit 33bb476

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ Jupytext ChangeLog
1111
- The `rst2md` conversion now works with `sphinx-gallery>=0.8`. Thanks to [Thomas J. Fan](https://github.com/thomasjpfan) for fixing this! ([#1334](https://github.com/mwouts/jupytext/pull/1334))
1212
- We have updated the JupyterLab extension dependencies ([#1300](https://github.com/mwouts/jupytext/pull/1300), [#1355](https://github.com/mwouts/jupytext/pull/1355), [#1360](https://github.com/mwouts/jupytext/pull/1360)). Thanks to [Mahendra Paipuri](https://github.com/mahendrapaipuri) for these PRs!
1313

14+
**Added**
15+
- The context menu has a "New Text Notebook" entry. Thanks to [Mahendra Paipuri](https://github.com/mahendrapaipuri) for this PR ([#1365](https://github.com/mwouts/jupytext/pull/1365))!
16+
1417
**Fixed**
1518
- We have added and fixed round trip tests on MyST Markdown notebooks ([#759](https://github.com/mwouts/jupytext/issues/759), [#789](https://github.com/mwouts/jupytext/issues/789), [#1267](https://github.com/mwouts/jupytext/issues/1267), [#1317](https://github.com/mwouts/jupytext/issues/1317))
1619
- The `--quiet` option now works with the `--pipe` mode of Jupytext CLI ([#1305](https://github.com/mwouts/jupytext/issues/1305))
20+
- Jupytext is now compatible with the cell toolbar extension - thanks to [Nicolas Brichet](https://github.com/brichet) for the fix! ([#1358](https://github.com/mwouts/jupytext/pull/1358))
21+
- The project description on PyPI now uses absolute links ([#1287](https://github.com/mwouts/jupytext/issues/1287))
1722

1823

1924
1.16.7 (2025-02-09)

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = { file = "LICENSE" }
99
authors = [
1010
{ name = "Marc Wouts", email = "[email protected]" },
1111
]
12-
readme = "README.md"
12+
readme = "dist/README_with_absolute_links.md"
1313
requires-python = ">=3.8"
1414
classifiers = [
1515
"Development Status :: 5 - Production/Stable",
@@ -107,6 +107,9 @@ docs = [
107107
"jupytext" = "jupytext.cli:jupytext"
108108
"jupytext-config" = "jupytext_config.__main__:main"
109109

110+
[tool.hatch.metadata.hooks.custom]
111+
path = "tools/absolute_links_in_readme.py"
112+
110113
[tool.hatch.version]
111114
# Read version string from version.py and use it for the package
112115
path = "src/jupytext/version.py"

src/jupytext/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Jupytext's version number"""
22

3-
__version__ = "1.17.0-dev"
3+
__version__ = "1.17.0rc0"

tools/absolute_links_in_readme.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import re
2+
from pathlib import Path
3+
4+
from hatchling.metadata.plugin.interface import MetadataHookInterface
5+
6+
7+
class AbsoluteLinksInReadme(MetadataHookInterface):
8+
"""Hook that processes README.md to make relative links absolute."""
9+
10+
def update(self, metadata):
11+
"""Process README.md when metadata is being prepared."""
12+
readme_src_path = Path("README.md")
13+
readme_output_path = Path("dist/README_with_absolute_links.md")
14+
base_url = "https://github.com/mwouts/jupytext/blob/main/"
15+
16+
# Ensure the dist directory exists
17+
readme_output_path.parent.mkdir(exist_ok=True)
18+
19+
self.convert_links(readme_src_path, readme_output_path, base_url)
20+
return metadata
21+
22+
def convert_links(self, src_path, output_path, base_url):
23+
"""Convert relative links in README.md to absolute links."""
24+
print(f"Processing {src_path} to generate {output_path} with absolute links")
25+
content = src_path.read_text(encoding="utf-8")
26+
27+
# Find markdown links that don't start with http:// or https://
28+
pattern = re.compile(r"\[([^\]]+)\]\((?!http)([^)]+)\)")
29+
30+
def replace_link(match):
31+
text, url = match.groups()
32+
if not url.startswith(("http://", "https://", "#")):
33+
url = base_url + url
34+
return f"[{text}]({url})"
35+
36+
new_content = pattern.sub(replace_link, content)
37+
38+
# Write the processed content to the output file
39+
output_path.write_text(new_content, encoding="utf-8")
40+
print(f"Generated {output_path} with absolute links")

0 commit comments

Comments
 (0)