Skip to content

Commit

Permalink
Merge branch 'main' into html5
Browse files Browse the repository at this point in the history
  • Loading branch information
nkr0 committed Jan 30, 2025
2 parents 3deb38e + 69e24fa commit 0882ffa
Show file tree
Hide file tree
Showing 19 changed files with 434 additions and 100 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ jobs:
strategy:
matrix:
os: [ubuntu, macos, windows]
python: ["3.10", "3.11", "3.12"]
python: ["3.10", "3.11", "3.12", "3.13"]
include:
- os: ubuntu
python: "3.8"
- os: ubuntu
python: "3.9"

Expand Down
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Release history
###############

4.11.0 - 2025-01-15
===================

- Add setting to selectively omit Typogrify filters `(#3439) <https://github.com/getpelican/pelican/pull/3439>`_
- Add more blocks to the Simple theme’s base template, making it easier to create new themes by inheriting from the Simple theme `(#3405) <https://github.com/getpelican/pelican/pull/3405>`_
- Fix auto-reload behavior upon changes to the theme, content or settings. Make default ``IGNORE_FILES`` recursively ignore all hidden files as well as the `default filters <https://watchfiles.helpmanual.io/api/filters/#watchfiles.DefaultFilter.ignore_dirs>`_ from ``watchfiles.DefaultFilter``. `(#3441) <https://github.com/getpelican/pelican/pull/3441>`_
- Get current year from the ``SOURCE_DATE_EPOCH`` environment variable, if available `(#3430) <https://github.com/getpelican/pelican/pull/3430>`_
- Add Python 3.13 to test matrix and remove Python 3.8 `(#3435) <https://github.com/getpelican/pelican/pull/3435>`_
- Require Typogrify 2.1+ and Pygments <2.19

4.10.2 - 2024-11-27
===================

Expand Down
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os
import sys
import time

if sys.version_info >= (3, 11):
import tomllib
Expand Down Expand Up @@ -30,7 +31,9 @@
source_suffix = ".rst"
master_doc = "index"
project = project_data.get("name").upper()
year = datetime.datetime.now().date().year
year = datetime.datetime.fromtimestamp(
int(os.environ.get("SOURCE_DATE_EPOCH", time.time())), datetime.timezone.utc
).year
copyright = f"2010–{year}" # noqa: RUF001
exclude_patterns = ["_build"]
release = project_data.get("version")
Expand Down
4 changes: 2 additions & 2 deletions docs/locale/zh_CN/LC_MESSAGES/settings.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ msgstr ""
msgid ""
"Settings are configured in the form of a Python module (a file). There is"
" an `example settings file "
"<https://github.com/getpelican/pelican/raw/main/samples/pelican.conf.py>`_"
"<https://raw.githubusercontent.com/getpelican/pelican/main/samples/pelican.conf.py>`_"
" available for reference."
msgstr ""
"设置以Python模块(一个文件)的形式。 `示例配置文件 "
"<https://github.com/getpelican/pelican/raw/main/samples/pelican.conf.py>`_"
"<https://raw.githubusercontent.com/getpelican/pelican/main/samples/pelican.conf.py>`_"
" 可供您参考。"

#: ../../settings.rst:34 fd01256fff0d40319c6bd55c3e3d1f8d
Expand Down
14 changes: 8 additions & 6 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ which you map the signals to your plugin logic. Let's take a simple example::
your ``register`` callable or they will be garbage-collected before the
signal is emitted.

If multiple plugins connect to the same signal, plugins will be executed in the
order they are connected. With ``PLUGINS`` setting, order will be as defined in
the setting. If you rely on auto-discovered namespace plugins, no ``PLUGINS``
setting, they will be connected in the same order they are discovered (same
order as ``pelican-plugins`` output). If you want to specify the order
explicitly, disable auto-discovery by defining ``PLUGINS`` in the desired order.
If multiple plugins connect to the same signal, plugins will be invoked in the
order they are registered. When the ``PLUGINS`` setting is defined, plugin
invocation order will be the order in which the plugins are listed in the
``PLUGINS`` setting. If you rely on auto-discovered namespace plugins and have
no ``PLUGINS`` setting defined, plugins will be invoked in the same order that
they are discovered (the same order as listed in the output of the
``pelican-plugins`` command). If you want to specify the order explicitly,
disable auto-discovery by defining ``PLUGINS`` in the desired order.

Namespace plugin structure
--------------------------
Expand Down
22 changes: 17 additions & 5 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Environment variables can also be used here but must be escaped appropriately::

Settings are configured in the form of a Python module (a file). There is an
`example settings file
<https://github.com/getpelican/pelican/raw/main/samples/pelican.conf.py>`_
<https://raw.githubusercontent.com/getpelican/pelican/main/samples/pelican.conf.py>`_
available for reference.

To see a list of current settings in your environment, including both default
Expand Down Expand Up @@ -150,13 +150,17 @@ Basic settings

READERS = {'foo': FooReader}

.. data:: IGNORE_FILES = ['.*']
.. data:: IGNORE_FILES = ['**/.*']

A list of glob patterns. Files and directories matching any of these patterns
will be ignored by the processor. For example, the default ``['.*']`` will
A list of Unix glob patterns. Files and directories matching any of these patterns
or any of the commonly hidden files and directories set by ``watchfiles.DefaultFilter``
will be ignored by the processor. For example, the default ``['**/.*']`` will
ignore "hidden" files and directories, and ``['__pycache__']`` would ignore
Python 3's bytecode caches.

For a full list of the commonly hidden files set by ``watchfiles.DefaultFilter``,
please refer to the `watchfiles documentation`_.

.. data:: MARKDOWN = {...}

Extra configuration settings for the Markdown processor. Refer to the Python
Expand Down Expand Up @@ -288,7 +292,14 @@ Basic settings

A list of tags for Typogrify to ignore. By default Typogrify will ignore
``pre`` and ``code`` tags. This requires that Typogrify version 2.0.4 or
later is installed
later is installed.

.. data:: TYPOGRIFY_OMIT_FILTERS = []

A list of Typogrify filters to skip. Allowed values are: ``'amp'``,
``'smartypants'``, ``'caps'``, ``'initial_quotes'``, ``'widont'``. By
default, no filter is omitted (in other words, all filters get applied). This
setting requires that Typogrify version 2.1.0 or later is installed.

.. data:: TYPOGRIFY_DASHES = 'default'

Expand Down Expand Up @@ -1416,3 +1427,4 @@ Example settings

.. _Jinja Environment documentation: https://jinja.palletsprojects.com/en/latest/api/#jinja2.Environment
.. _Docutils Configuration: http://docutils.sourceforge.net/docs/user/config.html
.. _`watchfiles documentation`: https://watchfiles.helpmanual.io/api/filters/#watchfiles.DefaultFilter.ignore_dirs
12 changes: 6 additions & 6 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from datetime import timezone
from html import unescape
from typing import Any, Dict, Optional, Set, Tuple
from typing import Any, Optional
from urllib.parse import ParseResult, unquote, urljoin, urlparse, urlunparse

try:
Expand Down Expand Up @@ -47,7 +47,7 @@ class Content:
"""

default_template: Optional[str] = None
mandatory_properties: Tuple[str, ...] = ()
mandatory_properties: tuple[str, ...] = ()

@deprecated_attribute(old="filename", new="source_path", since=(3, 2, 0))
def filename():
Expand All @@ -56,10 +56,10 @@ def filename():
def __init__(
self,
content: str,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[dict[str, Any]] = None,
settings: Optional[Settings] = None,
source_path: Optional[str] = None,
context: Optional[Dict[Any, Any]] = None,
context: Optional[dict[Any, Any]] = None,
):
if metadata is None:
metadata = {}
Expand Down Expand Up @@ -226,7 +226,7 @@ def is_valid(self) -> bool:
)

@property
def url_format(self) -> Dict[str, Any]:
def url_format(self) -> dict[str, Any]:
"""Returns the URL, formatted with the proper values"""
metadata = copy.copy(self.metadata)
path = self.metadata.get("path", self.get_relative_source_path())
Expand Down Expand Up @@ -397,7 +397,7 @@ def _update_content(self, content: str, siteurl: str) -> str:
hrefs = self._get_intrasite_link_regex()
return hrefs.sub(lambda m: self._link_replacer(siteurl, m), content)

def get_static_links(self) -> Set[str]:
def get_static_links(self) -> set[str]:
static_links = set()
hrefs = self._get_intrasite_link_regex()
for m in hrefs.finditer(self._content):
Expand Down
8 changes: 4 additions & 4 deletions pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import partial
from itertools import chain, groupby
from operator import attrgetter
from typing import List, Optional, Set
from typing import Optional

from jinja2 import (
BaseLoader,
Expand Down Expand Up @@ -158,8 +158,8 @@ def _include_path(self, path, extensions=None):
return False

def get_files(
self, paths, exclude: Optional[List[str]] = None, extensions=None
) -> Set[str]:
self, paths, exclude: Optional[list[str]] = None, extensions=None
) -> set[str]:
"""Return a list of files to use, based on rules
:param paths: the list pf paths to search (relative to self.path)
Expand Down Expand Up @@ -253,7 +253,7 @@ def __str__(self):
# return the name of the class for logging purposes
return self.__class__.__name__

def _check_disabled_readers(self, paths, exclude: Optional[List[str]]) -> None:
def _check_disabled_readers(self, paths, exclude: Optional[list[str]]) -> None:
"""Log warnings for files that would have been processed by disabled readers."""
for fil in self.get_files(
paths, exclude=exclude, extensions=self.readers.disabled_extensions
Expand Down
17 changes: 14 additions & 3 deletions pelican/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,22 @@ def read_file(
smartypants.Attr.default |= smartypants.Attr.w

def typogrify_wrapper(text):
"""Ensures ignore_tags feature is backward compatible"""
"""Ensure compatibility with older versions of Typogrify.
The 'TYPOGRIFY_IGNORE_TAGS' and/or 'TYPOGRIFY_OMIT_FILTERS'
settings will be ignored if the installed version of Typogrify
doesn't have the corresponding features."""
try:
return typogrify(text, self.settings["TYPOGRIFY_IGNORE_TAGS"])
return typogrify(
text,
self.settings["TYPOGRIFY_IGNORE_TAGS"],
**{f: False for f in self.settings["TYPOGRIFY_OMIT_FILTERS"]},
)
except TypeError:
return typogrify(text)
try:
typogrify(text, self.settings["TYPOGRIFY_IGNORE_TAGS"])
except TypeError:
return typogrify(text)

if content:
content = typogrify_wrapper(content)
Expand Down
9 changes: 5 additions & 4 deletions pelican/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from os.path import isabs
from pathlib import Path
from types import ModuleType
from typing import Any, Dict, Optional
from typing import Any, Optional

from pelican.log import LimitFilter

Expand All @@ -24,7 +24,7 @@ def load_source(name: str, path: str) -> ModuleType:

logger = logging.getLogger(__name__)

Settings = Dict[str, Any]
Settings = dict[str, Any]

DEFAULT_THEME = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "themes", "notmyidea"
Expand Down Expand Up @@ -149,6 +149,7 @@ def load_source(name: str, path: str) -> ModuleType:
"ARTICLE_PERMALINK_STRUCTURE": "",
"TYPOGRIFY": False,
"TYPOGRIFY_IGNORE_TAGS": [],
"TYPOGRIFY_OMIT_FILTERS": [],
"TYPOGRIFY_DASHES": "default",
"SUMMARY_END_SUFFIX": "…",
"SUMMARY_MAX_LENGTH": 50,
Expand All @@ -157,7 +158,7 @@ def load_source(name: str, path: str) -> ModuleType:
"PYGMENTS_RST_OPTIONS": {},
"TEMPLATE_PAGES": {},
"TEMPLATE_EXTENSIONS": [".html"],
"IGNORE_FILES": [".*"],
"IGNORE_FILES": ["**/.*"],
"SLUG_REGEX_SUBSTITUTIONS": [
(r"[^\w\s-]", ""), # remove non-alphabetical/whitespace/'-' chars
(r"(?u)\A\s*", ""), # strip leading whitespace
Expand Down Expand Up @@ -613,7 +614,7 @@ def configure_settings(settings: Settings) -> Settings:
]:
if key in settings and not isinstance(settings[key], types):
value = settings.pop(key)
logger.warn(
logger.warning(
"Detected misconfigured %s (%s), falling back to the default (%s)",
key,
value,
Expand Down
16 changes: 3 additions & 13 deletions pelican/tests/test_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from shutil import copy, rmtree
from tempfile import mkdtemp
from unittest.mock import MagicMock
Expand Down Expand Up @@ -1528,18 +1527,9 @@ def test_invalid_symlink_is_overwritten(self):
self.generator.generate_context()
self.generator.generate_output(None)
self.assertTrue(os.path.islink(self.endfile))

# os.path.realpath is broken on Windows before python3.8 for symlinks.
# This is a (ugly) workaround.
# see: https://bugs.python.org/issue9949
if os.name == "nt" and sys.version_info < (3, 8):

def get_real_path(path):
return os.readlink(path) if os.path.islink(path) else path
else:
get_real_path = os.path.realpath

self.assertEqual(get_real_path(self.endfile), get_real_path(self.startfile))
self.assertEqual(
os.path.realpath(self.endfile), os.path.realpath(self.startfile)
)

def test_delete_existing_file_before_mkdir(self):
with open(self.startfile, "w") as f:
Expand Down
Loading

0 comments on commit 0882ffa

Please sign in to comment.