From bffec2afa7b183a753a8b11506b206934cf74fd2 Mon Sep 17 00:00:00 2001 From: Dan Blanchard Date: Wed, 7 Oct 2020 15:26:51 -0400 Subject: [PATCH] pyupgrade goodness --- doc/source/conf.py | 13 ++++++------- .../chef/cookbooks/python/files/default/get-pip.py | 14 ++++---------- examples/redis/tools/pid_top.py | 2 -- setup.py | 2 +- streamparse/__init__.py | 2 +- streamparse/cli/common.py | 2 +- streamparse/cli/update_virtualenv.py | 2 +- streamparse/cli/visualize.py | 4 +--- streamparse/dsl/bolt.py | 4 ++-- streamparse/dsl/component.py | 4 ++-- streamparse/dsl/spout.py | 4 ++-- streamparse/util.py | 4 ++-- streamparse/version.py | 4 +--- test/streamparse/cli/test_run.py | 6 +----- test/streamparse/test_dsl.py | 8 ++++---- 15 files changed, 29 insertions(+), 46 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index c8f11658..809b5a7a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # streamparse documentation build configuration file, created by # sphinx-quickstart on Sun Jan 19 22:29:52 2014. @@ -50,8 +49,8 @@ master_doc = "index" # General information about the project. -project = u"streamparse" -copyright = u"2014-2017, Parsely" +project = "streamparse" +copyright = "2014-2020, Parsely" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -213,7 +212,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ("index", "streamparse.tex", u"streamparse Documentation", u"Parsely", "manual") + ("index", "streamparse.tex", "streamparse Documentation", "Parsely", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -241,7 +240,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [("index", "streamparse", u"streamparse Documentation", [u"Parsely"], 1)] +man_pages = [("index", "streamparse", "streamparse Documentation", ["Parsely"], 1)] # If true, show URL addresses after external links. # man_show_urls = False @@ -256,8 +255,8 @@ ( "index", "streamparse", - u"streamparse Documentation", - u"Parsely", + "streamparse Documentation", + "Parsely", "streamparse", "Run Python on real-time streams of data.", "Miscellaneous", diff --git a/examples/kafka-jvm/chef/cookbooks/python/files/default/get-pip.py b/examples/kafka-jvm/chef/cookbooks/python/files/default/get-pip.py index 3f5cbf94..03d697b1 100644 --- a/examples/kafka-jvm/chef/cookbooks/python/files/default/get-pip.py +++ b/examples/kafka-jvm/chef/cookbooks/python/files/default/get-pip.py @@ -21509,17 +21509,11 @@ def unpack(sources): if __name__ == "__main__": - if sys.version_info >= (3, 0): - exec("def do_exec(co, loc): exec(co, loc)\n") - import pickle + exec("def do_exec(co, loc): exec(co, loc)\n") + import pickle - sources = sources.encode("ascii") # ensure bytes - sources = pickle.loads(bz2.decompress(base64.decodebytes(sources))) - else: - import cPickle as pickle - - exec("def do_exec(co, loc): exec co in loc\n") - sources = pickle.loads(bz2.decompress(base64.decodestring(sources))) + sources = sources.encode("ascii") # ensure bytes + sources = pickle.loads(bz2.decompress(base64.decodebytes(sources))) try: temp_dir = unpack(sources) diff --git a/examples/redis/tools/pid_top.py b/examples/redis/tools/pid_top.py index e4e41346..b823a532 100644 --- a/examples/redis/tools/pid_top.py +++ b/examples/redis/tools/pid_top.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import psutil diff --git a/setup.py b/setup.py index 653d032c..38ef7286 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Copyright 2014-2019 Parsely, Inc. +Copyright 2014-2020 Parsely, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/streamparse/__init__.py b/streamparse/__init__.py index 48458bfb..85393b23 100644 --- a/streamparse/__init__.py +++ b/streamparse/__init__.py @@ -51,7 +51,7 @@ ] __license__ = """ -Copyright 2014-2019 Parsely, Inc. +Copyright 2014-2020 Parsely, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/streamparse/cli/common.py b/streamparse/cli/common.py index b0781114..35c2f776 100644 --- a/streamparse/cli/common.py +++ b/streamparse/cli/common.py @@ -30,7 +30,7 @@ def __init__( raise ValueError("nargs for store_dict actions must be > 0") if const is not None and nargs != "?": raise ValueError('nargs must be "?" to supply const') - super(_StoreDictAction, self).__init__( + super().__init__( option_strings=option_strings, dest=dest, nargs=nargs, diff --git a/streamparse/cli/update_virtualenv.py b/streamparse/cli/update_virtualenv.py index 7061ff30..e05bb5cd 100644 --- a/streamparse/cli/update_virtualenv.py +++ b/streamparse/cli/update_virtualenv.py @@ -123,7 +123,7 @@ def create_or_update_virtualenvs( # Check to ensure streamparse is in at least one requirements file found_streamparse = False for requirements_path in requirements_paths: - with open(requirements_path, "r") as fp: + with open(requirements_path) as fp: for line in fp: if "streamparse" in line: found_streamparse = True diff --git a/streamparse/cli/visualize.py b/streamparse/cli/visualize.py index 0aecd8e2..7424eac9 100644 --- a/streamparse/cli/visualize.py +++ b/streamparse/cli/visualize.py @@ -74,9 +74,7 @@ def to_graphviz(topology_class, node_attr=None, edge_attr=None, **kwargs): for stream_id, grouping in spec.inputs.items(): parent = stream_id.componentId outputs = all_specs[parent].common.streams[stream_id.streamId].output_fields - label = "Stream: {}\lFields: {}\lGrouping: {}\l".format( - stream_id.streamId, outputs, grouping - ) + label = fr"Stream: {stream_id.streamId}\lFields: {outputs}\lGrouping: {grouping}\l" sametail = f"{parent}-{stream_id.streamId}" if sametail not in sametail_nodes: g.node(sametail, shape="point", width="0") diff --git a/streamparse/dsl/bolt.py b/streamparse/dsl/bolt.py index c40f0996..e179b96b 100644 --- a/streamparse/dsl/bolt.py +++ b/streamparse/dsl/bolt.py @@ -18,7 +18,7 @@ def __init__( config=None, outputs=None, ): - super(ShellBoltSpec, self).__init__( + super().__init__( component_cls, name=name, inputs=inputs, @@ -43,7 +43,7 @@ def __init__( config=None, outputs=None, ): - super(JavaBoltSpec, self).__init__( + super().__init__( component_cls, name=name, serialized_java=serialized_java, diff --git a/streamparse/dsl/component.py b/streamparse/dsl/component.py index f7fb110a..63ae26a0 100644 --- a/streamparse/dsl/component.py +++ b/streamparse/dsl/component.py @@ -213,7 +213,7 @@ def __init__( config=None, outputs=None, ): - super(JavaComponentSpec, self).__init__( + super().__init__( component_cls, name=name, inputs=inputs, @@ -256,7 +256,7 @@ def __init__( config=None, outputs=None, ): - super(ShellComponentSpec, self).__init__( + super().__init__( component_cls, name=name, inputs=inputs, diff --git a/streamparse/dsl/spout.py b/streamparse/dsl/spout.py index 4de036d7..df539035 100644 --- a/streamparse/dsl/spout.py +++ b/streamparse/dsl/spout.py @@ -17,7 +17,7 @@ def __init__( config=None, outputs=None, ): - super(ShellSpoutSpec, self).__init__( + super().__init__( component_cls, name=name, par=par, @@ -40,7 +40,7 @@ def __init__( config=None, outputs=None, ): - super(JavaSpoutSpec, self).__init__( + super().__init__( component_cls, name=name, par=par, diff --git a/streamparse/util.py b/streamparse/util.py index 81eeae20..33b12d21 100644 --- a/streamparse/util.py +++ b/streamparse/util.py @@ -91,7 +91,7 @@ def ssh_tunnel(env_config, local_port=6627, remote_port=None, quiet=False): # Periodically check to see if the ssh command failed and returned a # value, then raise an Exception if ssh_proc.poll() is not None: - raise IOError( + raise OSError( f"Unable to open ssh tunnel via: \"{' '.join(ssh_cmd)}\"" ) time.sleep(0.2) @@ -212,7 +212,7 @@ def get_topology_definition(topology_name=None, config_file=None): "--name flags.".format(specs_dir=topology_path) ) topology_file = topology_files[0] - topology_name = re.sub(r"(^{}|\.py$)".format(topology_path), "", topology_file) + topology_name = re.sub(fr"(^{topology_path}|\.py$)", "", topology_file) else: topology_file = f"{os.path.join(topology_path, topology_name)}.py" if not os.path.exists(topology_file): diff --git a/streamparse/version.py b/streamparse/version.py index 3bebdb1b..4b574fc9 100644 --- a/streamparse/version.py +++ b/streamparse/version.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -# Copyright 2014-2019 Parsely, Inc. +# Copyright 2014-2020 Parsely, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/test/streamparse/cli/test_run.py b/test/streamparse/cli/test_run.py index 238a535f..90b1e480 100644 --- a/test/streamparse/cli/test_run.py +++ b/test/streamparse/cli/test_run.py @@ -1,13 +1,9 @@ import argparse import unittest +from unittest.mock import patch from nose.tools import ok_ -try: - from unittest.mock import patch -except ImportError: - from mock import patch - from streamparse.cli.run import main, subparser_hook diff --git a/test/streamparse/test_dsl.py b/test/streamparse/test_dsl.py index b34d3396..b3bebf78 100644 --- a/test/streamparse/test_dsl.py +++ b/test/streamparse/test_dsl.py @@ -408,7 +408,7 @@ class JavaWordCount(Topology): word_spout = WordSpout.spec(par=2) word_bolt = JavaBolt.spec( full_class_name="com.bar.foo.counter.WordCountBolt", - args_list=[u"foo", 1, b"\x09\x10", True, 3.14159], + args_list=["foo", 1, b"\x09\x10", True, 3.14159], inputs={word_spout: Grouping.fields("word")}, par=8, outputs=["word", "count"], @@ -421,7 +421,7 @@ class JavaWordCount(Topology): self.assertEqual( java_object.args_list, [ - JavaObjectArg(string_arg=u"foo"), + JavaObjectArg(string_arg="foo"), JavaObjectArg(long_arg=1), JavaObjectArg(binary_arg=b"\x09\x10"), JavaObjectArg(bool_arg=True), @@ -522,7 +522,7 @@ def test_java_spout_valid_arg_list(self): class JavaWordCount(Topology): word_spout = JavaSpout.spec( full_class_name="com.bar.foo.counter.WordSpout", - args_list=[u"foo", 1, b"\x09\x10", True, 3.14159], + args_list=["foo", 1, b"\x09\x10", True, 3.14159], par=8, outputs=["word"], ) @@ -535,7 +535,7 @@ class JavaWordCount(Topology): self.assertEqual( java_object.args_list, [ - JavaObjectArg(string_arg=u"foo"), + JavaObjectArg(string_arg="foo"), JavaObjectArg(long_arg=1), JavaObjectArg(binary_arg=b"\x09\x10"), JavaObjectArg(bool_arg=True),