From 41c214f24fdcf8491705bdc61e5cb2df46cf3a59 Mon Sep 17 00:00:00 2001 From: Karthik Kumar Viswanathan Date: Tue, 10 Dec 2024 14:49:20 -0800 Subject: [PATCH] Update Makefile. Address remaining comments from @3coins. Co-authored-by: Piyush Jain --- .gitignore | 2 + libs/aws/Makefile | 76 +++++++++++++------ libs/aws/README.md | 2 +- libs/aws/pyproject.toml | 4 +- libs/aws/scripts/check_imports.py | 3 +- libs/aws/tests/callbacks.py | 2 +- .../unit_tests/retrievers/test_bedrock.py | 2 +- 7 files changed, 64 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index aed12c91..aa848098 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vs/ .vscode/ .idea/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -59,6 +60,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +.mypy_cache_test/ # Translations *.mo diff --git a/libs/aws/Makefile b/libs/aws/Makefile index d461eebd..aef41994 100644 --- a/libs/aws/Makefile +++ b/libs/aws/Makefile @@ -1,16 +1,38 @@ +###################### +# NON FILE TARGETS +###################### .PHONY: all format lint test tests integration_tests docker_tests help extended_tests -# Default target executed when no arguments are given to make. -all: help +###################### +# ALL TARGETS +###################### + +all: help ## Default target = help + +###################### +# TEST CASES +###################### # Define a variable for the test file path. -TEST_FILE ?= tests/unit_tests/ +test test_watch tests: TEST_FILE ?= tests/unit_tests/ integration_test integration_tests: TEST_FILE = tests/integration_tests/ -test tests integration_test integration_tests: +# Define a variable for Python and notebook files. +PYTHON_FILES=. + +tests: ## Run all unit tests + poetry run pytest $(TEST_FILE) + +test: ## Run individual unit test: make test TEST_FILE=tests/unit_test/test.py poetry run pytest $(TEST_FILE) -test_watch: +integration_tests: ## Run all integration tests + poetry run pytest $(TEST_FILE) + +integration_test: ## Run individual integration test: make integration_test TEST_FILE=tests/integration_tests/integ_test.py + poetry run pytest $(TEST_FILE) + +test_watch: ## Run and interactively watch unit tests poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE) ###################### @@ -26,34 +48,44 @@ lint_package: PYTHON_FILES=langchain_aws lint_tests: PYTHON_FILES=tests lint_tests: MYPY_CACHE=.mypy_cache_test -lint lint_diff lint_package lint_tests: - poetry run ruff . +lint: ## Run linter + poetry run ruff check + +lint_diff: ## Run linter poetry run ruff format $(PYTHON_FILES) --diff - poetry run ruff --select I $(PYTHON_FILES) + +lint_package: ## Run linter on package + poetry run ruff check --select I $(PYTHON_FILES) + +lint_tests: ## Run linter tests mkdir -p $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE) -format format_diff: +format: ## Run code formatter poetry run ruff format $(PYTHON_FILES) - poetry run ruff --select I --fix $(PYTHON_FILES) -spell_check: +format_diff: ## Run code formatter and show differences + poetry run ruff check --select I --fix $(PYTHON_FILES) + +spell_check: ## Run code spell check poetry run codespell --toml pyproject.toml -spell_fix: +spell_fix: ## Run code spell fix poetry run codespell --toml pyproject.toml -w -check_imports: $(shell find langchain_aws -name '*.py') - poetry run python ./scripts/check_imports.py $^ +###################### +# DEPENDENCIES +###################### + +install_dev: ## Install development environment + @pip install --no-cache -U poetry + @poetry install --with dev,test,codespell,lint,typing + +check_imports: $(shell find langchain_aws -name '*.py') ## Check missing imports + @poetry run python ./scripts/check_imports.py $^ ###################### # HELP ###################### -help: - @echo '----' - @echo 'check_imports - check imports' - @echo 'format - run code formatters' - @echo 'lint - run linters' - @echo 'test - run unit tests' - @echo 'tests - run unit tests' - @echo 'test TEST_FILE= - run all tests in file' +help: ## Print this help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/libs/aws/README.md b/libs/aws/README.md index 7f4f9080..8da53c4b 100644 --- a/libs/aws/README.md +++ b/libs/aws/README.md @@ -89,4 +89,4 @@ There are three different search methods we can use to do retrieval. By default, ```python retriever=vds.as_retriever() -``` \ No newline at end of file +``` diff --git a/libs/aws/pyproject.toml b/libs/aws/pyproject.toml index a7b30938..9c7d35db 100644 --- a/libs/aws/pyproject.toml +++ b/libs/aws/pyproject.toml @@ -32,10 +32,12 @@ pytest-watcher = "^0.3.4" langchain-tests = "0.3.1" langchain = "^0.3.7" - [tool.poetry.group.codespell] optional = true +[tool.codespell] +ignore-words-list = "HSA, notIn" + [tool.poetry.group.codespell.dependencies] codespell = "^2.2.6" diff --git a/libs/aws/scripts/check_imports.py b/libs/aws/scripts/check_imports.py index 365f5fa1..f6014201 100644 --- a/libs/aws/scripts/check_imports.py +++ b/libs/aws/scripts/check_imports.py @@ -5,11 +5,12 @@ 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 + has_failure = True print(file) # noqa: T201 traceback.print_exc() print() # noqa: T201 diff --git a/libs/aws/tests/callbacks.py b/libs/aws/tests/callbacks.py index 821d066a..ba9dfef3 100644 --- a/libs/aws/tests/callbacks.py +++ b/libs/aws/tests/callbacks.py @@ -23,7 +23,7 @@ class BaseFakeCallbackHandler(BaseModel): ignore_retriever_: bool = False ignore_chat_model_: bool = False - # to allow for similar callback handlers that are not technicall equal + # to allow for similar callback handlers that are not technically equal fake_id: Union[str, None] = None # add finer-grained counters for easier debugging of failing tests diff --git a/libs/aws/tests/unit_tests/retrievers/test_bedrock.py b/libs/aws/tests/unit_tests/retrievers/test_bedrock.py index 6d5a84de..98357428 100644 --- a/libs/aws/tests/unit_tests/retrievers/test_bedrock.py +++ b/libs/aws/tests/unit_tests/retrievers/test_bedrock.py @@ -59,7 +59,7 @@ def test_retriever_invoke(amazon_retriever, mock_client): retrievalConfiguration={ "vectorSearchConfiguration": { "numberOfResults": 5, - # Expecting to be called with correct "in" operatior instead of "in_" + # Expecting to be called with correct "in" operator instead of "in_" "filter": {"in": {"key": "key", "value": ["value1", "value2"]}}, } },