From e358298698ba9b3b2c004bdff7ab527e28b78220 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Tue, 5 Dec 2023 22:33:15 +0100 Subject: [PATCH] refacto: move global variables to constants module --- mkdocs_rss_plugin/constants.py | 24 +++++++++++++++++ .../{customtypes.py => models.py} | 2 +- mkdocs_rss_plugin/plugin.py | 27 ++++++++++--------- mkdocs_rss_plugin/util.py | 7 +---- 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 mkdocs_rss_plugin/constants.py rename mkdocs_rss_plugin/{customtypes.py => models.py} (97%) diff --git a/mkdocs_rss_plugin/constants.py b/mkdocs_rss_plugin/constants.py new file mode 100644 index 00000000..e2f4b7eb --- /dev/null +++ b/mkdocs_rss_plugin/constants.py @@ -0,0 +1,24 @@ +#! python3 # noqa: E265 + +# ############################################################################ +# ########## Libraries ############# +# ################################## + +# standard library +from pathlib import Path + +# package +from mkdocs_rss_plugin import __about__ + +# ############################################################################ +# ########## Globals ############# +# ################################ + +DEFAULT_TEMPLATE_FOLDER = Path(__file__).parent / "templates" +DEFAULT_TEMPLATE_FILENAME = DEFAULT_TEMPLATE_FOLDER / "rss.xml.jinja2" +OUTPUT_FEED_CREATED = "feed_rss_created.xml" +OUTPUT_FEED_UPDATED = "feed_rss_updated.xml" +REMOTE_REQUEST_HEADERS = { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "User-Agent": f"{__about__.__title__}/{__about__.__version__}", +} diff --git a/mkdocs_rss_plugin/customtypes.py b/mkdocs_rss_plugin/models.py similarity index 97% rename from mkdocs_rss_plugin/customtypes.py rename to mkdocs_rss_plugin/models.py index 4e026573..16c545bb 100644 --- a/mkdocs_rss_plugin/customtypes.py +++ b/mkdocs_rss_plugin/models.py @@ -4,7 +4,7 @@ # ########## Libraries ############# # ################################## -# standard library +# standard from datetime import datetime from pathlib import Path from typing import NamedTuple diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 3a121e1b..77cecae2 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -11,6 +11,7 @@ from email.utils import formatdate from pathlib import Path from re import compile +from typing import Optional # 3rd party from jinja2 import Environment, FileSystemLoader, select_autoescape @@ -23,18 +24,18 @@ # package modules from mkdocs_rss_plugin.__about__ import __title__, __uri__, __version__ from mkdocs_rss_plugin.config import RssPluginConfig -from mkdocs_rss_plugin.customtypes import PageInformation +from mkdocs_rss_plugin.constants import ( + DEFAULT_TEMPLATE_FILENAME, + DEFAULT_TEMPLATE_FOLDER, + OUTPUT_FEED_CREATED, + OUTPUT_FEED_UPDATED, +) +from mkdocs_rss_plugin.models import PageInformation from mkdocs_rss_plugin.util import Util # ############################################################################ # ########## Globals ############# # ################################ - -DEFAULT_TEMPLATE_FOLDER = Path(__file__).parent / "templates" -DEFAULT_TEMPLATE_FILENAME = DEFAULT_TEMPLATE_FOLDER / "rss.xml.jinja2" -OUTPUT_FEED_CREATED = "feed_rss_created.xml" -OUTPUT_FEED_UPDATED = "feed_rss_updated.xml" - logger = logging.getLogger("mkdocs.mkdocs_rss_plugin") @@ -50,14 +51,14 @@ def __init__(self): """Instanciation.""" # dates source self.src_date_created = self.src_date_updated = "git" - self.meta_datetime_format = None - self.meta_default_timezone = "UTC" - self.meta_default_time = None + self.meta_datetime_format: Optional[str] = None + self.meta_default_timezone: str = "UTC" + self.meta_default_time: Optional[str] = None # pages storage - self.pages_to_filter = [] + self.pages_to_filter: list = [] # prepare output feeds - self.feed_created = dict - self.feed_updated = dict + self.feed_created: dict = {} + self.feed_updated: dict = {} def on_config(self, config: config_options.Config) -> dict: """The config event is the first event called on build and diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index f67d3806..5069b6fe 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -25,7 +25,7 @@ from mkdocs.utils import get_build_datetime # package -from mkdocs_rss_plugin import __about__ +from mkdocs_rss_plugin.constants import REMOTE_REQUEST_HEADERS from mkdocs_rss_plugin.git_manager.ci import CiHandler # conditional imports @@ -38,11 +38,6 @@ # ########## Globals ############# # ################################ -REMOTE_REQUEST_HEADERS = { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "User-Agent": f"{__about__.__title__}/{__about__.__version__}", -} - logger = logging.getLogger("mkdocs.mkdocs_rss_plugin")