Minor code cleanup
- Reducing linter errors - Removing old Python 2-only code (__future__ print)
This commit is contained in:
@@ -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:
|
The examples directory has one example that shows off pycapnp quite nicely. Here it is, reproduced:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import addressbook_pb2 as addressbook
|
import addressbook_pb2 as addressbook
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -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 *
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import shutil
|
|||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from .msg import info
|
|
||||||
|
|
||||||
pjoin = os.path.join
|
pjoin = os.path.join
|
||||||
|
|
||||||
@@ -55,9 +54,9 @@ def fetch_archive(savedir, url, fname, force=False):
|
|||||||
"""download an archive to a specific location"""
|
"""download an archive to a specific location"""
|
||||||
dest = pjoin(savedir, fname)
|
dest = pjoin(savedir, fname)
|
||||||
if os.path.exists(dest) and not force:
|
if os.path.exists(dest) and not force:
|
||||||
info("already have %s" % fname)
|
print("already have %s" % fname)
|
||||||
return dest
|
return dest
|
||||||
info("fetching %s into %s" % (url, savedir))
|
print("fetching %s into %s" % (url, savedir))
|
||||||
if not os.path.exists(savedir):
|
if not os.path.exists(savedir):
|
||||||
os.makedirs(savedir)
|
os.makedirs(savedir)
|
||||||
req = urlopen(url)
|
req = urlopen(url)
|
||||||
@@ -79,7 +78,7 @@ def fetch_libcapnp(savedir, url=None):
|
|||||||
is_preconfigured = True
|
is_preconfigured = True
|
||||||
dest = pjoin(savedir, 'capnproto-c++')
|
dest = pjoin(savedir, 'capnproto-c++')
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
info("already have %s" % dest)
|
print("already have %s" % dest)
|
||||||
return
|
return
|
||||||
fname = fetch_archive(savedir, url, libcapnp_name)
|
fname = fetch_archive(savedir, url, libcapnp_name)
|
||||||
tf = tarfile.open(fname)
|
tf = tarfile.open(fname)
|
||||||
|
|||||||
@@ -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)))
|
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
from __future__ import print_function
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from jinja2 import Environment, PackageLoader
|
||||||
|
|
||||||
import capnp
|
import capnp
|
||||||
import schema_capnp
|
import schema_capnp
|
||||||
import sys
|
|
||||||
from jinja2 import Environment, PackageLoader
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def find_type(code, id):
|
def find_type(code, id):
|
||||||
for node in code['nodes']:
|
for node in code['nodes']:
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import capnp # noqa: F401
|
import capnp # noqa: F401
|
||||||
|
|
||||||
import addressbook_capnp
|
import addressbook_capnp
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
import socket
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
@@ -13,7 +11,7 @@ import capnp
|
|||||||
import thread_capnp
|
import thread_capnp
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
this_dir = os.path.dirname(os.path.abspath(__file__))
|
this_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import argparse
|
import argparse
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import argparse
|
import argparse
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import capnp
|
import capnp
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
17
setup.py
17
setup.py
@@ -3,8 +3,6 @@
|
|||||||
pycapnp distutils setup.py
|
pycapnp distutils setup.py
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@@ -15,9 +13,10 @@ import pkgconfig
|
|||||||
|
|
||||||
from distutils.command.clean import clean as _clean
|
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__)
|
_this_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
@@ -139,11 +138,11 @@ class build_libcapnp_ext(build_ext_c):
|
|||||||
need_build = True
|
need_build = True
|
||||||
|
|
||||||
if need_build:
|
if need_build:
|
||||||
info(
|
print(
|
||||||
"*WARNING* no libcapnp detected or rebuild forced. "
|
"*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. "
|
"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")
|
bundle_dir = os.path.join(_this_dir, "bundled")
|
||||||
if not os.path.exists(bundle_dir):
|
if not os.path.exists(bundle_dir):
|
||||||
@@ -162,7 +161,7 @@ class build_libcapnp_ext(build_ext_c):
|
|||||||
fetch_libcapnp(bundle_dir, libcapnp_url)
|
fetch_libcapnp(bundle_dir, libcapnp_url)
|
||||||
build_libcapnp(bundle_dir, build_dir)
|
build_libcapnp(bundle_dir, build_dir)
|
||||||
else:
|
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.include_dirs += [os.path.join(build_dir, 'include')]
|
||||||
self.library_dirs += [os.path.join(build_dir, 'lib{}'.format(8 * struct.calcsize("P")))]
|
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'))
|
src_glob = glob.glob(os.path.join(build_dir, 'include', 'capnp', '*.capnp'))
|
||||||
dst_dir = os.path.join(self.build_lib, "capnp")
|
dst_dir = os.path.join(self.build_lib, "capnp")
|
||||||
for file in src_glob:
|
for file in src_glob:
|
||||||
info("copying {} -> {}".format(file, dst_dir))
|
print("copying {} -> {}".format(file, dst_dir))
|
||||||
shutil.copy(file, dst_dir)
|
shutil.copy(file, dst_dir)
|
||||||
|
|
||||||
return build_ext_c.run(self)
|
return build_ext_c.run(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user