Codebase list python-procrunner / fb086983-6445-4395-b47d-97f9e23f48c5/main .azure-pipelines / syntax-validation.py
fb086983-6445-4395-b47d-97f9e23f48c5/main

Tree @fb086983-6445-4395-b47d-97f9e23f48c5/main (Download .tar.gz)

syntax-validation.py @fb086983-6445-4395-b47d-97f9e23f48c5/main

6695ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
48ca117
6695ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)")