langchain[patch]: CI add lint rule for community imports (#21618)

Add a rule to check for imports from community in global scope
This commit is contained in:
Eugene Yurtsev 2024-05-13 14:51:25 -04:00 committed by GitHub
parent 4378fbbef0
commit b923951062
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -27,6 +27,12 @@ langchain.(pydantic_v1|utils|schema|load|callbacks|env|_api|storage|llms|docstor
# make sure not importing from langchain_experimental # make sure not importing from langchain_experimental
git --no-pager grep '^from langchain_experimental\.' . && errors=$((errors+1)) git --no-pager grep '^from langchain_experimental\.' . && errors=$((errors+1))
# Add a basic lint rule to prevent imports from the global namespaces of langchain_community
# This lint rule won't catch imports from local scope.
# We can't add that rule without a more complex script to ignore imports from inside
# a if TYPE_CHECKING block.
git grep '^from langchain_community' | grep -vE '# ignore: community-import' && errors=$((errors+1))
# Decide on an exit status based on the errors # Decide on an exit status based on the errors
if [ "$errors" -gt 0 ]; then if [ "$errors" -gt 0 ]; then
exit 1 exit 1

View File

@ -12,7 +12,9 @@ pytest.importorskip(
) )
from langchain_community.llms.openai import OpenAI as CommunityOpenAI # noqa: E402 from langchain_community.llms.openai import ( # noqa: E402, # ignore: community-import
OpenAI as CommunityOpenAI,
)
class NotSerializable: class NotSerializable: