This commit is contained in:
Mason Daugherty 2025-07-28 17:40:39 -07:00 committed by GitHub
commit 4bb1a6d4ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 254 additions and 35 deletions

View File

@ -22,7 +22,7 @@ Thank you for contributing to LangChain! Follow these steps to mark your pull re
1. A test for the integration, preferably unit tests that do not rely on network access,
2. An example notebook showing its use. It lives in `docs/docs/integrations` directory.
- [ ] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. **We will not consider a PR unless these three are passing in CI.** See [contribution guidelines](https://python.langchain.com/docs/contributing/) for more.
- [ ] **Lint and test**: Run `make format`, `make lint` and `make unit_test` from the root of the package(s) you've modified. **We will not consider a PR unless these three are passing in CI.** See [contribution guidelines](https://python.langchain.com/docs/contributing/) for more.
Additional guidelines:

View File

@ -239,7 +239,7 @@ uv lock
```bash
# Run unit tests (no network)
make test
make unit_test
# Don't run integration tests, as API keys must be set

View File

@ -46,7 +46,7 @@ jobs:
- name: '🧪 Run Core Unit Tests'
shell: bash
run: |
make test
make unit_test
- name: '🔍 Calculate Minimum Dependency Versions'
working-directory: ${{ inputs.working-directory }}
@ -79,4 +79,4 @@ jobs:
# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'

View File

@ -52,7 +52,7 @@ jobs:
- name: '🧪 Run Core Tests'
shell: bash
run: |
make test
make unit_test
- name: '🧹 Verify Clean Working Directory'
shell: bash
@ -64,4 +64,4 @@ jobs:
# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
echo "$STATUS" | grep 'nothing to commit, working tree clean'

View File

@ -1,4 +1,4 @@
.PHONY: all clean help docs_build docs_clean docs_linkcheck api_docs_build api_docs_clean api_docs_linkcheck spell_check spell_fix lint lint_package lint_tests format format_diff
.PHONY: help clean docs_build docs_clean docs_linkcheck api_docs_build api_docs_quick_preview api_docs_clean api_docs_linkcheck spell_check spell_fix lint lint_package lint_tests format format_diff update-package-downloads
.EXPORT_ALL_VARIABLES:
UV_FROZEN = true
@ -100,7 +100,7 @@ lint lint_package lint_tests:
uv run --group lint ruff check docs cookbook
uv run --group lint ruff format docs cookbook cookbook --diff
git --no-pager grep 'from langchain import' docs cookbook | grep -vE 'from langchain import (hub)' && echo "Error: no importing langchain from root in docs, except for hub" && exit 1 || exit 0
git --no-pager grep 'api.python.langchain.com' -- docs/docs ':!docs/docs/additional_resources/arxiv_references.mdx' ':!docs/docs/integrations/document_loaders/sitemap.ipynb' || exit 0 && \
echo "Error: you should link python.langchain.com/api_reference, not api.python.langchain.com in the docs" && \
exit 1

View File

@ -48,7 +48,7 @@ uv sync
Then verify dependency installation:
```bash
make test
make unit_test
```
## Testing
@ -61,7 +61,7 @@ If you add new logic, please add a unit test.
To run unit tests:
```bash
make test
make unit_test
```
There are also [integration tests and code-coverage](../testing.mdx) available.
@ -72,7 +72,7 @@ If you are only developing `langchain_core`, you can simply install the dependen
```bash
cd libs/core
make test
make unit_test
```
## Formatting and linting

View File

@ -24,13 +24,13 @@ poetry install --with test
To run unit tests:
```bash
make test
make unit_test
```
To run a specific test:
```bash
TEST_FILE=tests/unit_tests/test_imports.py make test
TEST_FILE=tests/unit_tests/test_imports.py make unit_test
```
## Integration tests

View File

@ -89,7 +89,6 @@ help:
@echo '-- TESTS --'
@echo 'coverage - run unit tests and generate coverage report'
@echo 'test - run unit tests'
@echo 'tests - run unit tests (alias for "make test")'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
@echo 'extended_tests - run only extended unit tests'
@echo 'test_watch - run unit tests in watch mode'

View File

@ -88,7 +88,6 @@ help:
@echo '-- TESTS --'
@echo 'coverage - run unit tests and generate coverage report'
@echo 'test - run unit tests'
@echo 'tests - run unit tests (alias for "make test")'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
@echo 'extended_tests - run only extended unit tests'
@echo 'test_watch - run unit tests in watch mode'

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,4 +1,16 @@
"""This module checks if the given python files can be imported without error."""
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,4 +1,16 @@
"""load multiple Python files specified as command line arguments."""
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback
from importlib.machinery import SourceFileLoader

View File

@ -1,4 +1,16 @@
"""This module checks if the given python files can be imported without error."""
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import sys
import traceback

View File

@ -1,7 +1,9 @@
.PHONY: all format lint test tests integration_tests help extended_tests
.PHONY: format lint test tests unit_test unit_tests integration_tests help extended_tests format_diff lint_diff lint_package lint_tests spell_check spell_fix check_imports
# Default target executed when no arguments are given to make.
all: help
## help: Show this help info.
help: Makefile
@printf "\n\033[1mUsage: make <TARGETS> ...\033[0m\n\n\033[1mTargets:\033[0m\n\n"
@sed -n 's/^## //p' $< | awk -F':' '{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort | sed -e 's/^/ /'
.EXPORT_ALL_VARIABLES:
UV_FROZEN = true
@ -12,9 +14,14 @@ INTEGRATION_TEST_FILE ?= tests/integration_tests/
integration_test integration_tests: TEST_FILE=$(INTEGRATION_TEST_FILE)
test tests:
## test: Run both unit and integration tests
test tests: unit_test integration_tests
## unit_test: Run only unit tests
unit_test unit_tests:
uv run --group test pytest $(TEST_FILE)
## integration_test: Run only integration tests
integration_test integration_tests:
uv run --group test --group test_integration pytest $(TEST_FILE)
@ -23,7 +30,6 @@ integration_test integration_tests:
# LINTING AND FORMATTING
######################
# Define a variable for Python and notebook files.
PYTHON_FILES=.
MYPY_CACHE=.mypy_cache
lint format: PYTHON_FILES=.
@ -32,33 +38,30 @@ lint_package: PYTHON_FILES=langchain_tests
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test
## lint: Run linters on all files
## lint_diff: Run linters on changed files only
## lint_package: Run linters on package files only
## lint_tests: Run linters on test files only
lint lint_diff lint_package lint_tests:
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && uv run --all-groups mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
## format: Format all code
## format_diff: Format changed files only
format format_diff:
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check --fix $(PYTHON_FILES)
## spell_check: Check spelling in code
spell_check:
uv run --all-groups codespell --toml pyproject.toml
## spell_fix: Apply spelling fixes in code
spell_fix:
uv run --all-groups codespell --toml pyproject.toml -w
## check_imports: Check import statements
check_imports: $(shell find langchain_tests -name '*.py')
uv run --all-groups 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=<test_file> - run all tests in file'

View File

@ -1,3 +1,17 @@
"""Import validation script.
Validates that Python files can be imported without errors by dynamically
loading each file as a module. This is crucial for ensuring:
1. All dependencies are properly installed and available
2. Module-level code executes without syntax or runtime errors
3. Import statements are valid and don't create circular dependencies
4. The code structure follows Python import conventions
Typically run in CI/CD to catch import problems before deployment, ensuring that
all modules can be successfully imported in production environments.
"""
import random
import string
import sys