Skip to content

Commit 457bb50

Browse files
authored
Merge branch 'main' into add-timestamps-to-index-hosted-attestations
2 parents 85c5efa + 41adab7 commit 457bb50

21 files changed

+168
-57
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
source/guides/github-actions-ci-cd-sample/* @webknjaz
22
source/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows.rst @webknjaz
33

4+
# Sphinx extension
5+
pug_sphinx_extensions/ @FFY00
6+
47
# build-details.json
58
source/specifications/build-details/ @FFY00
69
source/specifications/specs/build-details-*.json @FFY00

source/specifications/schemas/build-details-v1.0.schema.json renamed to extra/specifications/schemas/build-details-v1.0.schema.json

File renamed without changes.
File renamed without changes.
File renamed without changes.

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def linkcheck(session):
8989
"--keep-going", # be strict
9090
"source", # where the rst files are located
9191
"build", # where to put the check output
92+
*session.posargs,
9293
)
9394

9495

pug_sphinx_extensions/__init__.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import os
2+
import pathlib
3+
import urllib
4+
5+
import sphinx.application
6+
import sphinx.util.logging
7+
8+
9+
DOMAIN = "packaging.python.org"
10+
11+
12+
logger = sphinx.util.logging.getLogger(__name__)
13+
14+
15+
def resolve_local_html_link(app: sphinx.application.Sphinx, url_path: str) -> str:
16+
"""Takes path of a link pointing an HTML render of the current project,
17+
and returns local path of the referenced document.
18+
19+
Support links to renders from both the `html` and `dirhtml` builders.
20+
21+
Example:
22+
23+
.. code-block:: python
24+
25+
>>> resolve_local_html_link('https://packaging.python.org/en/latest/flow/')
26+
'{srcdir}/flow.rst'
27+
>>> resolve_local_html_link('https://packaging.python.org/en/latest/flow.html')
28+
'{srcdir}/flow.rst'
29+
>>> resolve_local_html_link('https://packaging.python.org/en/latest/specifications/schemas/')
30+
'{srcdir}/specifications/schemas/index.rst'
31+
>>> resolve_local_html_link('https://packaging.python.org/en/latest/specifications/schemas/build-details-v1.0.schema.json')
32+
'{html_extra_path0}/specifications/schemas/build-details-v1.0.schema.json'
33+
34+
"""
35+
# Search for document in html_extra_path
36+
for entry in app.config.html_extra_path:
37+
candidate = (app.confdir / entry / url_path).resolve()
38+
if candidate.is_dir():
39+
candidate = candidate / "index.html"
40+
if candidate.exists():
41+
return os.fspath(candidate)
42+
# Convert html path to source path
43+
url_path = url_path.removesuffix("/") # Normalize
44+
if url_path.endswith(".html"):
45+
document = url_path.removesuffix(".html")
46+
elif (candidate := f"{url_path}/index") in app.project.docnames:
47+
document = candidate
48+
else:
49+
document = url_path
50+
return app.env.doc2path(document)
51+
52+
53+
def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str:
54+
"""Replace remote URIs targeting https://packaging.python.org/en/latest/...
55+
with local ones, so that local changes are taken into account by linkcheck.
56+
57+
Additionally, resolve local relative links to html_extra_path.
58+
"""
59+
local_uri = uri
60+
parsed = urllib.parse.urlparse(uri)
61+
# Links to https://packaging.python.org/en/latest/...
62+
if parsed.hostname == DOMAIN and parsed.path.startswith("/en/latest/"):
63+
document = parsed.path.removeprefix("/en/latest/")
64+
local_uri = resolve_local_html_link(app, document)
65+
logger.verbose(
66+
f"{uri!s} is a remote URL that points to local sources, "
67+
"replacing it with a local URL in linkcheck to take new changes "
68+
"into account (pass -vv for more info)"
69+
)
70+
logger.debug(f"Replacing linkcheck URL {uri!r} with {local_uri!r}")
71+
# Local relative links
72+
if not parsed.scheme and not parsed.netloc and parsed.path:
73+
full_path = pathlib.Path(app.env.docname).parent / parsed.path
74+
local_uri = resolve_local_html_link(app, os.fspath(full_path))
75+
if local_uri != uri:
76+
logger.verbose(f"Local linkcheck URL {uri!r} resolved as {local_uri!r}")
77+
return local_uri
78+
79+
80+
def setup(app: sphinx.application.Sphinx) -> dict[str, bool]:
81+
app.connect("linkcheck-process-uri", rewrite_local_uri)
82+
83+
return {
84+
"parallel_read_safe": True,
85+
"parallel_write_safe": True,
86+
}

source/conf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
33

44
import os
5+
import pathlib
6+
import sys
7+
8+
_ROOT = pathlib.Path(__file__).resolve().parent.parent
9+
sys.path.append(os.fspath(_ROOT))
510

611
# Some options are only enabled for the main packaging.python.org deployment builds
712
RTD_BUILD = bool(os.getenv("READTHEDOCS"))
@@ -22,6 +27,7 @@
2227
root_doc = "index"
2328

2429
extensions = [
30+
"pug_sphinx_extensions",
2531
"sphinx.ext.extlinks",
2632
"sphinx.ext.intersphinx",
2733
"sphinx.ext.todo",
@@ -83,6 +89,10 @@
8389
# https://plausible.io/packaging.python.org
8490
html_js_files.extend(_metrics_js_files)
8591

92+
html_extra_path = [
93+
"../extra",
94+
]
95+
8696
# -- Options for HTML help output ------------------------------------------------------
8797
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-help-output
8898

@@ -129,7 +139,6 @@
129139

130140
linkcheck_ignore = [
131141
r"http://localhost:\d+",
132-
r"https://packaging\.python\.org/en/latest/specifications/schemas/.*",
133142
r"https://test\.pypi\.org/project/example-package-YOUR-USERNAME-HERE",
134143
r"https://pypi\.org/manage/.*",
135144
r"https://test\.pypi\.org/manage/.*",
@@ -210,7 +219,6 @@
210219
"tox": ("https://tox.wiki/en/latest/", None),
211220
"twine": ("https://twine.readthedocs.io/en/stable/", None),
212221
"virtualenv": ("https://virtualenv.pypa.io/en/stable/", None),
213-
"warehouse": ("https://warehouse.pypa.io/", None),
214222
}
215223

216224
# -- Options for todo extension --------------------------------------------------------

source/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Glossary
160160

161161
A string with valid SPDX license expression syntax,
162162
including one or more SPDX :term:`License Identifier`\(s),
163-
which describes a :term:`Project`'s license(s)
163+
which describes a :term:`Distribution Archive`'s license(s)
164164
and how they inter-relate.
165165
Examples:
166166
``GPL-3.0-or-later``,

source/guides/creating-command-line-tools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ To just run the program without installing it permanently, use ``pipx run``, whi
154154
$ pipx run --spec . greet --doctor
155155
156156
This syntax is a bit impractical, however; as the name of the entry point we defined above does not match the package name,
157-
we need to state explicitly which executable script to run (even though there is only on in existence).
157+
we need to state explicitly which executable script to run (even though there is only one in existence).
158158

159159
There is, however, a more practical solution to this problem, in the form of an entry point specific to ``pipx run``.
160160
The same can be defined as follows in :file:`pyproject.toml`:

source/guides/github-actions-ci-cd-sample/publish-to-test-pypi.yml renamed to source/guides/github-actions-ci-cd-sample/publish-to-pypi.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v6
1212
with:
1313
persist-credentials: false
1414
- name: Set up Python
15-
uses: actions/setup-python@v5
15+
uses: actions/setup-python@v6
1616
with:
1717
python-version: "3.x"
1818
- name: Install pypa/build
@@ -24,7 +24,7 @@ jobs:
2424
- name: Build a binary wheel and a source tarball
2525
run: python3 -m build
2626
- name: Store the distribution packages
27-
uses: actions/upload-artifact@v4
27+
uses: actions/upload-artifact@v5
2828
with:
2929
name: python-package-distributions
3030
path: dist/
@@ -44,7 +44,7 @@ jobs:
4444

4545
steps:
4646
- name: Download all the dists
47-
uses: actions/download-artifact@v4
47+
uses: actions/download-artifact@v6
4848
with:
4949
name: python-package-distributions
5050
path: dist/
@@ -66,7 +66,7 @@ jobs:
6666

6767
steps:
6868
- name: Download all the dists
69-
uses: actions/download-artifact@v4
69+
uses: actions/download-artifact@v6
7070
with:
7171
name: python-package-distributions
7272
path: dist/

0 commit comments

Comments
 (0)