Skip to content

Commit

Permalink
Merge pull request #3311 from boxydog/fix_3216_two_commits
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer authored May 30, 2024
2 parents f0b6e87 + 6d8597a commit 8d8feb6
Show file tree
Hide file tree
Showing 26 changed files with 148 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: v0.1.15
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
args: ["--check"]

exclude: ^pelican/tests/output/
8 changes: 4 additions & 4 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

# pelican.log has to be the first pelican module to be loaded
# because logging.setLoggerClass has to be called before logging.getLogger
from pelican.log import console
from pelican.log import console # noqa: I001
from pelican.log import init as init_logging
from pelican.generators import (
ArticlesGenerator, # noqa: I100
ArticlesGenerator,
PagesGenerator,
SourceFileGenerator,
StaticGenerator,
Expand Down Expand Up @@ -354,8 +354,8 @@ def parse_arguments(argv=None):
"--settings",
dest="settings",
help="The settings of the application, this is "
"automatically set to {} if a file exists with this "
"name.".format(DEFAULT_CONFIG_NAME),
f"automatically set to {DEFAULT_CONFIG_NAME} if a file exists with this "
"name.",
)

parser.add_argument(
Expand Down
1 change: 0 additions & 1 deletion pelican/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

from . import main


if __name__ == "__main__":
main()
13 changes: 6 additions & 7 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

from pelican.plugins import signals
from pelican.settings import DEFAULT_CONFIG, Settings

# Import these so that they're available when you import from pelican.contents.
from pelican.urlwrappers import Author, Category, Tag, URLWrapper # NOQA
from pelican.utils import (
deprecated_attribute,
memoized,
Expand All @@ -28,9 +31,6 @@
truncate_html_words,
)

# Import these so that they're available when you import from pelican.contents.
from pelican.urlwrappers import Author, Category, Tag, URLWrapper # NOQA

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -370,13 +370,13 @@ def _find_path(path: str) -> Optional[Content]:

def _get_intrasite_link_regex(self) -> re.Pattern:
intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"]
regex = r"""
regex = rf"""
(?P<markup><[^\>]+ # match tag with all url-value attributes
(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*)
(?P<quote>["\']) # require value to be quoted
(?P<path>{}(?P<value>.*?)) # the url value
(?P=quote)""".format(intrasite_link_regex)
(?P<path>{intrasite_link_regex}(?P<value>.*?)) # the url value
(?P=quote)"""
return re.compile(regex, re.X)

def _update_content(self, content: str, siteurl: str) -> str:
Expand Down Expand Up @@ -465,7 +465,6 @@ def _get_summary(self) -> str:
@summary.setter
def summary(self, value: str):
"""Dummy function"""
pass

@property
def status(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion pelican/plugins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pkgutil
import sys


logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion pelican/plugins/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from blinker import signal, Signal
from blinker import Signal, signal
from ordered_set import OrderedSet

# Signals will call functions in the order of connection, i.e. plugin order
Expand Down
4 changes: 2 additions & 2 deletions pelican/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
try:
from markdown import Markdown
except ImportError:
Markdown = False # NOQA
Markdown = False

# Metadata processors have no way to discard an unwanted value, so we have
# them return this value instead to signal that it should be discarded later.
Expand Down Expand Up @@ -607,8 +607,8 @@ def read_file(

# eventually filter the content with typogrify if asked so
if self.settings["TYPOGRIFY"]:
from typogrify.filters import typogrify
import smartypants
from typogrify.filters import typogrify

typogrify_dashes = self.settings["TYPOGRIFY_DASHES"]
if typogrify_dashes == "oldschool":
Expand Down
1 change: 0 additions & 1 deletion pelican/rstdirectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from docutils import nodes, utils
from docutils.parsers.rst import Directive, directives, roles

from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import TextLexer, get_lexer_by_name
Expand Down
6 changes: 2 additions & 4 deletions pelican/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ def _printf_s_to_format_field(printf_string: str, format_field: str) -> str:
TEST_STRING = "PELICAN_PRINTF_S_DEPRECATION"
expected = printf_string % TEST_STRING

result = printf_string.replace("{", "{{").replace("}", "}}") % "{{{}}}".format(
format_field
)
result = printf_string.replace("{", "{{").replace("}", "}}") % f"{{{format_field}}}"
if result.format(**{format_field: TEST_STRING}) != expected:
raise ValueError(f"Failed to safely replace %s with {{{format_field}}}")

Expand Down Expand Up @@ -412,7 +410,7 @@ def handle_deprecated_settings(settings: Settings) -> Settings:
)
logger.warning(message)
if old_values.get("SLUG"):
for f in {"CATEGORY", "TAG"}:
for f in ("CATEGORY", "TAG"):
if old_values.get(f):
old_values[f] = old_values["SLUG"] + old_values[f]
old_values["AUTHOR"] = old_values.get("AUTHOR", [])
Expand Down
2 changes: 1 addition & 1 deletion pelican/tests/build_test/test_build_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from re import match
import tarfile
from pathlib import Path
from re import match
from zipfile import ZipFile

import pytest
Expand Down
4 changes: 1 addition & 3 deletions pelican/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ def assertLogCountEqual(self, count=None, msg=None, **kwargs):
self.assertEqual(
actual,
count,
msg="expected {} occurrences of {!r}, but found {}".format(
count, msg, actual
),
msg=f"expected {count} occurrences of {msg!r}, but found {actual}",
)


Expand Down
1 change: 0 additions & 1 deletion pelican/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pelican.generators import ArticlesGenerator, PagesGenerator
from pelican.tests.support import get_context, get_settings, unittest


CUR_DIR = os.path.dirname(__file__)
CONTENT_DIR = os.path.join(CUR_DIR, "content")

Expand Down
2 changes: 0 additions & 2 deletions pelican/tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pelican.tests.support import LoggedTestCase, get_context, get_settings, unittest
from pelican.utils import path_to_url, posixize_path, truncate_html_words


# generate one paragraph, enclosed with <p>
TEST_CONTENT = str(generate_lorem_ipsum(n=1))
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
Expand Down Expand Up @@ -297,7 +296,6 @@ def test_template(self):
def test_signal(self):
def receiver_test_function(sender):
receiver_test_function.has_been_called = True
pass

receiver_test_function.has_been_called = False

Expand Down
2 changes: 1 addition & 1 deletion pelican/tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
TemplatePagesGenerator,
)
from pelican.tests.support import (
TestCaseWithCLocale,
can_symlink,
get_context,
get_settings,
unittest,
TestCaseWithCLocale,
)
from pelican.writers import Writer

Expand Down
14 changes: 6 additions & 8 deletions pelican/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from pelican.settings import DEFAULT_CONFIG
from pelican.tests.support import (
TestCaseWithCLocale,
mute,
skipIfNoExecutable,
temporary_folder,
unittest,
TestCaseWithCLocale,
)
from pelican.tools.pelican_import import (
blogger2fields,
Expand All @@ -19,12 +19,12 @@
download_attachments,
fields2pelican,
get_attachments,
tumblr2fields,
wp2fields,
medium_slug,
mediumpost2fields,
mediumposts2fields,
strip_medium_post_content,
medium_slug,
tumblr2fields,
wp2fields,
)
from pelican.utils import path_to_file_url, slugify

Expand All @@ -41,7 +41,7 @@
try:
from bs4 import BeautifulSoup
except ImportError:
BeautifulSoup = False # NOQA
BeautifulSoup = False

try:
import bs4.builder._lxml as LXML
Expand Down Expand Up @@ -532,9 +532,7 @@ def test_attachments_associated_with_correct_post(self):
self.assertEqual(self.attachments[post], {expected_invalid})
else:
self.fail(
"all attachments should match to a " "filename or None, {}".format(
post
)
"all attachments should match to a " f"filename or None, {post}"
)

def test_download_attachments(self):
Expand Down
1 change: 0 additions & 1 deletion pelican/tests/test_paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pelican.settings import DEFAULT_CONFIG
from pelican.tests.support import get_settings, unittest


# generate one paragraph, enclosed with <p>
TEST_CONTENT = str(generate_lorem_ipsum(n=1))
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
Expand Down
2 changes: 1 addition & 1 deletion pelican/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from contextlib import contextmanager

import pelican.tests.dummy_plugins.normal_plugin.normal_plugin as normal_plugin
from pelican.plugins._utils import (
get_namespace_plugins,
get_plugin_name,
load_plugins,
plugin_enabled,
)
from pelican.plugins.signals import signal
from pelican.tests.dummy_plugins.normal_plugin import normal_plugin
from pelican.tests.support import unittest


Expand Down
1 change: 0 additions & 1 deletion pelican/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pelican.tests.support import get_settings, unittest
from pelican.utils import SafeDatetime


CUR_DIR = os.path.dirname(__file__)
CONTENT_PATH = os.path.join(CUR_DIR, "content")

Expand Down
1 change: 0 additions & 1 deletion pelican/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
from os.path import abspath, dirname, join


from pelican.settings import (
DEFAULT_CONFIG,
DEFAULT_THEME,
Expand Down
1 change: 0 additions & 1 deletion pelican/tools/pelican_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pelican.settings import DEFAULT_CONFIG
from pelican.utils import SafeDatetime, slugify


logger = logging.getLogger(__name__)


Expand Down
6 changes: 3 additions & 3 deletions pelican/tools/pelican_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def ask_timezone(question, default, tzurl):
r = tz_dict[r]
break
else:
print("Please enter a valid time zone:\n" " (check [{}])".format(tzurl))
print("Please enter a valid time zone:\n" f" (check [{tzurl}])")
return r


Expand Down Expand Up @@ -205,14 +205,14 @@ def main():
args = parser.parse_args()

print(
"""Welcome to pelican-quickstart v{v}.
f"""Welcome to pelican-quickstart v{__version__}.
This script will help you create a new Pelican-based website.
Please answer the following questions so this script can generate the files
needed by Pelican.
""".format(v=__version__)
"""
)

project = os.path.join(os.environ.get("VIRTUAL_ENV", os.curdir), ".project")
Expand Down
14 changes: 3 additions & 11 deletions pelican/tools/pelican_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,11 @@ def install(path, v=False, u=False):
except OSError as e:
err(
"Cannot change permissions of files "
"or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)),
f"or directory in `{theme_path}':\n{e!s}",
die=False,
)
except Exception as e:
err(
"Cannot copy `{p}' to `{t}':\n{e}".format(
p=path, t=theme_path, e=str(e)
)
)
err(f"Cannot copy `{path}' to `{theme_path}':\n{e!s}")


def symlink(path, v=False):
Expand All @@ -268,11 +264,7 @@ def symlink(path, v=False):
try:
os.symlink(path, theme_path)
except Exception as e:
err(
"Cannot link `{p}' to `{t}':\n{e}".format(
p=path, t=theme_path, e=str(e)
)
)
err(f"Cannot link `{path}' to `{theme_path}':\n{e!s}")


def is_broken_link(path):
Expand Down
2 changes: 1 addition & 1 deletion pelican/urlwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __str__(self):
return self.name

def __repr__(self):
return f"<{type(self).__name__} {repr(self._name)}>"
return f"<{type(self).__name__} {self._name!r}>"

def _from_settings(self, key, get_page_name=False):
"""Returns URL information as defined in settings.
Expand Down
Loading

0 comments on commit 8d8feb6

Please sign in to comment.