Skip to content

Commit af08200

Browse files
davorrunjeekzhu
andauthored
Add mypy to pre-commit (microsoft#2068)
* Add mypy check in pre-commit * Add mypy check in pre-commit * bug fix * CI fix * add python version matrix for checking types in CI * added 3.12 to CI --------- Co-authored-by: Eric Zhu <[email protected]>
1 parent 93ce477 commit af08200

File tree

6 files changed

+60
-16
lines changed

6 files changed

+60
-16
lines changed

.github/workflows/pre-commit.yml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818

1919
pre-commit-check:
2020
runs-on: ubuntu-latest
21+
env:
22+
SKIP: "mypy"
2123
steps:
2224
- uses: actions/checkout@v3
2325
- uses: actions/setup-python@v4

.github/workflows/type-check.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ permissions: {}
1313

1414
jobs:
1515
type-check:
16+
strategy:
17+
fail-fast: true
18+
matrix:
19+
version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1620
runs-on: ubuntu-latest
1721
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-python@v4
20-
- run: pip install ".[jupyter-executor]" mypy
21-
# As more modules are type check clean, add them here
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.version }}
26+
# All additional modules should be defined in setup.py
27+
- run: pip install ".[types]"
28+
# Any additional configuration should be defined in pyproject.toml
2229
- run: |
23-
mypy \
24-
autogen/logger \
25-
autogen/exception_utils.py \
26-
autogen/coding \
27-
autogen/oai/openai_utils.py
30+
mypy

.pre-commit-config.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ repos:
4444
website/docs/tutorial/code-executors.ipynb |
4545
notebook/.*
4646
)$
47+
# See https://jaredkhan.com/blog/mypy-pre-commit
48+
- repo: local
49+
hooks:
50+
- id: mypy
51+
name: mypy
52+
entry: "./scripts/pre-commit-mypy-run.sh"
53+
language: python
54+
# use your preferred Python version
55+
# language_version: python3.8
56+
additional_dependencies: [".[types]"]
57+
types: [python]
58+
# use require_serial so that script
59+
# is only called once per commit
60+
require_serial: true
61+
# Print the number of files as a sanity-check
62+
verbose: true
4763
- repo: https://github.com/nbQA-dev/nbQA
4864
rev: 1.8.4
4965
hooks:

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ max-complexity = 10
6262

6363
[tool.mypy]
6464

65+
files = [
66+
"autogen/logger",
67+
"autogen/exception_utils.py",
68+
"autogen/coding",
69+
"autogen/oai/openai_utils.py",
70+
]
71+
6572
strict = true
6673
python_version = "3.8"
6774
ignore_missing_imports = true

scripts/pre-commit-mypy-run.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
# taken from: https://jaredkhan.com/blog/mypy-pre-commit
4+
5+
# A script for running mypy,
6+
# with all its dependencies installed.
7+
8+
set -o errexit
9+
10+
# Change directory to the project root directory.
11+
cd "$(dirname "$0")"/..
12+
13+
mypy

setup.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
"docker",
2828
]
2929

30+
jupyter_executor = [
31+
"jupyter-kernel-gateway",
32+
"websocket-client",
33+
"requests",
34+
"jupyter-client>=8.6.0",
35+
"ipykernel>=6.29.0",
36+
]
37+
3038
setuptools.setup(
3139
name="pyautogen",
3240
version=__version__,
@@ -57,13 +65,8 @@
5765
"graph": ["networkx", "matplotlib"],
5866
"websurfer": ["beautifulsoup4", "markdownify", "pdfminer.six", "pathvalidate"],
5967
"redis": ["redis"],
60-
"jupyter-executor": [
61-
"jupyter-kernel-gateway",
62-
"websocket-client",
63-
"requests",
64-
"jupyter-client>=8.6.0",
65-
"ipykernel>=6.29.0",
66-
],
68+
"jupyter-executor": jupyter_executor,
69+
"types": ["mypy==1.9.0"] + jupyter_executor,
6770
},
6871
classifiers=[
6972
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)