mirror of
https://github.com/hwchase17/langchain.git
synced 2026-05-15 03:25:21 +00:00
Co-authored-by: Mason Daugherty <mason@langchain.dev> Co-authored-by: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Co-authored-by: Sydney Runkle <sydneymarierunkle@gmail.com>
34 lines
939 B
Python
34 lines
939 B
Python
"""Check imports script.
|
|
|
|
Quickly verify that a list of Python files can be loaded by the Python interpreter
|
|
without raising any errors. Ran before running more expensive tests. Useful in
|
|
Makefiles.
|
|
|
|
If loading a file fails, the script prints the problematic filename and the detailed
|
|
error traceback.
|
|
"""
|
|
|
|
import random
|
|
import string
|
|
import sys
|
|
import traceback
|
|
from importlib.machinery import SourceFileLoader
|
|
|
|
if __name__ == "__main__":
|
|
files = sys.argv[1:]
|
|
has_failure = False
|
|
for file in files:
|
|
try:
|
|
module_name = "".join(
|
|
random.choice(string.ascii_letters) # noqa: S311
|
|
for _ in range(20)
|
|
)
|
|
SourceFileLoader(module_name, file).load_module()
|
|
except Exception:
|
|
has_failure = True
|
|
print(file) # noqa: T201
|
|
traceback.print_exc()
|
|
print() # noqa: T201
|
|
|
|
sys.exit(1 if has_failure else 0)
|