Skip to content

Commit 4f85f70

Browse files
authored
packaging: restore Python 3.8 and 3.9 (#304)
2 parents da3b135 + 541384d commit 4f85f70

21 files changed

+165
-91
lines changed

.github/workflows/lint-and-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
python-version:
25+
- "3.8"
26+
- "3.9"
2527
- "3.10"
2628
- "3.11"
2729
- "3.12"

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ repos:
3535
hooks:
3636
- id: pyupgrade
3737
args:
38-
- "--py310-plus"
38+
- "--py38-plus"
3939

4040
- repo: https://github.com/astral-sh/ruff-pre-commit
4141
rev: "v0.4.7"
4242
hooks:
4343
- id: ruff
4444
args:
4545
- --fix-only
46-
- --target-version=py310
46+
- --target-version=py38
4747

4848
- repo: https://github.com/pycqa/isort
4949
rev: 5.13.2
@@ -59,7 +59,7 @@ repos:
5959
hooks:
6060
- id: black
6161
args:
62-
- --target-version=py310
62+
- --target-version=py38
6363

6464
- repo: https://github.com/pycqa/flake8
6565
rev: 7.0.0

mkdocs_rss_plugin/__about__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#! python3 # noqa: E265
22

33
"""
4-
Metadata about the package to easily retrieve informations about it.
4+
Metadata about the package to easily retrieve informations about it.
55
6-
See: https://packaging.python.org/guides/single-sourcing-package-version/
6+
See: https://packaging.python.org/guides/single-sourcing-package-version/
77
"""
88

99
# ############################################################################

mkdocs_rss_plugin/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# ########## Libraries #############
55
# ##################################
66

7-
# standard
8-
from typing import Union
9-
107
# 3rd party
118
from mkdocs.config import config_options
129
from mkdocs.config.base import Config
@@ -21,8 +18,8 @@ class _DateFromMeta(Config):
2118

2219
# TODO: remove deprecated code in future version. Only str values will be accepted
2320
# for as_creation and as_update
24-
as_creation = config_options.Type(Union[bool, str], default="git")
25-
as_update = config_options.Type(Union[bool, str], default="git")
21+
as_creation = config_options.Type(str, default="git")
22+
as_update = config_options.Type(str, default="git")
2623
datetime_format = config_options.Type(str, default="%Y-%m-%d %H:%M")
2724
default_time = config_options.Type(str, default="00:00")
2825
default_timezone = config_options.Type(str, default="UTC")

mkdocs_rss_plugin/integrations/theme_material_social_plugin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
from hashlib import md5
1010
from pathlib import Path
11+
from typing import Optional
1112

1213
# 3rd party
1314
from mkdocs.config.defaults import MkDocsConfig
@@ -41,7 +42,7 @@ class IntegrationMaterialSocialCards:
4142
IS_SOCIAL_PLUGIN_CARDS_ENABLED: bool = True
4243
IS_THEME_MATERIAL: bool = False
4344
IS_INSIDERS: bool = False
44-
CARDS_MANIFEST: dict | None = None
45+
CARDS_MANIFEST: Optional[dict] = None
4546

4647
def __init__(self, mkdocs_config: MkDocsConfig, switch_force: bool = True) -> None:
4748
"""Integration instantiation.
@@ -103,7 +104,7 @@ def is_mkdocs_theme_material(self, mkdocs_config: MkDocsConfig) -> bool:
103104
self.IS_THEME_MATERIAL = mkdocs_config.theme.name == "material"
104105
return self.IS_THEME_MATERIAL
105106

106-
def is_mkdocs_theme_material_insiders(self) -> bool | None:
107+
def is_mkdocs_theme_material_insiders(self) -> Optional[bool]:
107108
"""Check if the material theme is community or insiders edition.
108109
109110
Returns:
@@ -195,7 +196,7 @@ def is_social_plugin_enabled_page(
195196
"cards", fallback_value
196197
)
197198

198-
def load_cache_cards_manifest(self) -> dict | None:
199+
def load_cache_cards_manifest(self) -> Optional[dict]:
199200
"""Load social cards manifest if the file exists.
200201
201202
Returns:
@@ -258,8 +259,8 @@ def get_social_cards_cache_dir(self, mkdocs_config: MkDocsConfig) -> Path:
258259
return self.social_cards_cache_dir
259260

260261
def get_social_card_build_path_for_page(
261-
self, mkdocs_page: Page, mkdocs_site_dir: str | None = None
262-
) -> Path | None:
262+
self, mkdocs_page: Page, mkdocs_site_dir: Optional[str] = None
263+
) -> Optional[Path]:
263264
"""Get social card path in Mkdocs build dir for a specific page.
264265
265266
Args:
@@ -287,7 +288,7 @@ def get_social_card_build_path_for_page(
287288
logger.debug(f"Not found: {expected_built_card_path}")
288289
return None
289290

290-
def get_social_card_cache_path_for_page(self, mkdocs_page: Page) -> Path | None:
291+
def get_social_card_cache_path_for_page(self, mkdocs_page: Page) -> Optional[Path]:
291292
"""Get social card path in social plugin cache folder for a specific page.
292293
293294
Note:
@@ -346,7 +347,7 @@ def get_social_card_cache_path_for_page(self, mkdocs_page: Page) -> Path | None:
346347
def get_social_card_url_for_page(
347348
self,
348349
mkdocs_page: Page,
349-
mkdocs_site_url: str | None = None,
350+
mkdocs_site_url: Optional[str] = None,
350351
) -> str:
351352
"""Get social card URL for a specific page in documentation.
352353

mkdocs_rss_plugin/models.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# standard
88
from datetime import datetime
99
from pathlib import Path
10-
from typing import NamedTuple
10+
from typing import NamedTuple, Optional
1111

1212

1313
# ############################################################################
@@ -16,14 +16,14 @@
1616
class PageInformation(NamedTuple):
1717
"""Data type to set and get page information in order to produce the RSS feed."""
1818

19-
abs_path: Path | None = None
20-
categories: list | None = None
21-
authors: tuple | None = None
22-
created: datetime | None = None
23-
description: str | None = None
24-
guid: str | None = None
25-
image: str | None = None
26-
title: str | None = None
27-
updated: datetime | None = None
28-
url_comments: str | None = None
29-
url_full: str | None = None
19+
abs_path: Optional[Path] = None
20+
categories: Optional[list] = None
21+
authors: Optional[tuple] = None
22+
created: Optional[datetime] = None
23+
description: Optional[str] = None
24+
guid: Optional[str] = None
25+
image: Optional[str] = None
26+
title: Optional[str] = None
27+
updated: Optional[datetime] = None
28+
url_comments: Optional[str] = None
29+
url_full: Optional[str] = None

mkdocs_rss_plugin/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from email.utils import formatdate
1212
from pathlib import Path
1313
from re import compile as re_compile
14+
from typing import List, Optional
1415

1516
# 3rd party
1617
from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -57,7 +58,7 @@ class GitRssPlugin(BasePlugin[RssPluginConfig]):
5758
def __init__(self):
5859
"""Instantiation."""
5960
# pages storage
60-
self.pages_to_filter: list[PageInformation] = []
61+
self.pages_to_filter: List[PageInformation] = []
6162
# prepare output feeds
6263
self.feed_created: dict = {}
6364
self.feed_updated: dict = {}
@@ -229,7 +230,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
229230
@event_priority(priority=-75)
230231
def on_page_content(
231232
self, html: str, page: Page, config: MkDocsConfig, files: Files
232-
) -> str | None:
233+
) -> Optional[str]:
233234
"""The page_content event is called after the Markdown text is rendered to HTML
234235
(but before being passed to a template) and can be used to alter the HTML
235236
body of the page.

mkdocs_rss_plugin/timezoner.py

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

33

44
"""
5-
Manage timezones for pages date(time)s using zoneinfo module, added in Python 3.9.
5+
Manage timezones for pages date(time)s using zoneinfo module, added in Python 3.9.
66
77
"""
88

mkdocs_rss_plugin/timezoner_pre39.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! python3 # noqa: E265
2+
3+
4+
"""
5+
Manage timezones for pages date(time)s using pytz module.
6+
Meant to be dropped when Python 3.8 reaches EOL.
7+
"""
8+
9+
# ############################################################################
10+
# ########## Libraries #############
11+
# ##################################
12+
13+
# standard library
14+
from datetime import datetime
15+
16+
# 3rd party
17+
import pytz
18+
from mkdocs.plugins import get_plugin_logger
19+
20+
# package
21+
from mkdocs_rss_plugin.constants import MKDOCS_LOGGER_NAME
22+
23+
# ############################################################################
24+
# ########## Globals #############
25+
# ################################
26+
27+
28+
logger = get_plugin_logger(MKDOCS_LOGGER_NAME)
29+
30+
31+
# ############################################################################
32+
# ########## Functions ###########
33+
# ################################
34+
35+
36+
def set_datetime_zoneinfo(
37+
input_datetime: datetime, config_timezone: str = "UTC"
38+
) -> datetime:
39+
"""Apply timezone to a naive datetime.
40+
41+
:param input_datetime: offset-naive datetime
42+
:type input_datetime: datetime
43+
:param config_timezone: name of timezone as registered in IANA database,
44+
defaults to "UTC". Example : Europe/Paris.
45+
:type config_timezone: str, optional
46+
47+
:return: offset-aware datetime
48+
:rtype: datetime
49+
"""
50+
if input_datetime.tzinfo:
51+
return input_datetime
52+
elif not config_timezone:
53+
return input_datetime.replace(tzinfo=pytz.utc)
54+
else:
55+
config_tz = pytz.timezone(config_timezone)
56+
return config_tz.localize(input_datetime)

0 commit comments

Comments
 (0)