From c1e11ba5c088921b5a2be7c70ea07e3d8fa033d0 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:41:31 +0100 Subject: [PATCH 01/13] Test Python 3.9 and 3.13 on CI, test minimum dependencies --- .github/workflows/unit-tests.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 05224180e..eccaba7ef 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -12,14 +12,24 @@ on: jobs: unit-tests: - name: Unit tests + name: Unit tests (Python ${{ matrix.python-version }}, ${{ matrix.dependency-type }} dependencies) runs-on: ubuntu-latest + strategy: + matrix: + include: + - dependency-type: minimum + python-version: "3.9" + - dependency-type: standard + python-version: "3.13" steps: - name: Checkout uses: actions/checkout@v4 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + with: + python_version: ${{ matrix.python-version }} + dependency_type: ${{ matrix.dependency-type }} - name: Install extension dependencies and build the extension run: ./scripts/install.sh From 27f75ed9802d9a47134e00aa166c32319ad3ce2d Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:56:15 +0100 Subject: [PATCH 02/13] Bump versions in pyproject.toml files, define hatch build --- packages/jupyter-ai-magics/pyproject.toml | 4 ++-- packages/jupyter-ai/pyproject.toml | 4 ++-- pyproject.toml | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index 91ef5699f..915065d95 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -6,17 +6,17 @@ build-backend = "hatchling.build" name = "jupyter_ai_magics" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Framework :: Jupyter", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] dynamic = ["version", "description", "authors", "urls", "keywords"] diff --git a/packages/jupyter-ai/pyproject.toml b/packages/jupyter-ai/pyproject.toml index 88f5fc55f..6ce69e890 100644 --- a/packages/jupyter-ai/pyproject.toml +++ b/packages/jupyter-ai/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "jupyter_ai" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Framework :: Jupyter", "Framework :: Jupyter :: JupyterLab", @@ -16,11 +16,11 @@ classifiers = [ "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] dependencies = [ "jupyter_server>=1.6,<3", diff --git a/pyproject.toml b/pyproject.toml index d10ce4594..c30c5f1b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "jupyter_ai_monorepo" dynamic = ["version", "description", "authors", "urls", "keywords"] -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = [] [project.optional-dependencies] @@ -22,6 +22,15 @@ text = "BSD 3-Clause License" source = "nodejs" path = "package.json" +[tool.hatch.build] +packages = [ + "packages/jupyter-ai-magics", + "packages/jupyter-ai" +] + +[tool.hatch.metadata] +allow-direct-references = true + [tool.check-manifest] ignore = [".*"] From bbed7ce097ad9604af0f1a17089f7433c62a73a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:58:50 +0000 Subject: [PATCH 03/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../jupyter-ai-magics/jupyter_ai_magics/tests/test_magics.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/tests/test_magics.py b/packages/jupyter-ai-magics/jupyter_ai_magics/tests/test_magics.py index 6e6b34fe9..bd440a97a 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/tests/test_magics.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/tests/test_magics.py @@ -91,8 +91,9 @@ def test_max_history(ip, transcript, max_history, expected_context): ai_magics.transcript = transcript.copy() ai_magics.max_history = max_history provider = ai_magics._get_provider("openrouter") - with patch.object(provider, "generate") as generate, patch.dict( - os.environ, OPENROUTER_API_KEY="123" + with ( + patch.object(provider, "generate") as generate, + patch.dict(os.environ, OPENROUTER_API_KEY="123"), ): generate.return_value.generations = [[Mock(text="Leet code")]] result = ip.run_cell_magic( From 9affd843b8ffc38043ae9b2e64dab05809bb0b14 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:13:51 +0100 Subject: [PATCH 04/13] Fix spurious dev install in Python unit tests job --- .github/workflows/unit-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index eccaba7ef..e847f10fe 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -15,6 +15,7 @@ jobs: name: Unit tests (Python ${{ matrix.python-version }}, ${{ matrix.dependency-type }} dependencies) runs-on: ubuntu-latest strategy: + fail-fast: false matrix: include: - dependency-type: minimum @@ -31,9 +32,6 @@ jobs: python_version: ${{ matrix.python-version }} dependency_type: ${{ matrix.dependency-type }} - - name: Install extension dependencies and build the extension - run: ./scripts/install.sh - - name: Execute unit tests run: | set -eux From ea2cf9284355e84cea87ddb1800e0d6ef779516e Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:31:06 +0100 Subject: [PATCH 05/13] Restore the install from script, add pip list --- .github/workflows/unit-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e847f10fe..62082506d 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -32,6 +32,12 @@ jobs: python_version: ${{ matrix.python-version }} dependency_type: ${{ matrix.dependency-type }} + - name: Install extension dependencies and build the extension + run: ./scripts/install.sh + + - name: List installed versions + run: pip list + - name: Execute unit tests run: | set -eux From 9013e7b018f2283c5e635880c2973825bd7a9779 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:32:55 +0100 Subject: [PATCH 06/13] Fix the issue --- .../jupyter-ai/jupyter_ai/document_loaders/directory.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py index d8610fcf6..6fcce2752 100644 --- a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py +++ b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py @@ -136,7 +136,12 @@ def collect_filepaths(path, all_files: bool): filepaths = walk_directory(path, all_files) else: filepaths = [] - for glob_path in iglob(str(path), include_hidden=all_files, recursive=True): + kwargs = ( + {"include_hidden": all_files} + if "include_hidden" in inspect.signature(iglob).parameters + else {} + ) + for glob_path in iglob(str(path), recursive=True, **kwargs): if os.path.isfile(glob_path): filepaths.append(Path(glob_path)) valid_exts = {j.lower() for j in SUPPORTED_EXTS} From a6a867466c3de41d434bdd2f77747c983e4b0451 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:41:30 +0100 Subject: [PATCH 07/13] Satisfy mypy typing, fix missing import --- .../jupyter_ai/document_loaders/directory.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py index 6fcce2752..3e8b144c5 100644 --- a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py +++ b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py @@ -4,6 +4,7 @@ import tarfile from datetime import datetime from glob import iglob +from inspect import signature from pathlib import Path from typing import List @@ -136,12 +137,12 @@ def collect_filepaths(path, all_files: bool): filepaths = walk_directory(path, all_files) else: filepaths = [] - kwargs = ( - {"include_hidden": all_files} - if "include_hidden" in inspect.signature(iglob).parameters - else {} + glob_iterator = ( + iglob(str(path), recursive=True, include_hidden=all_files) + if "include_hidden" in signature(iglob).parameters + else iglob(str(path), recursive=True) ) - for glob_path in iglob(str(path), recursive=True, **kwargs): + for glob_path in glob_iterator: if os.path.isfile(glob_path): filepaths.append(Path(glob_path)) valid_exts = {j.lower() for j in SUPPORTED_EXTS} From 3d3a037eeb9f782912e33f1d0210254d4ec372e8 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:43:48 +0100 Subject: [PATCH 08/13] Fail if any of commands in install script fails --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index ae5de0ffd..bfe594b03 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -eux # install core packages pip install jupyterlab~=4.0 cp playground/config.example.py playground/config.py From 6080b0024718c68a0ba76d4bdb00187bba5ece6a Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:47:11 +0100 Subject: [PATCH 09/13] Revert back the attempt to use 3.13 --- .github/workflows/unit-tests.yml | 2 +- packages/jupyter-ai-magics/pyproject.toml | 4 ++-- packages/jupyter-ai/pyproject.toml | 4 ++-- pyproject.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 62082506d..70c270cd6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,7 +21,7 @@ jobs: - dependency-type: minimum python-version: "3.9" - dependency-type: standard - python-version: "3.13" + python-version: "3.12" steps: - name: Checkout uses: actions/checkout@v4 diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index 915065d95..91ef5699f 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -6,17 +6,17 @@ build-backend = "hatchling.build" name = "jupyter_ai_magics" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.9" +requires-python = ">=3.8" classifiers = [ "Framework :: Jupyter", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", ] dynamic = ["version", "description", "authors", "urls", "keywords"] diff --git a/packages/jupyter-ai/pyproject.toml b/packages/jupyter-ai/pyproject.toml index 6ce69e890..88f5fc55f 100644 --- a/packages/jupyter-ai/pyproject.toml +++ b/packages/jupyter-ai/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "jupyter_ai" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.9" +requires-python = ">=3.8" classifiers = [ "Framework :: Jupyter", "Framework :: Jupyter :: JupyterLab", @@ -16,11 +16,11 @@ classifiers = [ "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", ] dependencies = [ "jupyter_server>=1.6,<3", diff --git a/pyproject.toml b/pyproject.toml index c30c5f1b7..46d1f25ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "jupyter_ai_monorepo" dynamic = ["version", "description", "authors", "urls", "keywords"] -requires-python = ">=3.9" +requires-python = ">=3.8" dependencies = [] [project.optional-dependencies] From e0fccd776c7c5e111ad375ae68065695fa97103a Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:05:35 +0100 Subject: [PATCH 10/13] Add local dependencies specification --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 46d1f25ab..569af44ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,10 @@ build-backend = "hatchling.build" name = "jupyter_ai_monorepo" dynamic = ["version", "description", "authors", "urls", "keywords"] requires-python = ">=3.8" -dependencies = [] +dependencies = [ + "jupyter-ai-magics @ {root:uri}/packages/jupyter-ai-magics", + "jupyter-ai @ {root:uri}/packages/jupyter-ai" +] [project.optional-dependencies] build = [] From 97252257af129c7c862068083ca88f559644255b Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:57:33 +0100 Subject: [PATCH 11/13] Update the `requires-python` to `>=3.9,<3.13` in monorepo --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 569af44ed..62d93604c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "jupyter_ai_monorepo" dynamic = ["version", "description", "authors", "urls", "keywords"] -requires-python = ">=3.8" +requires-python = ">=3.9,<3.13" dependencies = [ "jupyter-ai-magics @ {root:uri}/packages/jupyter-ai-magics", "jupyter-ai @ {root:uri}/packages/jupyter-ai" From 610eeee97318afad34fe4745b751eec16243bd53 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:03:09 +0100 Subject: [PATCH 12/13] Drop `include_hidden=all_files` from `iglob` instead as per review users can still do `/learn .*` and it would be in line how `bash`/`zsh` works (e.g. `ls * -a` does not files in hidden directories but `ls .*` does). --- .../jupyter-ai/jupyter_ai/document_loaders/directory.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py index 3e8b144c5..d3b81a839 100644 --- a/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py +++ b/packages/jupyter-ai/jupyter_ai/document_loaders/directory.py @@ -4,7 +4,6 @@ import tarfile from datetime import datetime from glob import iglob -from inspect import signature from pathlib import Path from typing import List @@ -137,12 +136,7 @@ def collect_filepaths(path, all_files: bool): filepaths = walk_directory(path, all_files) else: filepaths = [] - glob_iterator = ( - iglob(str(path), recursive=True, include_hidden=all_files) - if "include_hidden" in signature(iglob).parameters - else iglob(str(path), recursive=True) - ) - for glob_path in glob_iterator: + for glob_path in iglob(str(path), recursive=True): if os.path.isfile(glob_path): filepaths.append(Path(glob_path)) valid_exts = {j.lower() for j in SUPPORTED_EXTS} From 0f4ea9bc3e7f09df830272d177f56ffcda639225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Krassowski?= <5832902+krassowski@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:26:43 +0100 Subject: [PATCH 13/13] Update Python pin to just `>3.9` --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 62d93604c..322177455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "jupyter_ai_monorepo" dynamic = ["version", "description", "authors", "urls", "keywords"] -requires-python = ">=3.9,<3.13" +requires-python = ">=3.9" dependencies = [ "jupyter-ai-magics @ {root:uri}/packages/jupyter-ai-magics", "jupyter-ai @ {root:uri}/packages/jupyter-ai"