From bae2edd1a582afc5372243cb6188a32e2bc7d1b2 Mon Sep 17 00:00:00 2001 From: Matthias Feys Date: Fri, 11 May 2018 19:10:49 +0200 Subject: [PATCH] Futurize options subpackage --- sdks/python/apache_beam/options/__init__.py | 1 + sdks/python/apache_beam/options/pipeline_options.py | 7 +++++-- sdks/python/apache_beam/options/pipeline_options_test.py | 2 ++ .../apache_beam/options/pipeline_options_validator.py | 3 +++ .../apache_beam/options/pipeline_options_validator_test.py | 3 +++ sdks/python/apache_beam/options/value_provider.py | 6 ++++++ sdks/python/apache_beam/options/value_provider_test.py | 3 +++ sdks/python/tox.ini | 1 + 8 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/options/__init__.py b/sdks/python/apache_beam/options/__init__.py index cce3acad34a4..f4f43cbb1236 100644 --- a/sdks/python/apache_beam/options/__init__.py +++ b/sdks/python/apache_beam/options/__init__.py @@ -14,3 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from __future__ import absolute_import diff --git a/sdks/python/apache_beam/options/pipeline_options.py b/sdks/python/apache_beam/options/pipeline_options.py index b5f9d77617da..0c96325d70cd 100644 --- a/sdks/python/apache_beam/options/pipeline_options.py +++ b/sdks/python/apache_beam/options/pipeline_options.py @@ -17,7 +17,10 @@ """Pipeline options obtained from command line parsing.""" +from __future__ import absolute_import + import argparse +from builtins import object from apache_beam.options.value_provider import RuntimeValueProvider from apache_beam.options.value_provider import StaticValueProvider @@ -175,7 +178,7 @@ def from_dictionary(cls, options): A PipelineOptions object representing the given arguments. """ flags = [] - for k, v in options.iteritems(): + for k, v in options.items(): if isinstance(v, bool): if v: flags.append('--%s' % k) @@ -233,7 +236,7 @@ def _visible_option_list(self): for option in dir(self._visible_options) if option[0] != '_') def __dir__(self): - return sorted(dir(type(self)) + self.__dict__.keys() + + return sorted(dir(type(self)) + list(self.__dict__.keys()) + self._visible_option_list()) def __getattr__(self, name): diff --git a/sdks/python/apache_beam/options/pipeline_options_test.py b/sdks/python/apache_beam/options/pipeline_options_test.py index 66c69bdfc70e..289e67f15fe3 100644 --- a/sdks/python/apache_beam/options/pipeline_options_test.py +++ b/sdks/python/apache_beam/options/pipeline_options_test.py @@ -17,6 +17,8 @@ """Unit tests for the pipeline options module.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/options/pipeline_options_validator.py b/sdks/python/apache_beam/options/pipeline_options_validator.py index 24d2e55eadbe..874e739fb611 100644 --- a/sdks/python/apache_beam/options/pipeline_options_validator.py +++ b/sdks/python/apache_beam/options/pipeline_options_validator.py @@ -19,7 +19,10 @@ For internal use only; no backwards-compatibility guarantees. """ +from __future__ import absolute_import + import re +from builtins import object from apache_beam.internal import pickler from apache_beam.options.pipeline_options import DebugOptions diff --git a/sdks/python/apache_beam/options/pipeline_options_validator_test.py b/sdks/python/apache_beam/options/pipeline_options_validator_test.py index 8ff66c78f17b..c0582e2f7d1e 100644 --- a/sdks/python/apache_beam/options/pipeline_options_validator_test.py +++ b/sdks/python/apache_beam/options/pipeline_options_validator_test.py @@ -17,8 +17,11 @@ """Unit tests for the pipeline options validator module.""" +from __future__ import absolute_import + import logging import unittest +from builtins import object from hamcrest.core.base_matcher import BaseMatcher diff --git a/sdks/python/apache_beam/options/value_provider.py b/sdks/python/apache_beam/options/value_provider.py index 4aaa0f744741..0ef83e344c99 100644 --- a/sdks/python/apache_beam/options/value_provider.py +++ b/sdks/python/apache_beam/options/value_provider.py @@ -19,6 +19,9 @@ and dynamically provided values. """ +from __future__ import absolute_import + +from builtins import object from functools import wraps from apache_beam import error @@ -66,6 +69,9 @@ def __eq__(self, other): return True return False + def __hash__(self): + return hash((type(self), self.value_type, self.value)) + class RuntimeValueProvider(ValueProvider): runtime_options = None diff --git a/sdks/python/apache_beam/options/value_provider_test.py b/sdks/python/apache_beam/options/value_provider_test.py index 482ea47504ae..bc0271482349 100644 --- a/sdks/python/apache_beam/options/value_provider_test.py +++ b/sdks/python/apache_beam/options/value_provider_test.py @@ -16,6 +16,9 @@ # """Unit tests for the ValueProvider class.""" + +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 61dc12c3017a..2f0ee9ab0029 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -100,6 +100,7 @@ deps = modules = apache_beam/coders apache_beam/metrics + apache_beam/options commands = python --version pip --version