Skip to content

Commit 24fd0d0

Browse files
authored
Merge branch 'main' into tutorial
2 parents e2149e3 + 83da985 commit 24fd0d0

25 files changed

+389
-319
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.1
22
jobs:
33
build-book:
44
docker:
5-
- image: cimg/python:3.9
5+
- image: cimg/python:3.13
66
steps:
77
- checkout
88
- run:

.github/workflows/build-book.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Python
2121
uses: actions/setup-python@v5
2222
with:
23-
python-version: "3.9"
23+
python-version: "3.13"
2424

2525
- name: Upgrade pip
2626
run: |
@@ -68,4 +68,4 @@ jobs:
6868
directory: "_build/html"
6969
arguments: |
7070
--ignore-files "/.+\/_static\/.+/,/genindex.html/"
71-
--ignore-status-codes "404, 403, 429, 503"
71+
--ignore-status-codes "0, 200, 403, 429, 503"

TRANSLATING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ If a language is ready to go live, the maintainers will add the language code to
287287

288288
When the guide is built for release in CI, Sphinx will also generate the translated versions of the guide for the languages in the `RELEASE_LANGUAGES` list.
289289

290-
Translations are released in the same way as the English version of the guide, and the translated versions will be available in folders named after the language code. For example, the Spanish translation will be available in [https://www.pyopensci.org/python-package-guide/es/](https://www.pyopensci.org/python-package-guide/es/).
290+
Translations are released in the same way as the English version of the guide, and the translated versions will be available in folders named after the language code. For example, the Spanish translation will be available at: `https://www.pyopensci.org/python-package-guide/es/` when it is published online.
291291

292292
## Frequently Asked Questions (FAQ)
293293

_ext/__init__.py

Whitespace-only changes.

_ext/rss.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Create an RSS feed of tutorials
3+
4+
Cribbed from: https://github.com/python/peps/blob/main/pep_sphinx_extensions/generate_rss.py
5+
"""
6+
7+
from dataclasses import dataclass, asdict
8+
from datetime import datetime, UTC
9+
from email.utils import format_datetime
10+
from html import escape
11+
from pprint import pformat
12+
from typing import TYPE_CHECKING
13+
from urllib.parse import urljoin
14+
15+
if TYPE_CHECKING:
16+
from sphinx.application import Sphinx
17+
18+
19+
def _format_rfc_2822(dt: datetime) -> str:
20+
datetime = dt.replace(tzinfo=UTC)
21+
return format_datetime(datetime, usegmt=True)
22+
23+
24+
@dataclass
25+
class RSSItem:
26+
title: str
27+
date: datetime
28+
description: str
29+
url: str
30+
author: str = "pyOpenSci"
31+
32+
@classmethod
33+
def from_meta(cls, page_name: str, meta: dict, app: "Sphinx") -> "RSSItem":
34+
"""Create from a page's metadata"""
35+
url = urljoin(app.config.html_baseurl, app.builder.get_target_uri(page_name))
36+
# purposely don't use `get` here because we want to error if these fields are absent
37+
return RSSItem(
38+
title=meta[":og:title"],
39+
description=meta[":og:description"],
40+
date=datetime.fromisoformat(meta["date"]),
41+
author=meta.get(":og:author", "pyOpenSci"),
42+
url=url,
43+
)
44+
45+
def render(self) -> str:
46+
return f"""\
47+
<item>
48+
<title>{escape(self.title, quote=False)}</title>
49+
<link>{escape(self.url, quote=False)}</link>
50+
<description>{escape(self.description, quote=False)}</description>
51+
<author>{escape(self.author, quote=False)}</author>
52+
<guid isPermaLink="true">{self.url}</guid>
53+
<pubDate>{_format_rfc_2822(self.date)}</pubDate>
54+
</item>"""
55+
56+
57+
@dataclass
58+
class RSSFeed:
59+
items: list[RSSItem]
60+
last_build_date: datetime = datetime.now()
61+
title: str = "pyOpenSci Tutorials"
62+
link: str = "https://www.pyopensci.org/python-package-guide/tutorials/intro.html"
63+
self_link: str = "https://www.pyopensci.org/python-package-guide/tutorials.rss"
64+
description: str = "Tutorials for learning python i guess!!!"
65+
language: str = "en"
66+
67+
def render(self) -> str:
68+
items = sorted(self.items, key=lambda i: i.date, reverse=True)
69+
items = "\n".join([item.render() for item in items])
70+
return f"""\
71+
<?xml version='1.0' encoding='UTF-8'?>
72+
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
73+
<channel>
74+
<title>{self.title}</title>
75+
<link>{self.link}</link>
76+
<atom:link href="{self.self_link}" rel="self"/>
77+
<description>{self.description}</description>
78+
<language>{self.language}</language>
79+
<lastBuildDate>{_format_rfc_2822(self.last_build_date)}</lastBuildDate>
80+
{items}
81+
</channel>
82+
</rss>
83+
"""
84+
85+
86+
def generate_tutorials_feed(app: "Sphinx"):
87+
from sphinx.util import logging
88+
89+
logger = logging.getLogger("_ext.rss")
90+
logger.info("Generating RSS feed for tutorials")
91+
metadata = app.builder.env.metadata
92+
tutorials = [t for t in metadata if t.startswith("tutorials/")]
93+
feed_items = [RSSItem.from_meta(t, metadata[t], app) for t in tutorials]
94+
feed = RSSFeed(items=feed_items)
95+
with open(app.outdir / "tutorials.rss", "w") as f:
96+
f.write(feed.render())
97+
98+
logger.info(
99+
f"Generated RSS feed for tutorials, wrote to {app.outdir / 'tutorials.rss'}"
100+
)
101+
logger.debug(f"feed items: \n{pformat([asdict(item) for item in feed_items])}")

bibliography.bib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ @misc{creativecommonsShareAlikeCompatibilityGPLv32015
3838
year = {2015},
3939
month = sep,
4040
journal = {Creative Commons Wiki},
41-
url = {https://wiki.creativecommons.org/wiki/ShareAlike\_compatibility:\_GPLv3},
41+
url = {https://wiki.creativecommons.org/wiki/ShareAlike_compatibility:_GPLv3},
4242
urldate = {2024-03-02}
4343
}

conf.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('.'))
1616
from datetime import datetime
1717
import subprocess
1818
import os
19+
from typing import TYPE_CHECKING
20+
from _ext import rss
21+
22+
if TYPE_CHECKING:
23+
from sphinx.application import Sphinx
1924

2025
current_year = datetime.now().year
2126
organization_name = "pyOpenSci"
@@ -96,9 +101,10 @@
96101
]
97102

98103
html_baseurl = "https://www.pyopensci.org/python-package-guide/"
104+
lang_selector_baseurl = "/python-package-guide/"
99105
if not sphinx_env == "production":
100106
# for links in language selector when developing locally
101-
html_baseurl = "/"
107+
lang_selector_baseurl = "/"
102108

103109
html_theme_options = {
104110
"announcement": "<p><a href='https://www.pyopensci.org/about-peer-review/index.html'>We run peer review of scientific Python software. Learn more.</a></p>",
@@ -148,7 +154,7 @@
148154
"github_version": "main",
149155
"language": language,
150156
"languages": build_languages,
151-
"baseurl": html_baseurl,
157+
"baseurl": lang_selector_baseurl,
152158
}
153159

154160
# Add any paths that contain templates here, relative to this directory.
@@ -198,3 +204,14 @@
198204
bibtex_bibfiles = ["bibliography.bib"]
199205
# myst complains about bibtex footnotes because of render order
200206
suppress_warnings = ["myst.footnote"]
207+
208+
209+
def _post_build(app: "Sphinx", exception: Exception | None) -> None:
210+
rss.generate_tutorials_feed(app)
211+
212+
213+
def setup(app: "Sphinx"):
214+
app.connect("build-finished", _post_build)
215+
216+
# Parallel safety: https://www.sphinx-doc.org/en/master/extdev/index.html#extension-metadata
217+
return {"parallel_read_safe": True, "parallel_write_safe": True}

documentation/repository-files/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name: moving-pandas-github-community
1616
width: 80%
1717
alt: Image showing that the MovingPandas GitHub repository community health page with green checks next to each file including a description, README, code of conduct, contributing, license and issue templates. Note that Security policy has a yellow circle next to it as that is missing from the repo.
1818
---
19-
GitHub community health looks for a readme file among other elements when it evaluates the community level health of your repository. This example is from the [MovingPandas GitHub repo](https://github.com/anitagraser/movingpandas/community) *(screen shot taken Nov 23 2022)*
19+
GitHub community health looks for a readme file among other elements when it evaluates the community level health of your repository. This example is from the [MovingPandas GitHub repo](https://github.com/movingpandas/movingpandas/community) *(screen shot taken Nov 23 2022)*
2020
```
2121

2222
[Snyk](https://snyk.io/advisor/python) is another well-known company that

documentation/repository-files/license-files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bibliography:
55

66
(license-file)=
77

8-
# License files for scientific Python open source software
8+
# License files for Python open source software
99

1010
:::{button-link} <https://www.pyopensci.org/about-peer-review/>
1111
:color: primary
@@ -69,7 +69,7 @@ in some cases the license that you want is not available through that online
6969
process.
7070

7171
:::{admonition} License recommendations from the SciPy package
72-
[The SciPy documentation has an excellent overview of licenses.](https://docs.scipy.org/doc/scipy/dev/core-dev/index.html#licensing). One of the key elements
72+
[The SciPy documentation has an excellent overview of licenses.](https://docs.scipy.org/doc/scipy/dev/core-dev/index.html#licensing) One of the key elements
7373
that these docs recommend is ensuring that the license that you select is
7474
compatible with licenses used in many parts of the scientific Python ecosystem.
7575
Below is a highlight of this text which outlines license that are compatible

0 commit comments

Comments
 (0)