Skip to content

Commit

Permalink
infra: import CI speed (#14566)
Browse files Browse the repository at this point in the history
Was taking 10 mins. Now a few seconds.
  • Loading branch information
efriis committed Dec 11, 2023
1 parent 6a828e6 commit 482e2b9
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 30 deletions.
6 changes: 2 additions & 4 deletions libs/community/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ test_watch:
poetry run ptw --snapshot-update --now . -- -vv -x tests/unit_tests

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

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

lint lint_diff lint_package lint_tests:
./scripts/check_pydantic.sh .
./scripts/check_imports.sh
./scripts/lint_imports.sh
poetry run ruff .
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I $(PYTHON_FILES)
Expand Down
17 changes: 17 additions & 0 deletions libs/community/scripts/check_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import traceback
from importlib.machinery import SourceFileLoader

if __name__ == "__main__":
files = sys.argv[1:]
has_failure = False
for file in files:
try:
SourceFileLoader("x", file).load_module()
except Exception:
has_faillure = True
print(file)
traceback.print_exc()
print()

sys.exit(1 if has_failure else 0)
17 changes: 0 additions & 17 deletions libs/community/scripts/check_imports.sh

This file was deleted.

4 changes: 1 addition & 3 deletions libs/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ test_watch:
poetry run ptw --snapshot-update --now . -- -vv -x tests/unit_tests

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

extended_tests:
poetry run pytest --only-extended $(TEST_FILE)
Expand Down
17 changes: 17 additions & 0 deletions libs/core/scripts/check_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import traceback
from importlib.machinery import SourceFileLoader

if __name__ == "__main__":
files = sys.argv[1:]
has_failure = False
for file in files:
try:
SourceFileLoader("x", file).load_module()
except Exception:
has_faillure = True
print(file)
traceback.print_exc()
print()

sys.exit(1 if has_failure else 0)
4 changes: 1 addition & 3 deletions libs/experimental/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ integration_tests:
poetry run pytest tests/integration_tests

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


######################
Expand Down
17 changes: 17 additions & 0 deletions libs/experimental/scripts/check_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import traceback
from importlib.machinery import SourceFileLoader

if __name__ == "__main__":
files = sys.argv[1:]
has_failure = False
for file in files:
try:
SourceFileLoader("x", file).load_module()
except Exception:
has_faillure = True
print(file)
traceback.print_exc()
print()

sys.exit(1 if has_failure else 0)
4 changes: 1 addition & 3 deletions libs/langchain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ docker_tests:
docker run --rm my-langchain-image:test

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

######################
# LINTING AND FORMATTING
Expand Down
17 changes: 17 additions & 0 deletions libs/langchain/scripts/check_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import traceback
from importlib.machinery import SourceFileLoader

if __name__ == "__main__":
files = sys.argv[1:]
has_failure = False
for file in files:
try:
SourceFileLoader("x", file).load_module()
except Exception:
has_faillure = True
print(file)
traceback.print_exc()
print()

sys.exit(1 if has_failure else 0)

0 comments on commit 482e2b9

Please sign in to comment.