Skip to content

A programming framework for agentic AI

Add mypy to pre-commit (#2068)

Davor Runje99e48dc02404
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
index 18b23afd1..e6815db00 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
diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml
index 32e015edb..7769794e6 100644
--- a/.github/workflows/type-check.yml
+++ b/.github/workflows/type-check.yml
@@ -13,15 +13,18 @@ permissions: {}
jobs:
type-check:
+ strategy:
+ fail-fast: true
+ matrix:
+ version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
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
+ - 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
- run: |
- mypy \
- autogen/logger \
- autogen/exception_utils.py \
- autogen/coding \
- autogen/oai/openai_utils.py
+ mypy
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6b27154f9..3f4880794 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.8.4
hooks:
diff --git a/pyproject.toml b/pyproject.toml
index 570799849..fbcbb9b0a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -62,6 +62,13 @@ max-complexity = 10
[tool.mypy]
+files = [
+ "autogen/logger",
+ "autogen/exception_utils.py",
+ "autogen/coding",
+ "autogen/oai/openai_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 000000000..49a14e083
--- /dev/null
+++ b/scripts/pre-commit-mypy-run.sh
@@ -0,0 +1,13 @@
+#!/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")"/..
+
+mypy
diff --git a/setup.py b/setup.py
index c7b3e319b..4f94ad5e5 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,14 @@ install_requires = [
"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,13 +65,8 @@ setuptools.setup(
"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",
- ],
+ "jupyter-executor": jupyter_executor,
+ "types": ["mypy==1.9.0"] + jupyter_executor,
},
classifiers=[
"Programming Language :: Python :: 3",