File: syntax-validation.py

package info (click to toggle)
python-procrunner 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: python: 1,026; makefile: 80
file content (30 lines) | stat: -rw-r--r-- 946 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import ast
import os
import sys

print("Python", sys.version, "\n")

failures = 0

for base, _, files in os.walk("."):
    for f in files:
        if not f.endswith(".py"):
            continue
        filename = os.path.normpath(os.path.join(base, f))
        try:
            with open(filename) as fh:
                ast.parse(fh.read())
        except SyntaxError as se:
            failures += 1
            print(
                f"##vso[task.logissue type=error;sourcepath={filename};"
                f"linenumber={se.lineno};columnnumber={se.offset};]"
                f"SyntaxError: {se.msg}"
            )
            print(" " + se.text + " " * se.offset + "^")
            print(f"SyntaxError: {se.msg} in {filename} line {se.lineno}")
            print()

if failures:
    print(f"##vso[task.logissue type=warning]Found {failures} syntax error(s)")
    print(f"##vso[task.complete result=Failed;]Found {failures} syntax error(s)")