Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Pydantic imports #546

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: JS Lint
name: Lint
on:
- pull_request

jobs:
js_lint:
name: JS Lint
lint_ts:
name: Lint TypeScript source
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -15,5 +15,39 @@ jobs:
run: pip install jupyterlab~=4.0
- name: Install JS dependencies
run: jlpm
- name: Run JS Lint
- name: Lint TypeScript source
run: jlpm lerna run lint:check

lint_py_imports:
name: Lint Python imports
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Echo environment details
run: |
which python
which pip
python --version
pip --version

# see #546 for context on why this is necessary
- name: Create venv
run: |
python -m venv lint_py_imports

- name: Install job dependencies
run: |
source ./lint_py_imports/bin/activate
pip install jupyterlab~=4.0
pip install import-linter~=1.12.1
dlqqq marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Jupyter AI packages from source
run: |
source ./lint_py_imports/bin/activate
jlpm install
jlpm install-from-src

- name: Lint Python imports
run: |
source ./lint_py_imports/bin/activate
lint-imports
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"dev-uninstall": {
"dependsOn": ["clean:labextension"]
},
"install-from-src": {
"dependsOn": ["^install-from-src"]
}
},
"tasksRunnerOptions": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dev": "jupyter lab --config playground/config.py",
"dev-install": "lerna run dev-install --stream",
"dev-uninstall": "lerna run dev-uninstall --stream",
"install-from-src": "lerna run install-from-src --stream",
"lint": "jlpm && lerna run prettier && lerna run eslint",
"lint:check": "lerna run prettier:check && lerna run eslint:check",
"watch": "lerna run watch --parallel --stream",
Expand Down
3 changes: 2 additions & 1 deletion packages/jupyter-ai-magics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"scripts": {
"dev-install": "pip install -e \".[dev,all]\"",
"dev-uninstall": "pip uninstall jupyter_ai_magics -y"
"dev-uninstall": "pip uninstall jupyter_ai_magics -y",
"install-from-src": "pip install ."
}
}
4 changes: 1 addition & 3 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
from jupyter_ai.config_manager import ConfigManager, Logger
from jupyter_ai.models import AgentChatMessage, ChatMessage, HumanChatMessage
from jupyter_ai_magics.providers import BaseProvider

# necessary to prevent circular import
from pydantic import BaseModel
from langchain.pydantic_v1 import BaseModel

if TYPE_CHECKING:
from jupyter_ai.handlers import RootChatHandler
Expand Down
3 changes: 2 additions & 1 deletion packages/jupyter-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"watch:src": "tsc -w",
"watch:labextension": "jupyter labextension watch .",
"dev-install": "pip install -e \".[dev,all,test]\" && jupyter labextension develop . --overwrite && jupyter server extension enable jupyter_ai",
"dev-uninstall": "pip uninstall jupyter_ai -y"
"dev-uninstall": "pip uninstall jupyter_ai -y",
"install-from-src": "pip install ."
},
"dependencies": {
"@emotion/react": "^11.10.5",
Expand Down
16 changes: 6 additions & 10 deletions packages/jupyter-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ dependencies = [
"aiosqlite>=0.18",
"importlib_metadata>=5.2.0",
"langchain==0.0.350",
"tiktoken", # required for OpenAIEmbeddings
"tiktoken", # required for OpenAIEmbeddings
"jupyter_ai_magics",
"dask[distributed]",
"faiss-cpu", # Not distributed by official repo
"faiss-cpu", # Not distributed by official repo
"typing_extensions>=4.5.0",
"traitlets>=5.0",
"deepmerge>=1.0"
"deepmerge>=1.0",
]

dynamic = ["version", "description", "authors", "urls", "keywords"]
Expand All @@ -51,16 +51,12 @@ test = [
"pytest-cov",
"pytest-tornasync",
"pytest-jupyter",
"syrupy~=4.0.8"
"syrupy~=4.0.8",
]

dev = [
"jupyter_ai_magics[dev]"
]
dev = ["jupyter_ai_magics[dev]"]

all = [
"jupyter_ai_magics[all]"
]
all = ["jupyter_ai_magics[all]"]

[tool.hatch.version]
source = "nodejs"
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ ignore = [".*"]

[tool.check-wheel-contents]
ignore = ["W002"]

[tool.importlinter]
root_packages = ["jupyter_ai", "jupyter_ai_magics"]
include_external_packages = true

[[tool.importlinter.contracts]]
key = "pydantic"
name = "Forbidden import of `pydantic` package. Please import from `langchain.pydantic_v1` instead for compatibility with both Pydantic v1 and v2."
type = "forbidden"
source_modules = ["jupyter_ai", "jupyter_ai_magics"]
forbidden_modules = ["pydantic"]
Loading