frequenz-floss / frequenz-repo-config-python

Frequenz repository setup tools and common configuration for Python
https://frequenz-floss.github.io/frequenz-repo-config-python/
MIT License
3 stars 7 forks source link

Examples testing doesn't work with Sybil 6.1.0 #249

Closed llucax closed 1 month ago

llucax commented 2 months ago

What happened?

When upgrading from Sybil 6.0.3 to 6.1.0 we get the following error:

Example at /home/luca/devel/repo-config/src/frequenz/repo/config/pytest/examples.py, line 17, column 1 did not evaluate as expected:
Pylint validation failed for code example:

# Generated auto-imports for code example
# pylint: disable=unused-import,wildcard-import,unused-wildcard-import
import ast
import os
import subprocess
import textwrap
from pathlib import Path
from typing import Any
from sybil import Example
from sybil.evaluators.python import pad
from sybil.parsers.myst import CodeBlockParser
from frequenz.repo.config.pytest.examples import *
# pylint: enable=unused-import,wildcard-import,unused-wildcard-import

from frequenz.repo.config.pytest import examples
from sybil import Sybil

pytest_collect_file = Sybil(**examples.get_sybil_arguments()).pytest()
```
Output: ************* Module config.pytest.examples
src/frequenz/repo/config/pytest/examples.py:22:1: E0001: Parsing failed: 'invalid syntax (config.pytest.examples, line 22)' (syntax-error)

examples.py:17: SybilFailure

What did you expect instead?

It works.

Affected version(s)

v0.9.x

Affected part(s)

Build script, CI, dependencies, etc. (part:tooling), Tools to configure pytest (part:pytest)

Extra information

When printing the generated source, this is what's being passed to pylint:

# Generated auto-imports for code example
# pylint: disable=unused-import,wildcard-import,unused-wildcard-import
import ast
import os
import subprocess
import textwrap
from pathlib import Path
from typing import Any
from sybil import Example
from sybil.evaluators.python import pad
from sybil.parsers.myst import CodeBlockParser
from frequenz.repo.config.pytest.examples import *
# pylint: enable=unused-import,wildcard-import,unused-wildcard-import

from frequenz.repo.config.pytest import examples
from sybil import Sybil

pytest_collect_file = Sybil(**examples.get_sybil_arguments()).pytest()
```

The trailing ``` is clearly causing the issue (it is line 22).

I'm not sure if we were misusing Sybil or if there is a regression in Sybil, it probably needs to be investigated.

If it is an issue in Sybil, we might want to deal with it ourselves for now, otherwise we'll need to pin sybil in all downstream projects too.

From Sybil 6.1.0 changelog:

  • Add support for lexing nested fenced codeblocks in markdown.
  • Add support for tilde-delimited codeblocks in markdown.

Probably related to this issue.

Marenz commented 2 months ago

related https://github.com/simplistix/sybil/issues/115

llucax commented 2 months ago

So that issue confirms is a problem in how we use sybil, right? So we should fix our code?

The famous:

image

Marenz commented 2 months ago

Yeah, if you look at the issue, I asked a bit and he gave us a few pointers, so I am gonna look into that

llucax commented 2 months ago

I'm pinning sybil to < 6.1 for v0.9.x to fix this quickly for the current projects experiencing the issue. We can delay the proper fix to v0.10.0.