add checks on basic base modules (#10693)

This commit is contained in:
Harrison Chase 2023-09-16 22:08:11 -07:00 committed by GitHub
parent 5442d2b1fa
commit 2c957de2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -1,5 +1,5 @@
---
name: Imports
name: Documentation Lint
on:
push:
@ -18,6 +18,5 @@ jobs:
- name: Run import check
run: |
# We should not encourage imports directly from main init file
# Expect for __version__ and hub
# And of course expect for this file
git grep 'from langchain import' | grep -vE 'from langchain import (__version__|hub)' | grep -v '.github/workflows/check-imports.yml' && exit 1 || exit 0
# Expect for hub
git grep 'from langchain import' docs | grep -vE 'from langchain import (hub)' && exit 1 || exit 0

View File

@ -77,6 +77,7 @@ lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/langchain -
lint lint_diff:
./scripts/check_pydantic.sh .
./scripts/check_imports.sh
poetry run ruff .
poetry run black $(PYTHON_FILES) --check
poetry run mypy $(PYTHON_FILES)

View File

@ -0,0 +1,14 @@
#!/bin/bash
set -eu
git grep 'from langchain import' langchain | grep -vE 'from langchain import (__version__|hub)' && exit 1 || exit 0
# Pydantic bridge should not import from any other module
git grep 'from langchain ' langchain/pydantic_v1 && exit 1 || exit 0
# load should not import from anything except itself and pydantic_v1
git grep 'from langchain' langchain/load | grep -vE 'from langchain.(pydantic_v1)' && exit 1 || exit 0
# utils should not import from anything except itself and pydantic_v1
git grep 'from langchain' langchain/utils | grep -vE 'from langchain.(pydantic_v1|utils)' && exit 1 || exit 0