feat: support syntax error messages
henryiii opened this issue · 1 comments
henryiii commented
We currently only check on test runs, but if you have a syntax error (in my case, usually a bit of Python 3-only valid syntax that then gets caught in CI on Python 2), it would be nice to have the annotations there as well.
utgwkk commented
It is difficult as a functionality of this plugin, but writing a syntax-check test may be suitable. The below test will fail when source code contains a syntax error.
# For Python 2 compatibility, we use [glob2](https://pypi.org/project/glob2/) library
# instead of built-in glob module.
from glob2 import iglob
import py_compile
import pytest
python_files = iglob('src/**/*.py', recursive=True)
@pytest.mark.parametrize("path", python_files)
def test_syntax(path):
try:
py_compile.compile(path, doraise=True)
except py_compile.PyCompileError as ex:
pytest.fail(ex.msg)example result: https://github.com/utgwkk/20210731-sketch-python-problem-matcher/actions/runs/1084361862