Skip to content

Commit

Permalink
Update code for Ruff code style compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer committed May 27, 2024
1 parent 0b7996b commit a9df30c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
25 changes: 9 additions & 16 deletions pelican/plugins/pdf/pdf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
PDF Generator
-------
"""PDF Generator plugin for Pelican.
The pdf plugin generates PDF files from reStructuredText and Markdown sources.
This plugin generates PDF files from reStructuredText and Markdown source files.
"""

from itertools import chain
Expand All @@ -21,7 +19,7 @@


class PdfGenerator(Generator):
"Generate PDFs on the output dir, for all articles and pages"
"""Generate PDFs on the output dir, for all articles and pages."""

supported_md_fields = ["date"]

Expand All @@ -33,10 +31,7 @@ def __init__(self, *args, **kwargs):
else:
pdf_style_path = []

if "PDF_STYLE" in self.settings:
pdf_style = [self.settings["PDF_STYLE"]]
else:
pdf_style = []
pdf_style = [self.settings["PDF_STYLE"]] if "PDF_STYLE" in self.settings else []

self.pdfcreator = RstToPdf(
breakside=0, stylesheets=pdf_style, style_path=pdf_style_path, raw_html=True
Expand Down Expand Up @@ -95,7 +90,7 @@ def _create_pdf(self, obj, output_path):
hrefs = self._get_intrasite_link_regex()
text = hrefs.sub(lambda m: obj._link_replacer(obj.get_siteurl(), m), text)

logger.info(" [ok] writing %s" % output_pdf)
logger.info(f" [ok] writing {output_pdf}")

self.pdfcreator.createPdf(text=(header + text), output=output_pdf)

Expand All @@ -104,11 +99,9 @@ def _create_pdf(self, obj, output_path):

def _get_intrasite_link_regex(self):
intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"]
regex = r"""
(?P<markup>)(?P<quote>)(?P<path>(\:?){}(?P<value>.*?)(?=[>\n]))
""".format(
intrasite_link_regex
)
regex = rf"""
(?P<markup>)(?P<quote>)(?P<path>(\:?){intrasite_link_regex}(?P<value>.*?)(?=[>\n]))
"""
return re.compile(regex, re.X)

def _set_file_utime(self, path, datetime):
Expand All @@ -128,7 +121,7 @@ def generate_output(self, writer=None):
try:
os.mkdir(pdf_path)
except OSError:
logger.error("Couldn't create the pdf output folder in " + pdf_path)
logger.exception("Couldn't create the pdf output folder in " + pdf_path)

for obj in chain(self.context["articles"], self.context["pages"]):
self._create_pdf(obj, pdf_path)
Expand Down
5 changes: 3 additions & 2 deletions pelican/plugins/pdf/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
from tempfile import mkdtemp
import unittest

import pdf
from pelican import Pelican
from pelican.readers import MarkdownReader
from pelican.settings import read_settings

import pdf

CUR_DIR = os.path.dirname(__file__)


class TestPdfGeneration(unittest.TestCase):
"""Test class for PDF generation."""

def setUp(self, override=None):
self.temp_path = mkdtemp(prefix="pelicantests.")
settings = {
Expand Down

0 comments on commit a9df30c

Please sign in to comment.