from pathlib import Path
from typing import Tuple
import ast
import traceback


def check_python_syntax(source_file: Path) -> Tuple[bool, str]:
    """
    Check whether the given python file contains valid syntax

    Args:
        source_file: The path to the python file whose syntax is to be checked

    Returns:
        A tuple containing False & error message in case source_file does not have valid syntax,
        (True, ok) otherwise
    """
    valid, message = True, "ok"
    with open(source_file, encoding='utf-8') as f:
        source = f.read()

    try:
        ast.parse(source)
    except SyntaxError:
        valid, message = False, traceback.format_exc()

    return valid, message