Skip to content

Commit

Permalink
Make mypy an optional dependency (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson authored Sep 4, 2020
1 parent f975317 commit 34eff19
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions traits-stubs/traits_stubs_tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

import pkg_resources

from traits.testing.optional_dependencies import requires_mypy
from traits_stubs_tests.util import MypyAssertions


@requires_mypy
class TestAnnotations(TestCase, MypyAssertions):
def test_all(self, filename_suffix=''):
""" Run mypy for all files contained in traits_stubs_tests/examples
Expand Down
5 changes: 3 additions & 2 deletions traits-stubs/traits_stubs_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import re
import tempfile

from mypy import api as mypy_api


def parse_py_file(filepath):
""" This function parses a python file that have been annotated with error
Expand Down Expand Up @@ -98,6 +96,9 @@ def run_mypy(filepath):
The exit status
"""
# Local import to make it easier to skip tests if mypy is not in
# the environment.
from mypy import api as mypy_api

# Need to use tempdir since mypy complains that:
# "site-packages is in PYTHONPATH. Please change directory so it is not."
Expand Down
3 changes: 3 additions & 0 deletions traits/testing/optional_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def optional_import(name):
cython = optional_import("cython")
requires_cython = unittest.skipIf(cython is None, "Cython not available")

mypy = optional_import("mypy")
requires_mypy = unittest.skipIf(mypy is None, "Mypy not available")

numpy = optional_import("numpy")
requires_numpy = unittest.skipIf(numpy is None, "NumPy not available")

Expand Down

0 comments on commit 34eff19

Please sign in to comment.