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

Add mypy to pre-commit #2068

Merged
merged 10 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ 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
- 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]"
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
# Any additional configuration should be defined in pyproject.toml
- run: |
mypy --install-types --non-interactive \
autogen/logger \
autogen/exception_utils.py
mypy
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ max-complexity = 10

[tool.mypy]

files = [
"autogen/logger",
"autogen/exception_utils.py",
]

strict = true
python_version = "3.8"
ignore_missing_imports = true
Expand Down
13 changes: 13 additions & 0 deletions scripts/pre-commit-mypy-run.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 10 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
Expand Down Expand Up @@ -57,13 +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",
],
"jupyter-executor": jupyter_executor,
"types": ["mypy==1.9.0"] + jupyter_executor,
},
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
Loading