Compare commits

...

9 Commits

Author SHA1 Message Date
Mason Daugherty
8d3da6e38a Merge branch 'master' into mdrxy/make-targets 2025-08-11 18:20:32 -04:00
Mason Daugherty
d187be9203 Merge branch 'master' into mdrxy/make-targets 2025-07-28 16:27:36 -04:00
Mason Daugherty
881a2e8cc0 standard-tests 2025-07-28 16:25:35 -04:00
Mason Daugherty
6d2fc87584 feat: update all check_imports docstrings 2025-07-28 10:32:02 -04:00
Mason Daugherty
c95a1e26de . 2025-07-28 10:23:49 -04:00
Mason Daugherty
0bbfdaf3d5 make test -> make unit_test 2025-07-28 10:23:42 -04:00
Mason Daugherty
083a99b102 fix: remove unused PHONY target 2025-07-28 10:23:14 -04:00
Mason Daugherty
80a0d494a1 update help 2025-07-28 10:00:20 -04:00
Mason Daugherty
77ec77edcd correct PHONY 2025-07-28 10:00:13 -04:00
26 changed files with 252 additions and 33 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 }}

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

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

@@ -57,7 +57,7 @@ Then verify dependency installation:
```bash
# If you have `make` installed:
make test
make unit_test
# If you don't have `make` (Windows alternative):
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests
@@ -74,7 +74,7 @@ To run unit tests:
```bash
# If you have `make` installed:
make test
make unit_test
# If you don't have make (Windows alternative):
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests
@@ -90,7 +90,7 @@ If you are only developing `langchain_core`, you can simply install the dependen
cd libs/core
# If you have `make` installed:
make test
make unit_test
# If you don't have `make` (Windows alternative):
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests

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 secrets
import string
import sys