MCPcopy Create free account
hub / github.com/vercel/vercel / has_main_guard

Function has_main_guard

python/vercel-runtime/src/vercel_runtime/utils.py:42–60  ·  view source on GitHub ↗
(entrypoint_abs: str | None)

Source from the content-addressed store, hash-verified

40
41
42def has_main_guard(entrypoint_abs: str | None) -> bool:
43 if not entrypoint_abs:
44 return False
45
46 try:
47 with open(entrypoint_abs, encoding="utf-8") as file:
48 source = file.read()
49 except Exception:
50 return False
51
52 try:
53 tree = ast.parse(source, filename=entrypoint_abs)
54 except Exception:
55 return False
56
57 for node in ast.walk(tree):
58 if isinstance(node, ast.If) and _is_main_guard_test(node.test):
59 return True
60 return False
61
62
63def run_entrypoint_as_main(entrypoint_abs: str) -> None:

Callers

nothing calls this directly

Calls 3

_is_main_guard_testFunction · 0.85
readMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected