From 27cff211644cccc75c80d25af6a4360623e49c16 Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Mon, 18 Mar 2024 22:55:56 +0000 Subject: [PATCH 1/6] Add mypy check in pre-commit --- .github/workflows/type-check.yml | 9 ++++----- .pre-commit-config.yaml | 16 ++++++++++++++++ pyproject.toml | 5 +++++ scripts/pre-commit-mypy-run.sh | 23 +++++++++++++++++++++++ setup.py | 4 ++++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100755 scripts/pre-commit-mypy-run.sh diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml index ee790d8d5ca1..d9335dba648c 100644 --- a/.github/workflows/type-check.yml +++ b/.github/workflows/type-check.yml @@ -17,9 +17,8 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - - run: pip install ".[jupyter-executor]" mypy - # As more modules are type check clean, add them here + # All additional modules should be defined in setup.py + - run: pip install ".[types]" + # Any additional configuration should be defined in pyproject.toml - run: | - mypy --install-types --non-interactive \ - autogen/logger \ - autogen/exception_utils.py + mypy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b2751f1677f3..95c07994ad15 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,6 +44,22 @@ repos: website/docs/tutorial/code-executors.ipynb | notebook/.* )$ + # See https://jaredkhan.com/blog/mypy-pre-commit + - repo: local + hooks: + - id: mypy + name: mypy + entry: "./scripts/pre-commit-mypy-run.sh" + language: python + # use your preferred Python version + # language_version: python3.8 + additional_dependencies: [".[types]"] + types: [python] + # use require_serial so that script + # is only called once per commit + require_serial: true + # Print the number of files as a sanity-check + verbose: true - repo: https://github.com/nbQA-dev/nbQA rev: 1.7.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index f1763fba37ea..630bf861a6fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,11 @@ max-complexity = 10 [tool.mypy] +files = [ + "autogen/logger", + "autogen/exception_utils.py", +] + strict = true python_version = "3.8" ignore_missing_imports = true diff --git a/scripts/pre-commit-mypy-run.sh b/scripts/pre-commit-mypy-run.sh new file mode 100755 index 000000000000..59b7b29266ce --- /dev/null +++ b/scripts/pre-commit-mypy-run.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# taken from: https://jaredkhan.com/blog/mypy-pre-commit + +# A script for running mypy, +# with all its dependencies installed. + +set -o errexit + +# Change directory to the project root directory. +cd "$(dirname "$0")"/.. + +# Install the dependencies into the mypy env. +# Note that this can take seconds to run. +# In my case, I need to use a custom index URL. +# Avoid pip spending time quietly retrying since +# likely cause of failure is lack of VPN connection. +# pip install --editable ".[types]"\ +# --retries 1 \ +# --no-input \ +# --quiet + +mypy diff --git a/setup.py b/setup.py index c7b3e319be13..8a123e5913d8 100644 --- a/setup.py +++ b/setup.py @@ -64,6 +64,10 @@ "jupyter-client>=8.6.0", "ipykernel>=6.29.0", ], + "types": [ + "mypy==1.9.0", + ".[jupyter-executor]", + ], }, classifiers=[ "Programming Language :: Python :: 3", From ce7e3f9109b13f965babb84d61c26664b490204a Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Mon, 18 Mar 2024 22:57:00 +0000 Subject: [PATCH 2/6] Add mypy check in pre-commit --- scripts/pre-commit-mypy-run.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/scripts/pre-commit-mypy-run.sh b/scripts/pre-commit-mypy-run.sh index 59b7b29266ce..49a14e08375d 100755 --- a/scripts/pre-commit-mypy-run.sh +++ b/scripts/pre-commit-mypy-run.sh @@ -10,14 +10,4 @@ set -o errexit # Change directory to the project root directory. cd "$(dirname "$0")"/.. -# Install the dependencies into the mypy env. -# Note that this can take seconds to run. -# In my case, I need to use a custom index URL. -# Avoid pip spending time quietly retrying since -# likely cause of failure is lack of VPN connection. -# pip install --editable ".[types]"\ -# --retries 1 \ -# --no-input \ -# --quiet - mypy From 1ceab1797e49b7edf4db0d25c3f78effbd9a4501 Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Mon, 18 Mar 2024 23:12:25 +0000 Subject: [PATCH 3/6] bug fix --- setup.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 8a123e5913d8..4f94ad5e5896 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,14 @@ "docker", ] +jupyter_executor = [ + "jupyter-kernel-gateway", + "websocket-client", + "requests", + "jupyter-client>=8.6.0", + "ipykernel>=6.29.0", +] + setuptools.setup( name="pyautogen", version=__version__, @@ -57,17 +65,8 @@ "graph": ["networkx", "matplotlib"], "websurfer": ["beautifulsoup4", "markdownify", "pdfminer.six", "pathvalidate"], "redis": ["redis"], - "jupyter-executor": [ - "jupyter-kernel-gateway", - "websocket-client", - "requests", - "jupyter-client>=8.6.0", - "ipykernel>=6.29.0", - ], - "types": [ - "mypy==1.9.0", - ".[jupyter-executor]", - ], + "jupyter-executor": jupyter_executor, + "types": ["mypy==1.9.0"] + jupyter_executor, }, classifiers=[ "Programming Language :: Python :: 3", From e04a92e7bf5df989b037b6bea9df98a6fa2af642 Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Mon, 18 Mar 2024 23:22:28 +0000 Subject: [PATCH 4/6] CI fix --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 18b23afd18e3..e6815db00a26 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -18,6 +18,8 @@ jobs: pre-commit-check: runs-on: ubuntu-latest + env: + SKIP: "mypy" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From 716f1bc85f050f9f7d33bc4b1db68a7e4adadc05 Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Tue, 19 Mar 2024 08:11:38 +0000 Subject: [PATCH 5/6] add python version matrix for checking types in CI --- .github/workflows/type-check.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml index d9335dba648c..e807a233e314 100644 --- a/.github/workflows/type-check.yml +++ b/.github/workflows/type-check.yml @@ -13,10 +13,16 @@ permissions: {} jobs: type-check: + strategy: + fail-fast: true + matrix: + version: ["3.8", "3.9", "3.10", "3.11"] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.version }} # All additional modules should be defined in setup.py - run: pip install ".[types]" # Any additional configuration should be defined in pyproject.toml From a9fd147012bf43977e5ed45df9d7f40b2d769512 Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Tue, 19 Mar 2024 22:20:55 +0000 Subject: [PATCH 6/6] added 3.12 to CI --- .github/workflows/type-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml index e807a233e314..7769794e6bdb 100644 --- a/.github/workflows/type-check.yml +++ b/.github/workflows/type-check.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - version: ["3.8", "3.9", "3.10", "3.11"] + version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4