Skip to content

Commit

Permalink
Change mypy to be run in a pre-commit managed env.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Oct 10, 2023
1 parent ba9c330 commit 863be75
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/code-checks.yml

This file was deleted.

26 changes: 24 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches: [ "main" ]

jobs:

unittest-windows:
runs-on: windows-2019
strategy:
Expand All @@ -17,9 +18,11 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pip
allow-prereleases: true
- run: pip install tox
- run: tox -e py-all-extras

unittest-macos:
runs-on: macOS-12
strategy:
Expand All @@ -31,24 +34,43 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install tox
- run: tox -e py-all-extras

unittest-omegaconf:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
cache: pip
- run: pip install tox
- run: tox -e omegaconf

doctest:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- run: pip install -e .[all,doc]
- name: Run doc tests
run: sphinx-build -M doctest sphinx sphinx/_build sphinx/index.rst

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
- uses: actions/cache@v3
with:
key: pre-commit-cache
path: ~/.cache/pre-commit
- run: pip install pre-commit
- run: pre-commit run -a --hook-stage pre-push mypy
22 changes: 13 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ repos:
args: []
verbose: true

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
files: jsonargparse.*/.*.py
stages: [pre-push]
additional_dependencies:
[
types-PyYAML,
types-requests,
]
verbose: true

- repo: local
hooks:

Expand Down Expand Up @@ -87,15 +100,6 @@ repos:
pass_filenames: false
verbose: true

- id: mypy
name: mypy jsonargparse*/*.py
entry: bash -c "mypy jsonargparse*/*.py"
stages: [pre-push]
language: system
types: [python]
pass_filenames: false
verbose: true

- id: tox
name: tox --parallel
entry: tox --parallel
Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/_optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def is_pydantic_model(class_type) -> int:

if issubclass(cls, pydantic.BaseModel):
return pydantic_support
elif pydantic_support > 1 and issubclass(cls, pydantic.v1.BaseModel): # type: ignore
elif pydantic_support > 1 and issubclass(cls, pydantic.v1.BaseModel):
return 1
return 0

Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/_parameter_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def get_parameters_from_pydantic_or_attrs(
if not fields_iterator and attrs_support:
import attrs

if attrs.has(function_or_class): # type: ignore
if attrs.has(function_or_class):
fields_iterator = {f.name: f for f in attrs.fields(function_or_class)}.items()
get_field_data = get_field_data_attrs

Expand Down
2 changes: 1 addition & 1 deletion jsonargparse_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
def nothing_decorator(func):
return func

responses_activate = nothing_decorator # type: ignore
responses_activate = nothing_decorator


@pytest.fixture
Expand Down
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ reconplogger = [
]
test = [
"jsonargparse[test-no-urls]",
"jsonargparse[types-pyyaml]",
"responses>=0.12.0",
"types-PyYAML>=6.0.11",
"types-requests>=2.28.9",
"responses>=0.12.0",
"pydantic>=2.3.0",
"attrs>=22.2.0",
]
Expand All @@ -105,13 +105,6 @@ dev = [
"tox>=3.25.0",
"build>=0.10.0",
]
mypy = [
"jsonargparse[types-pyyaml]",
"mypy>=0.701",
]
types-pyyaml = [
"types-PyYAML>=6.0.11",
]
doc = [
"Sphinx>=1.7.9",
"sphinx-rtd-theme>=1.2.2",
Expand Down

0 comments on commit 863be75

Please sign in to comment.