Skip to content

Commit 482e2b9

Browse files
author
Erick Friis
authored
infra: import CI speed (#14566)
Was taking 10 mins. Now a few seconds.
1 parent 6a828e6 commit 482e2b9

9 files changed

Lines changed: 73 additions & 30 deletions

File tree

libs/community/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ test_watch:
1616
poetry run ptw --snapshot-update --now . -- -vv -x tests/unit_tests
1717

1818
check_imports: $(shell find langchain_community -name '*.py')
19-
for f in $^ ; do \
20-
python -c "from importlib.machinery import SourceFileLoader; SourceFileLoader('x', '$$f').load_module()" || exit 1; \
21-
done
19+
poetry run python ./scripts/check_imports.py $^
2220

2321
extended_tests:
2422
poetry run pytest --only-extended tests/unit_tests
@@ -39,7 +37,7 @@ lint_tests: MYPY_CACHE=.mypy_cache_test
3937

4038
lint lint_diff lint_package lint_tests:
4139
./scripts/check_pydantic.sh .
42-
./scripts/check_imports.sh
40+
./scripts/lint_imports.sh
4341
poetry run ruff .
4442
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
4543
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I $(PYTHON_FILES)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import traceback
3+
from importlib.machinery import SourceFileLoader
4+
5+
if __name__ == "__main__":
6+
files = sys.argv[1:]
7+
has_failure = False
8+
for file in files:
9+
try:
10+
SourceFileLoader("x", file).load_module()
11+
except Exception:
12+
has_faillure = True
13+
print(file)
14+
traceback.print_exc()
15+
print()
16+
17+
sys.exit(1 if has_failure else 0)

libs/community/scripts/check_imports.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

libs/core/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ test_watch:
1616
poetry run ptw --snapshot-update --now . -- -vv -x tests/unit_tests
1717

1818
check_imports: $(shell find langchain_core -name '*.py')
19-
for f in $^ ; do \
20-
python -c "from importlib.machinery import SourceFileLoader; SourceFileLoader('x', '$$f').load_module()" || exit 1; \
21-
done
19+
poetry run python ./scripts/check_imports.py $^
2220

2321
extended_tests:
2422
poetry run pytest --only-extended $(TEST_FILE)

libs/core/scripts/check_imports.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import traceback
3+
from importlib.machinery import SourceFileLoader
4+
5+
if __name__ == "__main__":
6+
files = sys.argv[1:]
7+
has_failure = False
8+
for file in files:
9+
try:
10+
SourceFileLoader("x", file).load_module()
11+
except Exception:
12+
has_faillure = True
13+
print(file)
14+
traceback.print_exc()
15+
print()
16+
17+
sys.exit(1 if has_failure else 0)

libs/experimental/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ integration_tests:
2222
poetry run pytest tests/integration_tests
2323

2424
check_imports: $(shell find langchain_experimental -name '*.py')
25-
for f in $^ ; do \
26-
python -c "from importlib.machinery import SourceFileLoader; SourceFileLoader('x', '$$f').load_module()" || exit 1; \
27-
done
25+
poetry run python ./scripts/check_imports.py $^
2826

2927

3028
######################
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import traceback
3+
from importlib.machinery import SourceFileLoader
4+
5+
if __name__ == "__main__":
6+
files = sys.argv[1:]
7+
has_failure = False
8+
for file in files:
9+
try:
10+
SourceFileLoader("x", file).load_module()
11+
except Exception:
12+
has_faillure = True
13+
print(file)
14+
traceback.print_exc()
15+
print()
16+
17+
sys.exit(1 if has_failure else 0)

libs/langchain/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ docker_tests:
4141
docker run --rm my-langchain-image:test
4242

4343
check_imports: $(shell find langchain -name '*.py')
44-
for f in $^ ; do \
45-
python -c "from importlib.machinery import SourceFileLoader; SourceFileLoader('x', '$$f').load_module()" || exit 1; \
46-
done
44+
poetry run python ./scripts/check_imports.py $^
4745

4846
######################
4947
# LINTING AND FORMATTING
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import traceback
3+
from importlib.machinery import SourceFileLoader
4+
5+
if __name__ == "__main__":
6+
files = sys.argv[1:]
7+
has_failure = False
8+
for file in files:
9+
try:
10+
SourceFileLoader("x", file).load_module()
11+
except Exception:
12+
has_faillure = True
13+
print(file)
14+
traceback.print_exc()
15+
print()
16+
17+
sys.exit(1 if has_failure else 0)

0 commit comments

Comments
 (0)