getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.62k stars 451 forks source link

Incompatibility with newer pygments version or similar(?) #3618

Closed sfan5 closed 2 years ago

sfan5 commented 2 years ago

Environment

Python Version: 3.10

Nikola Version: Nikola v8.2.1

Operating System: Linux

Description:

I'm not totally sure what caused this, except I upgraded everything in my virtualenv and it started happening.

Using a code block in a post (presumably) causes this exception to happen:

TaskError - taskid:render_posts:cache/posts/post-name-here.html
PythonAction Error
Traceback (most recent call last):
  File ".../venv/lib/python3.10/site-packages/pygments/__init__.py", line 61, in format
    formatter.format(tokens, realoutfile)
  File ".../venv/lib/python3.10/site-packages/pygments/formatter.py", line 94, in format
    return self.format_unencoded(tokensource, outfile)
  File ".../venv/lib/python3.10/site-packages/nikola/packages/pygments_better_html/__init__.py", line 222, in format_unencoded
    return super().format_unencoded(tokensource, outfile)
  File ".../venv/lib/python3.10/site-packages/pygments/formatters/html.py", line 981, in format_unencoded
    source = self.wrap(source)
TypeError: NikolaPygmentsHTML.wrap() missing 1 required positional argument: 'outfile'

During handling of the above exception, another exception occurred:

[...]

The following change gets rid of the exception and output looks fine:

diff --git a/nikola/utils.py b/nikola/utils.py
index e2a64a3cc..4323aa908 100644
--- a/nikola/utils.py
+++ b/nikola/utils.py
@@ -1690,7 +1690,7 @@ class NikolaPygmentsHTML(BetterHtmlFormatter):
         kwargs['nowrap'] = False
         super().__init__(**kwargs)

-    def wrap(self, source, outfile):
+    def wrap(self, source, *_):
         """Wrap the ``source``, which is a generator yielding individual lines, in custom generators."""
         style = []
         if self.prestyles:
Kwpolska commented 2 years ago

Duplicate of #3617 (with a time difference of two minutes, so it’s not your fault or anything :))

sfan5 commented 2 years ago

Ahhh what a coincidence :smile: