Skip to content

Commit

Permalink
basic mypy testing in tox
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrik committed Jul 17, 2019
1 parent 59cffe3 commit 9f334c5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mypy.ini
Expand Up @@ -6,7 +6,7 @@ warn_no_return = false
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
plugins = beam_plugin
#plugins = beam_plugin

[mypy-apache_beam.runners.dataflow.internal.clients.dataflow.dataflow_v1b3_client]
ignore_errors = true
Expand Down
53 changes: 53 additions & 0 deletions sdks/python/setup.py
Expand Up @@ -25,19 +25,71 @@
import sys
import warnings
from distutils.version import StrictVersion
from distutils.errors import DistutilsError

# Pylint and isort disagree here.
# pylint: disable=ungrouped-imports
import setuptools
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution
from pkg_resources import normalize_path
from pkg_resources import to_filename
from setuptools import Command
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.egg_info import egg_info
from setuptools.command.sdist import sdist
from setuptools.command.test import test


class mypy(Command):
user_options = []

def initialize_options(self):
"""Abstract method that is required to be overwritten"""

def finalize_options(self):
"""Abstract method that is required to be overwritten"""

def get_project_path(self, include_dists=[]):
# with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False)
#
# if with_2to3:
# # If we run 2to3 we can not do this inplace:
#
# # Ensure metadata is up-to-date
# self.reinitialize_command('build_py', inplace=0)
# self.run_command('build_py')
# bpy_cmd = self.get_finalized_command("build_py")
# build_path = normalize_path(bpy_cmd.build_lib)
#
# # Build extensions
# self.reinitialize_command('egg_info', egg_base=build_path)
# self.run_command('egg_info')
#
# self.reinitialize_command('build_ext', inplace=0)
# self.run_command('build_ext')
# else:
# Without 2to3 inplace works fine:
self.run_command('egg_info')

# Build extensions in-place
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')

ei_cmd = self.get_finalized_command("egg_info")

project_path = normalize_path(ei_cmd.egg_base)
return os.path.join(project_path, to_filename(ei_cmd.egg_name))

def run(self):
import subprocess
args = ['mypy', self.get_project_path()]
result = subprocess.call(args)
if result != 0:
raise DistutilsError()


def get_version():
global_names = {}
exec( # pylint: disable=exec-used
Expand Down Expand Up @@ -236,5 +288,6 @@ def run(self):
'egg_info': generate_protos_first(egg_info),
'sdist': generate_protos_first(sdist),
'test': generate_protos_first(test),
'mypy': generate_protos_first(mypy),
},
)
10 changes: 8 additions & 2 deletions sdks/python/tox.ini
Expand Up @@ -17,7 +17,7 @@

[tox]
# new environments will be excluded by default unless explicitly added to envlist.
envlist = py27,py35,py36,py37,py27-{gcp,cython,lint,lint3},py35-{gcp,cython,lint},py36-{gcp,cython},py37-{gcp,cython},docs
envlist = py27,py35,py36,py37,py27-{gcp,cython,lint,lint3},py35-{gcp,cython,lint},py36-{gcp,cython},py37-{gcp,cython,mypy},docs
toxworkdir = {toxinidir}/target/{env:ENV_NAME:.tox}

[pycodestyle]
Expand Down Expand Up @@ -172,7 +172,6 @@ commands =
pylint --version
time {toxinidir}/scripts/run_pylint_2to3.sh


[testenv:py35-lint]
deps =
pycodestyle==2.3.1
Expand All @@ -184,6 +183,13 @@ commands =
pylint --version
time {toxinidir}/scripts/run_mini_py3lint.sh

[testenv:py37-mypy]
deps =
mypy==0.711
commands =
mypy --version
python setup.py mypy

[testenv:docs]
extras = test,gcp,docs
deps =
Expand Down

0 comments on commit 9f334c5

Please sign in to comment.