mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 00:14:45 +01:00
Minor code cleanup
- Reducing linter errors - Removing old Python 2-only code (__future__ print)
This commit is contained in:
parent
255119b838
commit
49fd4854d8
22 changed files with 16 additions and 101 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import capnp
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import capnp
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
import addressbook_pb2 as addressbook
|
||||
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
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 schema_capnp
|
||||
import sys
|
||||
from jinja2 import Environment, PackageLoader
|
||||
import os
|
||||
|
||||
|
||||
def find_type(code, id):
|
||||
for node in code['nodes']:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
import capnp # noqa: F401
|
||||
|
||||
import addressbook_capnp
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import asyncio
|
||||
import socket
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import time
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import os
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import os
|
||||
|
|
|
@ -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__))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import capnp
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import capnp
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import threading
|
||||
import time
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import capnp
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
17
setup.py
17
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue