From 49fd4854d84430069a2f93226648e09308dc4e91 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 8 Jun 2020 23:51:07 -0700 Subject: [PATCH] Minor code cleanup - Reducing linter errors - Removing old Python 2-only code (__future__ print) --- README.md | 1 - benchmark/addressbook.capnp.orphan.py | 1 - benchmark/addressbook.capnp.py | 1 - benchmark/addressbook.proto.py | 1 - buildutils/__init__.py | 9 ----- buildutils/bundle.py | 7 ++-- buildutils/msg.py | 48 ----------------------- capnp/_gen.py | 9 ++--- examples/addressbook.py | 1 - examples/async_calculator_client.py | 1 - examples/async_calculator_server.py | 2 - examples/async_client.py | 2 - examples/async_reconnecting_ssl_client.py | 2 - examples/async_server.py | 2 - examples/async_ssl_client.py | 2 - examples/async_ssl_server.py | 4 +- examples/calculator_client.py | 1 - examples/calculator_server.py | 1 - examples/thread_client.py | 2 - examples/thread_server.py | 2 - scripts/capnp_test_pycapnp.py | 1 - setup.py | 17 ++++---- 22 files changed, 16 insertions(+), 101 deletions(-) delete mode 100644 buildutils/msg.py diff --git a/README.md b/README.md index 0be9ffd..f4947b5 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,6 @@ Make sure to look at the [examples](examples). The examples are generally kept u The examples directory has one example that shows off pycapnp quite nicely. Here it is, reproduced: ```python -from __future__ import print_function import os import capnp diff --git a/benchmark/addressbook.capnp.orphan.py b/benchmark/addressbook.capnp.orphan.py index cc2c8f5..96ff855 100644 --- a/benchmark/addressbook.capnp.orphan.py +++ b/benchmark/addressbook.capnp.orphan.py @@ -1,4 +1,3 @@ -from __future__ import print_function import os import capnp diff --git a/benchmark/addressbook.capnp.py b/benchmark/addressbook.capnp.py index 69417bd..f32cb0d 100644 --- a/benchmark/addressbook.capnp.py +++ b/benchmark/addressbook.capnp.py @@ -1,4 +1,3 @@ -from __future__ import print_function import os import capnp diff --git a/benchmark/addressbook.proto.py b/benchmark/addressbook.proto.py index 517b44c..d410a08 100644 --- a/benchmark/addressbook.proto.py +++ b/benchmark/addressbook.proto.py @@ -1,4 +1,3 @@ -from __future__ import print_function import addressbook_pb2 as addressbook import os diff --git a/buildutils/__init__.py b/buildutils/__init__.py index 33130e5..e69de29 100644 --- a/buildutils/__init__.py +++ b/buildutils/__init__.py @@ -1,9 +0,0 @@ -"""utilities for building pyzmq. - -Largely adapted from h5py -""" -# flake8: noqa F401 F403 - -from .msg import * -from .bundle import * -from .build import * diff --git a/buildutils/bundle.py b/buildutils/bundle.py index ff628b2..a406ef9 100644 --- a/buildutils/bundle.py +++ b/buildutils/bundle.py @@ -17,7 +17,6 @@ import shutil import tarfile from urllib.request import urlopen -from .msg import info pjoin = os.path.join @@ -55,9 +54,9 @@ def fetch_archive(savedir, url, fname, force=False): """download an archive to a specific location""" dest = pjoin(savedir, fname) if os.path.exists(dest) and not force: - info("already have %s" % fname) + print("already have %s" % fname) return dest - info("fetching %s into %s" % (url, savedir)) + print("fetching %s into %s" % (url, savedir)) if not os.path.exists(savedir): os.makedirs(savedir) req = urlopen(url) @@ -79,7 +78,7 @@ def fetch_libcapnp(savedir, url=None): is_preconfigured = True dest = pjoin(savedir, 'capnproto-c++') if os.path.exists(dest): - info("already have %s" % dest) + print("already have %s" % dest) return fname = fetch_archive(savedir, url, libcapnp_name) tf = tarfile.open(fname) diff --git a/buildutils/msg.py b/buildutils/msg.py deleted file mode 100644 index 4ed56b1..0000000 --- a/buildutils/msg.py +++ /dev/null @@ -1,48 +0,0 @@ -"""logging""" - -# Copyright (c) PyZMQ Developers. -# Distributed under the terms of the Modified BSD License. - -from __future__ import division - -import os -import sys -import logging - -# -# Logging (adapted from h5py: http://h5py.googlecode.com) -# - - -logger = logging.getLogger() -if os.environ.get('DEBUG'): - logger.setLevel(logging.DEBUG) -else: - logger.setLevel(logging.INFO) -logger.addHandler(logging.StreamHandler(sys.stderr)) - - -def debug(msg): - """Debug""" - logger.debug(msg) - - -def info(msg): - """Info""" - logger.info(msg) - - -def fatal(msg, code=1): - """Fatal""" - logger.error("Fatal: %s", msg) - exit(code) - - -def warn(msg): - """Warning""" - logger.error("Warning: %s", msg) - - -def line(c='*', width=48): - """Horizontal rule""" - print(c * (width // len(c))) diff --git a/capnp/_gen.py b/capnp/_gen.py index aa66c70..5b551ef 100644 --- a/capnp/_gen.py +++ b/capnp/_gen.py @@ -1,11 +1,10 @@ -from __future__ import print_function +import os +import sys + +from jinja2 import Environment, PackageLoader import capnp import schema_capnp -import sys -from jinja2 import Environment, PackageLoader -import os - def find_type(code, id): for node in code['nodes']: diff --git a/examples/addressbook.py b/examples/addressbook.py index ae53185..e53e7c7 100755 --- a/examples/addressbook.py +++ b/examples/addressbook.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function import capnp # noqa: F401 import addressbook_capnp diff --git a/examples/async_calculator_client.py b/examples/async_calculator_client.py index f7f1f85..37a6e0a 100755 --- a/examples/async_calculator_client.py +++ b/examples/async_calculator_client.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function import argparse import asyncio import socket diff --git a/examples/async_calculator_server.py b/examples/async_calculator_server.py index 08ef9d4..b2d7ddc 100755 --- a/examples/async_calculator_server.py +++ b/examples/async_calculator_server.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import asyncio import logging diff --git a/examples/async_client.py b/examples/async_client.py index 147c33c..222a027 100755 --- a/examples/async_client.py +++ b/examples/async_client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import asyncio import argparse import time diff --git a/examples/async_reconnecting_ssl_client.py b/examples/async_reconnecting_ssl_client.py index 5c8f34b..466e7e0 100755 --- a/examples/async_reconnecting_ssl_client.py +++ b/examples/async_reconnecting_ssl_client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import asyncio import argparse import os diff --git a/examples/async_server.py b/examples/async_server.py index 323c70e..067226e 100755 --- a/examples/async_server.py +++ b/examples/async_server.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import asyncio import logging diff --git a/examples/async_ssl_client.py b/examples/async_ssl_client.py index ff5f011..548cac1 100755 --- a/examples/async_ssl_client.py +++ b/examples/async_ssl_client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import asyncio import argparse import os diff --git a/examples/async_ssl_server.py b/examples/async_ssl_server.py index 5292153..ad0f6b3 100755 --- a/examples/async_ssl_server.py +++ b/examples/async_ssl_server.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import asyncio import logging @@ -13,7 +11,7 @@ import capnp import thread_capnp -logger = logging.getLogger(__name__) +logger = logging.getLogger(__) logger.setLevel(logging.DEBUG) this_dir = os.path.dirname(os.path.abspath(__file__)) diff --git a/examples/calculator_client.py b/examples/calculator_client.py index 85694da..d0f3653 100755 --- a/examples/calculator_client.py +++ b/examples/calculator_client.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function import argparse import capnp diff --git a/examples/calculator_server.py b/examples/calculator_server.py index 38ca7ef..d57616f 100755 --- a/examples/calculator_server.py +++ b/examples/calculator_server.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function import argparse import capnp diff --git a/examples/thread_client.py b/examples/thread_client.py index 2d3d2ee..6e19870 100755 --- a/examples/thread_client.py +++ b/examples/thread_client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import threading import time diff --git a/examples/thread_server.py b/examples/thread_server.py index 6a2b52f..d0ff0db 100755 --- a/examples/thread_server.py +++ b/examples/thread_server.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import capnp diff --git a/scripts/capnp_test_pycapnp.py b/scripts/capnp_test_pycapnp.py index 6c40ccd..9b182d1 100755 --- a/scripts/capnp_test_pycapnp.py +++ b/scripts/capnp_test_pycapnp.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function import os import sys diff --git a/setup.py b/setup.py index 82b0169..30a8150 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,6 @@ pycapnp distutils setup.py ''' -from __future__ import print_function - import glob import os import shutil @@ -15,9 +13,10 @@ import pkgconfig from distutils.command.clean import clean as _clean -from setuptools import setup, find_packages, Extension +from setuptools import setup, Extension -from buildutils import fetch_libcapnp, build_libcapnp, info +from buildutils.build import build_libcapnp +from buildutils.bundle import fetch_libcapnp _this_dir = os.path.dirname(__file__) @@ -139,11 +138,11 @@ class build_libcapnp_ext(build_ext_c): need_build = True if need_build: - info( + print( "*WARNING* no libcapnp detected or rebuild forced. " - "Will download and build it from source now. " + "Attempting to build it from source now. " "If you have C++ Cap'n Proto installed, it may be out of date or is not being detected. " - "Downloading and building libcapnp may take a while." + "This may take a while..." ) bundle_dir = os.path.join(_this_dir, "bundled") if not os.path.exists(bundle_dir): @@ -162,7 +161,7 @@ class build_libcapnp_ext(build_ext_c): fetch_libcapnp(bundle_dir, libcapnp_url) build_libcapnp(bundle_dir, build_dir) else: - info("capnproto already built at {}".format(build_dir)) + print("capnproto already built at {}".format(build_dir)) self.include_dirs += [os.path.join(build_dir, 'include')] self.library_dirs += [os.path.join(build_dir, 'lib{}'.format(8 * struct.calcsize("P")))] @@ -172,7 +171,7 @@ class build_libcapnp_ext(build_ext_c): src_glob = glob.glob(os.path.join(build_dir, 'include', 'capnp', '*.capnp')) dst_dir = os.path.join(self.build_lib, "capnp") for file in src_glob: - info("copying {} -> {}".format(file, dst_dir)) + print("copying {} -> {}".format(file, dst_dir)) shutil.copy(file, dst_dir) return build_ext_c.run(self)