This is an automated email from the ASF dual-hosted git repository. robertwb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push: new a353733 [BEAM-7737] Fix microbenchmark scripts compiled check (#9066) a353733 is described below commit a35373308d3901ca729a21b7c797c5288ec09671 Author: Rakesh Kumar <rakeshku...@lyft.com> AuthorDate: Mon Jul 15 05:21:47 2019 -0700 [BEAM-7737] Fix microbenchmark scripts compiled check (#9066) --- sdks/python/apache_beam/tools/microbenchmarks_test.py | 18 ++++++++++++++++++ sdks/python/apache_beam/tools/utils.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/tools/microbenchmarks_test.py b/sdks/python/apache_beam/tools/microbenchmarks_test.py index d306122..c757ebc 100644 --- a/sdks/python/apache_beam/tools/microbenchmarks_test.py +++ b/sdks/python/apache_beam/tools/microbenchmarks_test.py @@ -21,7 +21,11 @@ from __future__ import absolute_import import unittest +from pkg_resources import DistributionNotFound +from pkg_resources import get_distribution + from apache_beam.tools import coders_microbenchmark +from apache_beam.tools import utils class MicrobenchmarksTest(unittest.TestCase): @@ -31,6 +35,20 @@ class MicrobenchmarksTest(unittest.TestCase): coders_microbenchmark.run_coder_benchmarks( num_runs=1, input_size=10, seed=1, verbose=False) + def is_cython_installed(self): + try: + get_distribution('cython') + return True + except DistributionNotFound: + return False + + def test_check_compiled(self): + if self.is_cython_installed(): + utils.check_compiled('apache_beam.runners.worker.opcounters') + else: + with self.assertRaises(RuntimeError): + utils.check_compiled('apache_beam.runners.worker.opcounters') + if __name__ == '__main__': unittest.main() diff --git a/sdks/python/apache_beam/tools/utils.py b/sdks/python/apache_beam/tools/utils.py index 0d99b46..7c0211e 100644 --- a/sdks/python/apache_beam/tools/utils.py +++ b/sdks/python/apache_beam/tools/utils.py @@ -23,6 +23,7 @@ from __future__ import print_function import collections import gc +import importlib import os import time @@ -34,7 +35,7 @@ def check_compiled(module): Args: module: string, module name """ - check_module = __import__(module, globals(), locals()) + check_module = importlib.import_module(module) ext = os.path.splitext(check_module.__file__)[-1] if ext in ('.py', '.pyc'): raise RuntimeError(