diff --git a/sdks/python/apache_beam/examples/__init__.py b/sdks/python/apache_beam/examples/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/__init__.py +++ b/sdks/python/apache_beam/examples/__init__.py @@ -14,3 +14,5 @@ # 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/examples/complete/__init__.py b/sdks/python/apache_beam/examples/complete/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/complete/__init__.py +++ b/sdks/python/apache_beam/examples/complete/__init__.py @@ -14,3 +14,5 @@ # 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/examples/complete/autocomplete.py b/sdks/python/apache_beam/examples/complete/autocomplete.py index b556e65724ca..d9717bad85b7 100644 --- a/sdks/python/apache_beam/examples/complete/autocomplete.py +++ b/sdks/python/apache_beam/examples/complete/autocomplete.py @@ -22,6 +22,7 @@ import argparse import logging import re +from builtins import range import apache_beam as beam from apache_beam.io import ReadFromText diff --git a/sdks/python/apache_beam/examples/complete/autocomplete_test.py b/sdks/python/apache_beam/examples/complete/autocomplete_test.py index 888ce44dad4d..792f6d0402c8 100644 --- a/sdks/python/apache_beam/examples/complete/autocomplete_test.py +++ b/sdks/python/apache_beam/examples/complete/autocomplete_test.py @@ -17,6 +17,8 @@ """Test for the autocomplete example.""" +from __future__ import absolute_import + import unittest import apache_beam as beam diff --git a/sdks/python/apache_beam/examples/complete/estimate_pi.py b/sdks/python/apache_beam/examples/complete/estimate_pi.py index 982faaa0f475..332346260c1b 100644 --- a/sdks/python/apache_beam/examples/complete/estimate_pi.py +++ b/sdks/python/apache_beam/examples/complete/estimate_pi.py @@ -25,11 +25,14 @@ """ from __future__ import absolute_import +from __future__ import division import argparse import json import logging import random +from builtins import object +from builtins import range import apache_beam as beam from apache_beam.io import WriteToText diff --git a/sdks/python/apache_beam/examples/complete/estimate_pi_test.py b/sdks/python/apache_beam/examples/complete/estimate_pi_test.py index 34633132e41c..78376b6e05be 100644 --- a/sdks/python/apache_beam/examples/complete/estimate_pi_test.py +++ b/sdks/python/apache_beam/examples/complete/estimate_pi_test.py @@ -17,6 +17,8 @@ """Test for the estimate_pi example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/complete/game/__init__.py b/sdks/python/apache_beam/examples/complete/game/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/complete/game/__init__.py +++ b/sdks/python/apache_beam/examples/complete/game/__init__.py @@ -14,3 +14,5 @@ # 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/examples/complete/game/game_stats.py b/sdks/python/apache_beam/examples/complete/game/game_stats.py index 11b81fe1bd20..e37076424a76 100644 --- a/sdks/python/apache_beam/examples/complete/game/game_stats.py +++ b/sdks/python/apache_beam/examples/complete/game/game_stats.py @@ -71,6 +71,7 @@ """ from __future__ import absolute_import +from __future__ import division from __future__ import print_function import argparse @@ -229,7 +230,7 @@ def expand(self, user_scores): class UserSessionActivity(beam.DoFn): """Calculate and output an element's session duration, in seconds.""" def process(self, elem, window=beam.DoFn.WindowParam): - yield (window.end.micros - window.start.micros) / 1000000 + yield (window.end.micros - window.start.micros)//1000000 def run(argv=None): diff --git a/sdks/python/apache_beam/examples/complete/game/game_stats_test.py b/sdks/python/apache_beam/examples/complete/game/game_stats_test.py index 971f9dc9e299..209f0cf88000 100644 --- a/sdks/python/apache_beam/examples/complete/game/game_stats_test.py +++ b/sdks/python/apache_beam/examples/complete/game/game_stats_test.py @@ -17,6 +17,8 @@ """Test for the game_stats example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py b/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py index e99ab23ec678..d736cf50fcee 100644 --- a/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py +++ b/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py @@ -65,6 +65,7 @@ """ from __future__ import absolute_import +from __future__ import division from __future__ import print_function import argparse diff --git a/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py b/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py index 9c30127d7416..8c2497a883c3 100644 --- a/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py +++ b/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py @@ -17,6 +17,8 @@ """Test for the user_score example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/complete/game/leader_board.py b/sdks/python/apache_beam/examples/complete/game/leader_board.py index 27ef16dd5d5e..a92eaae86912 100644 --- a/sdks/python/apache_beam/examples/complete/game/leader_board.py +++ b/sdks/python/apache_beam/examples/complete/game/leader_board.py @@ -79,6 +79,7 @@ """ from __future__ import absolute_import +from __future__ import division from __future__ import print_function import argparse diff --git a/sdks/python/apache_beam/examples/complete/game/leader_board_test.py b/sdks/python/apache_beam/examples/complete/game/leader_board_test.py index aece2649b898..3aad052fe71a 100644 --- a/sdks/python/apache_beam/examples/complete/game/leader_board_test.py +++ b/sdks/python/apache_beam/examples/complete/game/leader_board_test.py @@ -17,6 +17,8 @@ """Test for the leader_board example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/complete/game/user_score.py b/sdks/python/apache_beam/examples/complete/game/user_score.py index 5b13eeca7a3f..7e1a07d8a85d 100644 --- a/sdks/python/apache_beam/examples/complete/game/user_score.py +++ b/sdks/python/apache_beam/examples/complete/game/user_score.py @@ -54,6 +54,7 @@ """ from __future__ import absolute_import +from __future__ import division import argparse import csv @@ -87,7 +88,7 @@ def process(self, elem): 'user': row[0], 'team': row[1], 'score': int(row[2]), - 'timestamp': int(row[3]) / 1000.0, + 'timestamp': int(row[3]) /1000.0, } except: # pylint: disable=bare-except # Log and count parse errors diff --git a/sdks/python/apache_beam/examples/complete/game/user_score_test.py b/sdks/python/apache_beam/examples/complete/game/user_score_test.py index 59903d985460..f41006fd0a15 100644 --- a/sdks/python/apache_beam/examples/complete/game/user_score_test.py +++ b/sdks/python/apache_beam/examples/complete/game/user_score_test.py @@ -17,6 +17,8 @@ """Test for the user_score example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/complete/juliaset/__init__.py b/sdks/python/apache_beam/examples/complete/juliaset/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/__init__.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/__init__.py @@ -14,3 +14,5 @@ # 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/examples/complete/juliaset/juliaset/__init__.py b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py @@ -14,3 +14,5 @@ # 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/examples/complete/juliaset/juliaset/juliaset.py b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py index 1beffeef9b17..f861e48403bc 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py @@ -21,8 +21,10 @@ """ from __future__ import absolute_import +from __future__ import division import argparse +from builtins import range import apache_beam as beam from apache_beam.io import WriteToText @@ -70,7 +72,7 @@ def generate_julia_set_visualization(data, n, max_iterations): xy = np.zeros((n, n, 3), dtype=np.uint8) for x, y, iteration in data: - xy[x, y] = colors[iteration * len(colors) / max_iterations] + xy[x, y] = colors[iteration * len(colors) // max_iterations] return xy diff --git a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py index e4986271e940..a7bc0f9208fe 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py @@ -17,6 +17,8 @@ """Test for the juliaset example.""" +from __future__ import absolute_import + import logging import os import re diff --git a/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py b/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py index 7289b04b07c8..9d727726f666 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py @@ -47,6 +47,8 @@ """ +from __future__ import absolute_import + import logging from apache_beam.examples.complete.juliaset.juliaset import juliaset diff --git a/sdks/python/apache_beam/examples/complete/juliaset/setup.py b/sdks/python/apache_beam/examples/complete/juliaset/setup.py index 2fcde7d3485d..0aa730e95497 100644 --- a/sdks/python/apache_beam/examples/complete/juliaset/setup.py +++ b/sdks/python/apache_beam/examples/complete/juliaset/setup.py @@ -24,6 +24,8 @@ This behavior is triggered by specifying the --setup_file command line option when running the workflow for remote execution. """ + +from __future__ import absolute_import from __future__ import print_function import subprocess diff --git a/sdks/python/apache_beam/examples/complete/tfidf.py b/sdks/python/apache_beam/examples/complete/tfidf.py index 20ad344e96a8..3eeb898b20a9 100644 --- a/sdks/python/apache_beam/examples/complete/tfidf.py +++ b/sdks/python/apache_beam/examples/complete/tfidf.py @@ -22,6 +22,7 @@ """ from __future__ import absolute_import +from __future__ import division import argparse import glob diff --git a/sdks/python/apache_beam/examples/complete/tfidf_test.py b/sdks/python/apache_beam/examples/complete/tfidf_test.py index 637d10a0df6b..159407effc55 100644 --- a/sdks/python/apache_beam/examples/complete/tfidf_test.py +++ b/sdks/python/apache_beam/examples/complete/tfidf_test.py @@ -17,6 +17,8 @@ """Test for the TF-IDF example.""" +from __future__ import absolute_import + import logging import os import re diff --git a/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py b/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py index a0b368f60350..fcef981c9b6c 100644 --- a/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py +++ b/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py @@ -17,6 +17,8 @@ """Test for the top wikipedia sessions example.""" +from __future__ import absolute_import + import json import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/__init__.py b/sdks/python/apache_beam/examples/cookbook/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/cookbook/__init__.py +++ b/sdks/python/apache_beam/examples/cookbook/__init__.py @@ -14,3 +14,5 @@ # 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/examples/cookbook/bigquery_side_input.py b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py index 91ddf51827b3..e1494514262c 100644 --- a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py +++ b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py @@ -27,8 +27,11 @@ a word that should be ignored when forming groups. """ +from __future__ import absolute_import + import argparse import logging +from builtins import range from random import randrange import apache_beam as beam @@ -46,7 +49,7 @@ def attach_corpus_fn(group, corpus, ignore): selected = None len_corpus = len(corpus) while not selected: - c = corpus[randrange(0, len_corpus - 1)].values()[0] + c = list(corpus[randrange(0, len_corpus - 1)].values())[0] if c != ignore: selected = c @@ -56,7 +59,7 @@ def attach_word_fn(group, words, ignore): selected = None len_words = len(words) while not selected: - c = words[randrange(0, len_words - 1)].values()[0] + c = list(words[randrange(0, len_words - 1)].values())[0] if c != ignore: selected = c diff --git a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py index 964b35b3f08f..11fb95b055c1 100644 --- a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py +++ b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py @@ -17,6 +17,8 @@ """Test for the BigQuery side input example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py index 961284908046..b7e90839ffaa 100644 --- a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py +++ b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py @@ -17,9 +17,12 @@ """End-to-end test for Bigquery tornadoes example.""" +from __future__ import absolute_import + import logging import time import unittest +from builtins import round from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr diff --git a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py index 45dcabaf853c..cad34d814b35 100644 --- a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py +++ b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py @@ -17,6 +17,8 @@ """Test for the BigQuery tornadoes example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/coders.py b/sdks/python/apache_beam/examples/cookbook/coders.py index f97b0f2d9c9a..b0f2a2b65e1e 100644 --- a/sdks/python/apache_beam/examples/cookbook/coders.py +++ b/sdks/python/apache_beam/examples/cookbook/coders.py @@ -33,6 +33,7 @@ import argparse import json import logging +from builtins import object import apache_beam as beam from apache_beam.io import ReadFromText diff --git a/sdks/python/apache_beam/examples/cookbook/coders_test.py b/sdks/python/apache_beam/examples/cookbook/coders_test.py index 988d3c9d25e1..7a3b7f876793 100644 --- a/sdks/python/apache_beam/examples/cookbook/coders_test.py +++ b/sdks/python/apache_beam/examples/cookbook/coders_test.py @@ -17,6 +17,8 @@ """Test for the coders example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/combiners_test.py b/sdks/python/apache_beam/examples/cookbook/combiners_test.py index ee1fb7765d47..15714c0051e7 100644 --- a/sdks/python/apache_beam/examples/cookbook/combiners_test.py +++ b/sdks/python/apache_beam/examples/cookbook/combiners_test.py @@ -23,6 +23,8 @@ checked directly on the last PCollection produced. """ +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py b/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py index 7aaccb4ac1c0..7620dae30bdc 100644 --- a/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py +++ b/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py @@ -17,6 +17,8 @@ """Tests for the various custom Count implementation examples.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py index 8040ab142fd4..d09a46a14d52 100644 --- a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py +++ b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py @@ -67,12 +67,12 @@ import logging import re import uuid +from builtins import object from google.cloud.proto.datastore.v1 import entity_pb2 from google.cloud.proto.datastore.v1 import query_pb2 from googledatastore import helper as datastore_helper from googledatastore import PropertyFilter -import six import apache_beam as beam from apache_beam.io import ReadFromText @@ -83,6 +83,11 @@ from apache_beam.options.pipeline_options import PipelineOptions from apache_beam.options.pipeline_options import SetupOptions +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class WordExtractingDoFn(beam.DoFn): """Parse each line of input text into words.""" @@ -132,7 +137,7 @@ def make_entity(self, content): datastore_helper.add_key_path(entity.key, self._kind, self._ancestor, self._kind, str(uuid.uuid4())) - datastore_helper.add_properties(entity, {"content": six.text_type(content)}) + datastore_helper.add_properties(entity, {"content": unicode(content)}) return entity @@ -187,7 +192,7 @@ def count_ones(word_ones): counts = (lines | 'split' >> (beam.ParDo(WordExtractingDoFn()) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | 'group' >> beam.GroupByKey() | 'count' >> beam.Map(count_ones)) diff --git a/sdks/python/apache_beam/examples/cookbook/filters_test.py b/sdks/python/apache_beam/examples/cookbook/filters_test.py index fd49f938742c..5187a2feb933 100644 --- a/sdks/python/apache_beam/examples/cookbook/filters_test.py +++ b/sdks/python/apache_beam/examples/cookbook/filters_test.py @@ -17,6 +17,8 @@ """Test for the filters example.""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/group_with_coder.py b/sdks/python/apache_beam/examples/cookbook/group_with_coder.py index d5dbecff6bda..f9c378817627 100644 --- a/sdks/python/apache_beam/examples/cookbook/group_with_coder.py +++ b/sdks/python/apache_beam/examples/cookbook/group_with_coder.py @@ -30,6 +30,7 @@ import argparse import logging import sys +from builtins import object import apache_beam as beam from apache_beam import coders diff --git a/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py b/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py index ed38b5d8a4ed..522333e570e3 100644 --- a/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py +++ b/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py @@ -17,6 +17,8 @@ """Test for the custom coders example.""" +from __future__ import absolute_import + import logging import tempfile import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/mergecontacts.py b/sdks/python/apache_beam/examples/cookbook/mergecontacts.py index 237d4ca6efd7..79e7274663ef 100644 --- a/sdks/python/apache_beam/examples/cookbook/mergecontacts.py +++ b/sdks/python/apache_beam/examples/cookbook/mergecontacts.py @@ -34,6 +34,7 @@ import argparse import logging import re +from builtins import next import apache_beam as beam from apache_beam.io import ReadFromText diff --git a/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py b/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py index 32a3d518861f..8c7144bbfa76 100644 --- a/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py +++ b/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py @@ -17,6 +17,8 @@ """Test for the mergecontacts example.""" +from __future__ import absolute_import + import logging import tempfile import unittest diff --git a/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py b/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py index 1051106ea9b0..78e02e716027 100644 --- a/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py +++ b/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py @@ -17,6 +17,8 @@ """Test for the multiple_output_pardo example.""" +from __future__ import absolute_import + import logging import re import tempfile diff --git a/sdks/python/apache_beam/examples/hourly_team_score_it_test.py b/sdks/python/apache_beam/examples/hourly_team_score_it_test.py index ffea48e524e8..e46bf47e0be6 100644 --- a/sdks/python/apache_beam/examples/hourly_team_score_it_test.py +++ b/sdks/python/apache_beam/examples/hourly_team_score_it_test.py @@ -30,6 +30,8 @@ """ +from __future__ import absolute_import + import logging import time import unittest diff --git a/sdks/python/apache_beam/examples/leader_board_it_test.py b/sdks/python/apache_beam/examples/leader_board_it_test.py index 12c3972ef0f4..44297bda7bf0 100644 --- a/sdks/python/apache_beam/examples/leader_board_it_test.py +++ b/sdks/python/apache_beam/examples/leader_board_it_test.py @@ -30,10 +30,13 @@ """ +from __future__ import absolute_import + import logging import time import unittest import uuid +from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr @@ -95,7 +98,7 @@ def _inject_pubsub_game_events(self, topic, message_count): logging.debug('Injecting %d game events to topic %s', message_count, topic.full_name) - for _ in xrange(message_count): + for _ in range(message_count): topic.publish(self.INPUT_EVENT % self._test_timestamp) def _cleanup_pubsub(self): diff --git a/sdks/python/apache_beam/examples/snippets/__init__.py b/sdks/python/apache_beam/examples/snippets/__init__.py index cce3acad34a4..6569e3fe5de4 100644 --- a/sdks/python/apache_beam/examples/snippets/__init__.py +++ b/sdks/python/apache_beam/examples/snippets/__init__.py @@ -14,3 +14,5 @@ # 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/examples/snippets/snippets.py b/sdks/python/apache_beam/examples/snippets/snippets.py index 2e648209179b..161a67b037fe 100644 --- a/sdks/python/apache_beam/examples/snippets/snippets.py +++ b/sdks/python/apache_beam/examples/snippets/snippets.py @@ -29,10 +29,12 @@ prefix the PATH_TO_HTML where they are included followed by a descriptive string. The tags can contain only letters, digits and _. """ +from __future__ import absolute_import +from __future__ import division import argparse - -import six +from builtins import object +from builtins import range import apache_beam as beam from apache_beam.io import iobase @@ -53,6 +55,11 @@ # pylint:disable=unused-variable # pylint:disable=wrong-import-order, wrong-import-position +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class SnippetUtils(object): from apache_beam.pipeline import PipelineVisitor @@ -1048,7 +1055,7 @@ def to_entity(content): entity = entity_pb2.Entity() googledatastore.helper.add_key_path(entity.key, kind, str(uuid.uuid4())) googledatastore.helper.add_properties(entity, - {'content': six.text_type(content)}) + {'content': unicode(content)}) return entity entities = musicians | 'To Entity' >> beam.Map(to_entity) diff --git a/sdks/python/apache_beam/examples/snippets/snippets_test.py b/sdks/python/apache_beam/examples/snippets/snippets_test.py index b05b6c4a220d..b219609c037e 100644 --- a/sdks/python/apache_beam/examples/snippets/snippets_test.py +++ b/sdks/python/apache_beam/examples/snippets/snippets_test.py @@ -17,6 +17,8 @@ # """Tests for all code snippets used in public docs.""" +from __future__ import absolute_import +from __future__ import division import glob import gzip @@ -25,6 +27,10 @@ import tempfile import unittest import uuid +from builtins import map +from builtins import object +from builtins import range +from builtins import zip import mock diff --git a/sdks/python/apache_beam/examples/streaming_wordcount.py b/sdks/python/apache_beam/examples/streaming_wordcount.py index 6ee50bea5304..388f9e39b5b2 100644 --- a/sdks/python/apache_beam/examples/streaming_wordcount.py +++ b/sdks/python/apache_beam/examples/streaming_wordcount.py @@ -23,8 +23,6 @@ import argparse import logging -import six - import apache_beam as beam import apache_beam.transforms.window as window from apache_beam.examples.wordcount import WordExtractingDoFn @@ -32,6 +30,11 @@ from apache_beam.options.pipeline_options import SetupOptions from apache_beam.options.pipeline_options import StandardOptions +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + def run(argv=None): """Build and run the pipeline.""" @@ -72,7 +75,7 @@ def count_ones(word_ones): counts = (lines | 'split' >> (beam.ParDo(WordExtractingDoFn()) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | beam.WindowInto(window.FixedWindows(15, 0)) | 'group' >> beam.GroupByKey() diff --git a/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py b/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py index 30e438098b15..419e247e8ef8 100644 --- a/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py +++ b/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py @@ -38,8 +38,6 @@ import logging import re -import six - import apache_beam as beam import apache_beam.transforms.window as window from apache_beam.examples.wordcount import WordExtractingDoFn @@ -50,6 +48,11 @@ from apache_beam.testing.util import equal_to_per_window from apache_beam.transforms.core import ParDo +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class PrintFn(beam.DoFn): """A DoFn that prints label, element, its window, and its timstamp. """ @@ -119,7 +122,7 @@ def count_ones(word_ones): | 'AddTimestampFn' >> beam.ParDo(AddTimestampFn()) | 'After AddTimestampFn' >> ParDo(PrintFn('After AddTimestampFn')) | 'Split' >> (beam.ParDo(WordExtractingDoFn()) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'PairWithOne' >> beam.Map(lambda x: (x, 1)) | beam.WindowInto(window.FixedWindows(5, 0)) | 'GroupByKey' >> beam.GroupByKey() diff --git a/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py b/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py index 5db1878f34fd..3c0cfa93a2c3 100644 --- a/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py +++ b/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py @@ -17,9 +17,12 @@ """End-to-end test for the streaming wordcount example.""" +from __future__ import absolute_import + import logging import unittest import uuid +from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr diff --git a/sdks/python/apache_beam/examples/user_score_it_test.py b/sdks/python/apache_beam/examples/user_score_it_test.py index 7cd59e91a81f..1c754a92ff53 100644 --- a/sdks/python/apache_beam/examples/user_score_it_test.py +++ b/sdks/python/apache_beam/examples/user_score_it_test.py @@ -30,6 +30,8 @@ """ +from __future__ import absolute_import + import logging import unittest import uuid diff --git a/sdks/python/apache_beam/examples/windowed_wordcount.py b/sdks/python/apache_beam/examples/windowed_wordcount.py index 987b66040a76..b5c4fde7aa7c 100644 --- a/sdks/python/apache_beam/examples/windowed_wordcount.py +++ b/sdks/python/apache_beam/examples/windowed_wordcount.py @@ -26,11 +26,14 @@ import argparse import logging -import six - import apache_beam as beam import apache_beam.transforms.window as window +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + TABLE_SCHEMA = ('word:STRING, count:INTEGER, ' 'window_start:TIMESTAMP, window_end:TIMESTAMP') @@ -77,7 +80,7 @@ def count_ones(word_ones): transformed = (lines | 'Split' >> (beam.FlatMap(find_words) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'PairWithOne' >> beam.Map(lambda x: (x, 1)) | beam.WindowInto(window.FixedWindows(2*60, 0)) | 'Group' >> beam.GroupByKey() diff --git a/sdks/python/apache_beam/examples/wordcount.py b/sdks/python/apache_beam/examples/wordcount.py index a26ef8a9bc7d..3ba3b334188b 100644 --- a/sdks/python/apache_beam/examples/wordcount.py +++ b/sdks/python/apache_beam/examples/wordcount.py @@ -23,8 +23,6 @@ import logging import re -import six - import apache_beam as beam from apache_beam.io import ReadFromText from apache_beam.io import WriteToText @@ -33,6 +31,11 @@ from apache_beam.options.pipeline_options import PipelineOptions from apache_beam.options.pipeline_options import SetupOptions +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class WordExtractingDoFn(beam.DoFn): """Parse each line of input text into words.""" @@ -96,7 +99,7 @@ def count_ones(word_ones): counts = (lines | 'split' >> (beam.ParDo(WordExtractingDoFn()) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | 'group' >> beam.GroupByKey() | 'count' >> beam.Map(count_ones)) diff --git a/sdks/python/apache_beam/examples/wordcount_debugging.py b/sdks/python/apache_beam/examples/wordcount_debugging.py index 9fdcade7a263..5d932d54ec60 100644 --- a/sdks/python/apache_beam/examples/wordcount_debugging.py +++ b/sdks/python/apache_beam/examples/wordcount_debugging.py @@ -45,8 +45,6 @@ import logging import re -import six - import apache_beam as beam from apache_beam.io import ReadFromText from apache_beam.io import WriteToText @@ -56,6 +54,11 @@ from apache_beam.testing.util import assert_that from apache_beam.testing.util import equal_to +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class FilterTextFn(beam.DoFn): """A DoFn that filters for a specific key based on a regular expression.""" @@ -101,7 +104,7 @@ def count_ones(word_ones): return (pcoll | 'split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x)) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | 'group' >> beam.GroupByKey() | 'count' >> beam.Map(count_ones)) diff --git a/sdks/python/apache_beam/examples/wordcount_debugging_test.py b/sdks/python/apache_beam/examples/wordcount_debugging_test.py index 92ee2402ad65..513b72426eba 100644 --- a/sdks/python/apache_beam/examples/wordcount_debugging_test.py +++ b/sdks/python/apache_beam/examples/wordcount_debugging_test.py @@ -17,6 +17,8 @@ """Test for the debugging wordcount example.""" +from __future__ import absolute_import + import logging import re import tempfile diff --git a/sdks/python/apache_beam/examples/wordcount_fnapi.py b/sdks/python/apache_beam/examples/wordcount_fnapi.py index dce24517b115..00964c9ea46c 100644 --- a/sdks/python/apache_beam/examples/wordcount_fnapi.py +++ b/sdks/python/apache_beam/examples/wordcount_fnapi.py @@ -28,8 +28,6 @@ import logging import re -import six - import apache_beam as beam from apache_beam.io import ReadFromText # TODO(BEAM-2887): Enable after the issue is fixed. @@ -40,6 +38,11 @@ from apache_beam.options.pipeline_options import PipelineOptions from apache_beam.options.pipeline_options import SetupOptions +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + class WordExtractingDoFn(beam.DoFn): """Parse each line of input text into words.""" @@ -104,7 +107,7 @@ def run(argv=None): counts = (lines | 'split' >> (beam.ParDo(WordExtractingDoFn()) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | 'group_and_sum' >> beam.CombinePerKey(sum)) diff --git a/sdks/python/apache_beam/examples/wordcount_it_test.py b/sdks/python/apache_beam/examples/wordcount_it_test.py index fe42a4fa5f01..4c262746e362 100644 --- a/sdks/python/apache_beam/examples/wordcount_it_test.py +++ b/sdks/python/apache_beam/examples/wordcount_it_test.py @@ -17,6 +17,8 @@ """End-to-end test for the wordcount example.""" +from __future__ import absolute_import + import logging import time import unittest diff --git a/sdks/python/apache_beam/examples/wordcount_minimal.py b/sdks/python/apache_beam/examples/wordcount_minimal.py index 34abdb78a0dd..1fbca3279641 100644 --- a/sdks/python/apache_beam/examples/wordcount_minimal.py +++ b/sdks/python/apache_beam/examples/wordcount_minimal.py @@ -50,14 +50,17 @@ import logging import re -import six - import apache_beam as beam from apache_beam.io import ReadFromText from apache_beam.io import WriteToText from apache_beam.options.pipeline_options import PipelineOptions from apache_beam.options.pipeline_options import SetupOptions +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + def run(argv=None): """Main entry point; defines and runs the wordcount pipeline.""" @@ -103,7 +106,7 @@ def run(argv=None): counts = ( lines | 'Split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x)) - .with_output_types(six.text_type)) + .with_output_types(unicode)) | 'PairWithOne' >> beam.Map(lambda x: (x, 1)) | 'GroupAndSum' >> beam.CombinePerKey(sum)) diff --git a/sdks/python/apache_beam/examples/wordcount_minimal_test.py b/sdks/python/apache_beam/examples/wordcount_minimal_test.py index 5ee7b7803980..24ece493e090 100644 --- a/sdks/python/apache_beam/examples/wordcount_minimal_test.py +++ b/sdks/python/apache_beam/examples/wordcount_minimal_test.py @@ -17,6 +17,8 @@ """Test for the minimal wordcount example.""" +from __future__ import absolute_import + import collections import logging import re @@ -52,7 +54,7 @@ def test_basics(self): match = re.search(r'([a-z]+): ([0-9]+)', line) if match is not None: results.append((match.group(1), int(match.group(2)))) - self.assertEqual(sorted(results), sorted(expected_words.iteritems())) + self.assertEqual(sorted(results), sorted(expected_words.items())) if __name__ == '__main__': diff --git a/sdks/python/apache_beam/examples/wordcount_test.py b/sdks/python/apache_beam/examples/wordcount_test.py index 9834ba53111a..58655dd33194 100644 --- a/sdks/python/apache_beam/examples/wordcount_test.py +++ b/sdks/python/apache_beam/examples/wordcount_test.py @@ -17,6 +17,8 @@ """Test for the wordcount example.""" +from __future__ import absolute_import + import collections import logging import re @@ -51,7 +53,7 @@ def test_basics(self): match = re.search(r'([a-z]+): ([0-9]+)', line) if match is not None: results.append((match.group(1), int(match.group(2)))) - self.assertEqual(sorted(results), sorted(expected_words.iteritems())) + self.assertEqual(sorted(results), sorted(expected_words.items())) if __name__ == '__main__': diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 14b6c8bad0de..c80cefd24cb0 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -100,6 +100,7 @@ deps = flake8==3.5.0 modules = apache_beam/coders + apache_beam/examples apache_beam/portability apache_beam/internal apache_beam/metrics