Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traceback parsing changes in 2.15.0 error on valid pycon code blocks #2407

Closed
CAM-Gerlach opened this issue Apr 10, 2023 · 8 comments · Fixed by #2410
Closed

Traceback parsing changes in 2.15.0 error on valid pycon code blocks #2407

CAM-Gerlach opened this issue Apr 10, 2023 · 8 comments · Fixed by #2410
Assignees
Labels
A-lexing area: changes to individual lexers S-major severity: major

Comments

@CAM-Gerlach
Copy link

CAM-Gerlach commented Apr 10, 2023

(Sorry, accidentally hit the submit shortcut before I was done writing it)

Unfortunately, the traceback parsing changes to fix #2226 and #2329 implemented in fe42aac (I can't seem to find the associated pull request) appears to result in Pygments treating certain valid code blocks as invalid, issuing a warning and failing Sphinx builds (with -W). In particular, this occurred on the following code block in the CPython's multiprocessing module docs:

.. note::

   Functionality within this package requires that the ``__main__`` module be
   importable by the children. This is covered in :ref:`multiprocessing-programming`
   however it is worth pointing out here. This means that some examples, such
   as the :class:`multiprocessing.pool.Pool` examples will not work in the
   interactive interpreter. For example::

      >>> from multiprocessing import Pool
      >>> p = Pool(5)
      >>> def f(x):
      ...     return x*x
      ...
      >>> with p:
      ...     p.map(f, [1,2,3])
      Process PoolWorker-1:
      Process PoolWorker-2:
      Process PoolWorker-3:
      Traceback (most recent call last):
      Traceback (most recent call last):
      Traceback (most recent call last):
      AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
      AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
      AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>

that worked in 2.14.9, which when 2.15.0 was released suddenly broke the CPython Docs CI job with the error:

WARNING: Could not lex literal_block as "pycon". Highlighting skipped.

Here's a more minimal example that also doesn't parse:

Here's a code block::

   >>> print("\n".join(["Traceback (most recent call last):"] * 2))
   Traceback (most recent call last):
   Traceback (most recent call last):

This also occurs with an explicit pycon lexer specified:

Here's another code block:

.. code-block:: pycon

   >>> print("\n".join(["Traceback (most recent call last):"] * 2))
   Traceback (most recent call last):
   Traceback (most recent call last):

and also with arbitrary text after the traceback line:

Here's a code block::

   >>> print("\n".join(["Traceback (most recent call last):", "blah blah"])
   Traceback (most recent call last):
   blah blah

While this example parses:

Here's a code block::

   >>> print("\n".join(["Traceback (most recent call last):"] * 1))
   Traceback (most recent call last):

Here's an example of a failing run.

@CAM-Gerlach CAM-Gerlach changed the title raceback parsing changes in 2.15.0 rejects valid pycon code blocks Traceback parsing changes in 2.15.0 rejects valid pycon code blocks Apr 10, 2023
@CAM-Gerlach CAM-Gerlach changed the title Traceback parsing changes in 2.15.0 rejects valid pycon code blocks Traceback parsing changes in 2.15.0 error on valid pycon code blocks Apr 10, 2023
@Anteru Anteru added the A-lexing area: changes to individual lexers label Apr 10, 2023
@Anteru Anteru added the S-major severity: major label Apr 10, 2023
@jeanas
Copy link
Contributor

jeanas commented Apr 10, 2023

Thanks for reporting! On a note, though, does CPython not pin Pygments and other dependencies in its CI? I would have expected it, for such a large project where keeping a working CI is critical...

@hugovk
Copy link
Contributor

hugovk commented Apr 10, 2023

@jeanas
Copy link
Contributor

jeanas commented Apr 10, 2023

OK, although it could use a lock file, or the sort-of-lockfile substitute given by pip freeze.

@CAM-Gerlach
Copy link
Author

Yeah, we definitely keep the direct deps pinned; this is just the first time we've seen this issue with the transitive deps and it wouldn't necessarily work cross platform if any of the transitive deps are conditional, and it also work would with other package managers like Conda. AFAIK this is the first time I can recall that we've seen this sort of breakage before from a non-direct dep. Also, the docs build server runs on a whole separate system (AFAIK) that I think is all pinned down, so not sure it would help the actual production builds right now anyway.

rtobar added a commit to rtobar/python-docs-es that referenced this issue Apr 11, 2023
La última versión de Pygments está provocando errores al parsear código
de python que es válido. Esto ya ha sido reportado en
pygments/pygments#2407, sólo hace falta
esperar por el fix, y mientras tanto evitar usar esta nueva versión.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
cmaureir pushed a commit to python/python-docs-es that referenced this issue Apr 12, 2023
La última versión de Pygments está provocando errores al parsear código
de python que es válido. Esto ya ha sido reportado en
pygments/pygments#2407, sólo hace falta
esperar por el fix, y mientras tanto evitar usar esta nueva versión.

Este problema fue visto en #2372 por primera vez, pero de hecho ya nos
está afectando: el último build en CI de `3.11` ya falló por la misma
razón.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
birkenfeld added a commit that referenced this issue Apr 12, 2023
…be valid

which causes Error to be flagged with output that just happens
to look like a traceback

Fixes #2407
@birkenfeld
Copy link
Member

birkenfeld commented Apr 12, 2023

Fix in #2410 - please try.

In general, 2.15 is still better behaved than older versions, which silently swallowed part of the output, as you can see e.g. here:
https://docs.python.org/3.10/library/multiprocessing.html

Process PoolWorker-1:
Process PoolWorker-2:
Process PoolWorker-3:
Traceback (most recent call last):
AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'

Note the single "Traceback" line.

birkenfeld added a commit that referenced this issue Apr 12, 2023
which causes Error to be flagged with console outputs that just happen
to look like a traceback

Fixes #2407
@jeanas
Copy link
Contributor

jeanas commented Apr 12, 2023

See also #2411

@CAM-Gerlach
Copy link
Author

Thanks @birkenfeld & @jeanas for the quick fix! Looks like that at least fixes the error and restores syntax highlighting on the block. It does look a bit odd that all three Traceback lines are highlighted, but only the first AttributeError line is, but this is a pretty esoteric case....

image

Any idea when the next release containing this fix will be released? If its soon, we can skip backporting the change to the older security-only CPython branches and just wait for the new version to be released. A lockfile would be nice longer term, but unfortunately, its not quite as simple as just having our GH Actions jobs use it, as the actual production docs site and other docs formats are currently produced by a separately managed build server with its own maintainers, scripts and configuration that would need to be investigated, modified, tested and deployed.

@jeanas
Copy link
Contributor

jeanas commented Apr 18, 2023

Pygments 2.15.1 has been released with #2410 and #2412 (thanks @Anteru for the release work!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lexing area: changes to individual lexers S-major severity: major
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants