Skip to content

Commit b173099

Browse files
authored
Infra: replace feedgen/lxml dependency to test Python 3.12-dev (python#2973)
1 parent a48b585 commit b173099

File tree

7 files changed

+46
-45
lines changed

7 files changed

+46
-45
lines changed

.github/workflows/render.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: ["3.x", "3.11-dev"]
12+
python-version: ["3.x", "3.12-dev"]
1313

1414
steps:
1515
- name: 🛎️ Checkout

.github/workflows/test.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
python-version: ["3.9", "3.10", "3.11-dev"]
25+
python-version: ["3.9", "3.10", "3.11", "3.12-dev"]
2626
os: [windows-latest, macos-latest, ubuntu-latest]
27-
# lxml doesn't yet install for 3.11 on Windows
28-
exclude:
29-
- { python-version: "3.11-dev", os: windows-latest }
3027

3128
steps:
3229
- uses: actions/checkout@v3

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ check-links: venv
2929
## rss to generate the peps.rss file
3030
.PHONY: rss
3131
rss: venv
32-
$(VENVDIR)/bin/python3 generate_rss.py
32+
$(VENVDIR)/bin/python3 generate_rss.py -o $(OUTPUT_DIR)
3333

3434
## clean to remove the venv and build files
3535
.PHONY: clean

generate_rss.py

+41-34
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# This file is placed in the public domain or under the
33
# CC0-1.0-Universal license, whichever is more permissive.
44

5+
import argparse
56
import datetime
67
import email.utils
8+
from html import escape
79
from pathlib import Path
810
import re
911

@@ -12,19 +14,16 @@
1214
from docutils import utils
1315
from docutils.parsers import rst
1416
from docutils.parsers.rst import roles
15-
from feedgen import entry
16-
from feedgen import feed
1717

1818
# get the directory with the PEP sources
1919
PEP_ROOT = Path(__file__).parent
2020

2121

22-
# Monkeypatch feedgen.util.formatRFC2822
2322
def _format_rfc_2822(dt: datetime.datetime) -> str:
23+
dt = dt.replace(tzinfo=datetime.timezone.utc)
2424
return email.utils.format_datetime(dt, usegmt=True)
2525

2626

27-
entry.formatRFC2822 = feed.formatRFC2822 = _format_rfc_2822
2827
line_cache: dict[Path, dict[str, str]] = {}
2928

3029
# Monkeypatch PEP and RFC reference roles to match Sphinx behaviour
@@ -137,6 +136,15 @@ def pep_abstract(full_path: Path) -> str:
137136

138137

139138
def main():
139+
parser = argparse.ArgumentParser(description="Generate RSS feed")
140+
parser.add_argument(
141+
"-o",
142+
"--output-dir",
143+
default="build", # synchronise with render.yaml -> deploy step
144+
help="Output directory, relative to root. Default 'build'.",
145+
)
146+
args = parser.parse_args()
147+
140148
# get list of peps with creation time (from "Created:" string in pep source)
141149
peps_with_dt = sorted((pep_creation(path), path) for path in PEP_ROOT.glob("pep-????.???"))
142150

@@ -152,21 +160,20 @@ def main():
152160
author = first_line_starting_with(full_path, "Author:")
153161
if "@" in author or " at " in author:
154162
parsed_authors = email.utils.getaddresses([author])
155-
# ideal would be to pass as a list of dicts with names and emails to
156-
# item.author, but FeedGen's RSS <author/> output doesn't pass W3C
157-
# validation (as of 12/06/2021)
158163
joined_authors = ", ".join(f"{name} ({email_address})" for name, email_address in parsed_authors)
159164
else:
160165
joined_authors = author
161166
url = f"https://peps.python.org/pep-{pep_num:0>4}/"
162167

163-
item = entry.FeedEntry()
164-
item.title(f"PEP {pep_num}: {title}")
165-
item.link(href=url)
166-
item.description(pep_abstract(full_path))
167-
item.guid(url, permalink=True)
168-
item.published(dt.replace(tzinfo=datetime.timezone.utc)) # ensure datetime has a timezone
169-
item.author(email=joined_authors)
168+
item = f"""\
169+
<item>
170+
<title>PEP {pep_num}: {escape(title, quote=False)}</title>
171+
<link>{escape(url, quote=False)}</link>
172+
<description>{escape(pep_abstract(full_path), quote=False)}</description>
173+
<author>{escape(joined_authors, quote=False)}</author>
174+
<guid isPermaLink="true">{url}</guid>
175+
<pubDate>{_format_rfc_2822(dt)}</pubDate>
176+
</item>"""
170177
items.append(item)
171178

172179
# The rss envelope
@@ -175,28 +182,28 @@ def main():
175182
language features, and some meta-information like release
176183
procedure and schedules.
177184
"""
178-
179-
# Setup feed generator
180-
fg = feed.FeedGenerator()
181-
fg.language("en")
182-
fg.generator("")
183-
fg.docs("https://cyber.harvard.edu/rss/rss.html")
184-
185-
# Add metadata
186-
fg.title("Newest Python PEPs")
187-
fg.link(href="https://peps.python.org")
188-
fg.link(href="https://peps.python.org/peps.rss", rel="self")
189-
fg.description(" ".join(desc.split()))
190-
fg.lastBuildDate(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc))
191-
192-
# Add PEP information (ordered by newest first)
193-
for item in items:
194-
fg.add_entry(item)
185+
last_build_date = _format_rfc_2822(datetime.datetime.utcnow())
186+
items = "\n".join(reversed(items))
187+
output = f"""\
188+
<?xml version='1.0' encoding='UTF-8'?>
189+
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
190+
<channel>
191+
<title>Newest Python PEPs</title>
192+
<link>https://peps.python.org/peps.rss</link>
193+
<description>{" ".join(desc.split())}</description>
194+
<atom:link href="https://peps.python.org/peps.rss" rel="self"/>
195+
<docs>https://cyber.harvard.edu/rss/rss.html</docs>
196+
<language>en</language>
197+
<lastBuildDate>{last_build_date}</lastBuildDate>
198+
{items}
199+
</channel>
200+
</rss>
201+
"""
195202

196203
# output directory for target HTML files
197-
out_dir = PEP_ROOT / "build"
198-
out_dir.mkdir(exist_ok=True)
199-
out_dir.joinpath("peps.rss").write_bytes(fg.rss_str(pretty=True))
204+
out_dir = PEP_ROOT / args.output_dir
205+
out_dir.mkdir(exist_ok=True, parents=True)
206+
out_dir.joinpath("peps.rss").write_text(output)
200207

201208

202209
if __name__ == "__main__":

readthedocs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
build:
44
os: ubuntu-22.04
55
tools:
6-
python: "3.10"
6+
python: "3.11"
77

88
commands:
99
- make dirhtml JOBS=$(nproc) OUTPUT_DIR=_readthedocs/html

requirements.txt

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ Pygments >= 2.9.0
55
Sphinx >= 5.1.1, != 6.1.0, != 6.1.1
66
docutils >= 0.19.0
77

8-
# For RSS
9-
feedgen >= 0.9.0 # For RSS feed
10-
118
# For tests
129
pytest
1310
pytest-cov

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
py{311, 310, 39}
3+
py{312, 311, 310, 39}
44
skipsdist = true
55

66
[testenv]

0 commit comments

Comments
 (0)