Fixing flake8 warnings and errors
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude benchmark Excluding the benchmark directory (due to protobuf generated files) Also removing some Python2 specific code
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
Largely adapted from h5py
|
||||
"""
|
||||
# flake8: noqa F401 F403
|
||||
|
||||
from .msg import *
|
||||
from .config import *
|
||||
|
||||
@@ -5,6 +5,9 @@ import os
|
||||
import tempfile
|
||||
|
||||
def build_libcapnp(bundle_dir, build_dir, verbose=False):
|
||||
'''
|
||||
Build capnproto
|
||||
'''
|
||||
bundle_dir = os.path.abspath(bundle_dir)
|
||||
capnp_dir = os.path.join(bundle_dir, 'capnproto-c++')
|
||||
build_dir = os.path.abspath(build_dir)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
"""utilities for fetching build dependencies."""
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) PyZMQ Developers
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
#
|
||||
# This bundling code is largely adapted from pyzmq-static's get.sh by
|
||||
# Brandon Craig-Rhodes, which is itself BSD licensed.
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Adapted for use in pycapnp from pyzmq. See https://github.com/zeromq/pyzmq
|
||||
# for original project.
|
||||
@@ -17,7 +16,6 @@ import shutil
|
||||
import stat
|
||||
import sys
|
||||
import tarfile
|
||||
from glob import glob
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
try:
|
||||
@@ -27,27 +25,28 @@ except ImportError:
|
||||
# py3
|
||||
from urllib.request import urlopen
|
||||
|
||||
from .msg import fatal, debug, info, warn
|
||||
from .msg import fatal, info, warn
|
||||
|
||||
pjoin = os.path.join
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
bundled_version = (0,7,0)
|
||||
libcapnp = "capnproto-c++-%i.%i.%i.tar.gz" % (bundled_version)
|
||||
libcapnp_url = "https://capnproto.org/" + libcapnp
|
||||
bundled_version = (0, 7, 4)
|
||||
libcapnp_name = "capnproto-c++-%i.%i.%i.tar.gz" % (bundled_version)
|
||||
libcapnp_url = "https://capnproto.org/" + libcapnp_name
|
||||
|
||||
HERE = os.path.dirname(__file__)
|
||||
ROOT = os.path.dirname(HERE)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Utilities
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
def untgz(archive):
|
||||
"""Remove .tar.gz"""
|
||||
return archive.replace('.tar.gz', '')
|
||||
|
||||
def localpath(*args):
|
||||
@@ -69,9 +68,9 @@ def fetch_archive(savedir, url, fname, force=False):
|
||||
f.write(req.read())
|
||||
return dest
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# libcapnp
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
def fetch_libcapnp(savedir, url=None):
|
||||
"""download and extract libcapnp"""
|
||||
@@ -83,7 +82,7 @@ def fetch_libcapnp(savedir, url=None):
|
||||
if os.path.exists(dest):
|
||||
info("already have %s" % dest)
|
||||
return
|
||||
fname = fetch_archive(savedir, url, libcapnp)
|
||||
fname = fetch_archive(savedir, url, libcapnp_name)
|
||||
tf = tarfile.open(fname)
|
||||
with_version = pjoin(savedir, tf.firstmember.path)
|
||||
tf.extractall(savedir)
|
||||
@@ -120,7 +119,7 @@ def stage_platform_hpp(capnproot):
|
||||
p = Popen('./configure', cwd=capnproot, shell=True,
|
||||
stdout=PIPE, stderr=PIPE,
|
||||
)
|
||||
o,e = p.communicate()
|
||||
_, e = p.communicate()
|
||||
if p.returncode:
|
||||
warn("failed to configure libcapnp:\n%s" % e)
|
||||
if sys.platform == 'darwin':
|
||||
@@ -172,6 +171,6 @@ def copy_and_patch_libcapnp(capnp, libcapnp):
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
except OSError:
|
||||
fatal("install_name_tool not found, cannot patch libcapnp for bundling.")
|
||||
out,err = p.communicate()
|
||||
_, err = p.communicate()
|
||||
if p.returncode:
|
||||
fatal("Could not patch bundled libcapnp install_name: %s" % err, p.returncode)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Config functions"""
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) PyZMQ Developers
|
||||
#
|
||||
# This file is part of pyzmq, copied and adapted from h5py.
|
||||
@@ -9,23 +9,24 @@
|
||||
#
|
||||
# Distributed under the terms of the New BSD License. The full license is in
|
||||
# the file COPYING.BSD, distributed as part of this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
from .msg import debug, warn
|
||||
|
||||
try:
|
||||
from configparser import ConfigParser
|
||||
except:
|
||||
except Exception:
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
pjoin = os.path.join
|
||||
from .msg import debug, fatal, warn
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Utility functions (adapted from h5py: http://h5py.googlecode.com)
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
def load_config(name, base='conf'):
|
||||
@@ -130,9 +131,8 @@ def merge(into, d):
|
||||
else:
|
||||
into[key] = merge(into[key], d[key])
|
||||
return into
|
||||
elif isinstance(into, list):
|
||||
if isinstance(into, list):
|
||||
return into + d
|
||||
else:
|
||||
return d
|
||||
|
||||
def discover_settings(conf_base=None):
|
||||
|
||||
@@ -23,7 +23,7 @@ pjoin = os.path.join
|
||||
root = os.path.abspath(pjoin(os.path.dirname(__file__), os.path.pardir))
|
||||
|
||||
sys.path.insert(0, pjoin(root, 'zmq', 'utils'))
|
||||
from constant_names import all_names, no_prefix
|
||||
from constant_names import all_names, no_prefix # noqa: E402
|
||||
|
||||
ifndef_t = """#ifndef {0}
|
||||
#define {0} (_PYZMQ_UNDEFINED)
|
||||
@@ -79,5 +79,6 @@ def render_constants():
|
||||
generate_file("constants.pxi", constants_pyx, pjoin(root, 'zmq', 'backend', 'cython'))
|
||||
generate_file("zmq_constants.h", ifndefs, pjoin(root, 'zmq', 'utils'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
render_constants()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Detect zmq version"""
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) PyZMQ Developers
|
||||
#
|
||||
# This file is part of pyzmq, copied and adapted from h5py.
|
||||
@@ -9,7 +9,7 @@
|
||||
#
|
||||
# Distributed under the terms of the New BSD License. The full license is in
|
||||
# the file COPYING.BSD, distributed as part of this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
# Adapted for use in pycapnp from pyzmq. See https://github.com/zeromq/pyzmq
|
||||
# for original project.
|
||||
@@ -29,15 +29,15 @@ from .patch import patch_lib_paths
|
||||
|
||||
pjoin = os.path.join
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Utility functions (adapted from h5py: http://h5py.googlecode.com)
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
def test_compilation(cfile, compiler=None, **compiler_attrs):
|
||||
"""Test simple compilation with given settings"""
|
||||
cc = get_compiler(compiler, **compiler_attrs)
|
||||
|
||||
efile, ext = os.path.splitext(cfile)
|
||||
efile, _ = os.path.splitext(cfile)
|
||||
|
||||
cpreargs = lpreargs = []
|
||||
if sys.platform == 'darwin':
|
||||
@@ -65,6 +65,7 @@ def test_compilation(cfile, compiler=None, **compiler_attrs):
|
||||
return efile
|
||||
|
||||
def compile_and_run(basedir, src, compiler=None, **compiler_attrs):
|
||||
"""Compile and run"""
|
||||
if not os.path.exists(basedir):
|
||||
os.makedirs(basedir)
|
||||
cfile = pjoin(basedir, os.path.basename(src))
|
||||
@@ -161,8 +162,9 @@ def test_build():
|
||||
return detected
|
||||
|
||||
|
||||
def erase_dir(dir):
|
||||
def erase_dir(path):
|
||||
"""Erase directory"""
|
||||
try:
|
||||
shutil.rmtree(dir)
|
||||
shutil.rmtree(path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from distutils import ccompiler
|
||||
from distutils.sysconfig import customize_compiler
|
||||
@@ -14,13 +13,8 @@ from subprocess import Popen, PIPE
|
||||
pjoin = os.path.join
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
u = lambda x: x
|
||||
else:
|
||||
u = lambda x: x.decode('utf8', 'replace')
|
||||
|
||||
|
||||
def customize_mingw(cc):
|
||||
"""customize mingw"""
|
||||
# strip -mno-cygwin from mingw32 (Python Issue #12641)
|
||||
for cmd in [cc.compiler, cc.compiler_cxx, cc.compiler_so, cc.linker_exe, cc.linker_so]:
|
||||
if '-mno-cygwin' in cmd:
|
||||
@@ -55,11 +49,10 @@ def get_output_error(cmd):
|
||||
try:
|
||||
result = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
except IOError as e:
|
||||
return -1, u(''), u('Failed to run %r: %r' % (cmd, e))
|
||||
return -1, '', 'Failed to run %r: %r' % (cmd, e)
|
||||
so, se = result.communicate()
|
||||
# unicode:
|
||||
so = so.decode('utf8', 'replace')
|
||||
se = se.decode('utf8', 'replace')
|
||||
|
||||
return result.returncode, so, se
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Logging (adapted from h5py: http://h5py.googlecode.com)
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
@@ -22,18 +22,22 @@ else:
|
||||
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):
|
||||
logger.error("Fatal: " + msg)
|
||||
"""Fatal"""
|
||||
logger.error("Fatal: %s", msg)
|
||||
exit(code)
|
||||
|
||||
def warn(msg):
|
||||
logger.error("Warning: " + msg)
|
||||
"""Warning"""
|
||||
logger.error("Warning: %s", msg)
|
||||
|
||||
def line(c='*', width=48):
|
||||
"""Horizontal rule"""
|
||||
print(c * (width // len(c)))
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ LIB_PAT = re.compile(r"\s*(.*) \(compatibility version (\d+\.\d+\.\d+), "
|
||||
def _get_libs(fname):
|
||||
rc, so, se = get_output_error(['otool', '-L', fname])
|
||||
if rc:
|
||||
logging.error("otool -L %s failed: %r" % (fname, se))
|
||||
logging.error("otool -L %s failed: %r", fname, se)
|
||||
return
|
||||
for line in so.splitlines()[1:]:
|
||||
m = LIB_PAT.match(line)
|
||||
@@ -33,6 +33,7 @@ def _find_library(lib, path):
|
||||
real_lib = os.path.join(d, lib)
|
||||
if os.path.exists(real_lib):
|
||||
return real_lib
|
||||
return None
|
||||
|
||||
def _install_name_change(fname, lib, real_lib):
|
||||
rc, so, se = get_output_error(['install_name_tool', '-change', lib, real_lib, fname])
|
||||
|
||||
@@ -31,8 +31,26 @@ Example Usage::
|
||||
for phone in person.phones:
|
||||
print(phone.type, ':', phone.number)
|
||||
"""
|
||||
# flake8: noqa F401 F403 F405
|
||||
from .version import version as __version__
|
||||
from .lib.capnp import *
|
||||
from .lib.capnp import _DynamicStructReader, _DynamicStructBuilder, _DynamicResizableListBuilder, _DynamicListReader, _DynamicListBuilder, _DynamicOrphan, _DynamicResizableListBuilder, _MallocMessageBuilder, _PackedFdMessageReader, _StreamFdMessageReader, _write_message_to_fd, _write_packed_message_to_fd, _StructModule, _InterfaceModule, _DynamicCapabilityClient, _CapabilityClient, _EventLoop
|
||||
from .lib.capnp import (
|
||||
_CapabilityClient,
|
||||
_DynamicCapabilityClient,
|
||||
_DynamicListBuilder,
|
||||
_DynamicListReader,
|
||||
_DynamicOrphan,
|
||||
_DynamicResizableListBuilder,
|
||||
_DynamicStructBuilder,
|
||||
_DynamicStructReader,
|
||||
_EventLoop,
|
||||
_InterfaceModule,
|
||||
_MallocMessageBuilder,
|
||||
_PackedFdMessageReader,
|
||||
_StreamFdMessageReader,
|
||||
_StructModule,
|
||||
_write_message_to_fd,
|
||||
_write_packed_message_to_fd,
|
||||
)
|
||||
|
||||
add_import_hook() # enable import hook by default
|
||||
|
||||
12
docs/conf.py
12
docs/conf.py
@@ -1,3 +1,6 @@
|
||||
'''
|
||||
Docs configuration
|
||||
'''
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# capnp documentation build configuration file, created by
|
||||
@@ -11,7 +14,9 @@
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os, string
|
||||
import string
|
||||
# import sys, os
|
||||
import capnp
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
@@ -48,11 +53,10 @@ copyright = u'2013, Author'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
import capnp
|
||||
|
||||
vs = capnp.__version__
|
||||
# The short X.Y version.
|
||||
version = vs.rstrip(string.letters)
|
||||
version = vs.rstrip(string.ascii_letters)
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = vs
|
||||
|
||||
@@ -173,7 +177,6 @@ htmlhelp_basename = 'capnpdoc'
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
@@ -182,6 +185,7 @@ latex_elements = {
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
# 'preamble': '',
|
||||
latex_elements = {
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import capnp
|
||||
import capnp # noqa: F401
|
||||
|
||||
import addressbook_capnp
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import print_function
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import threading
|
||||
import time
|
||||
import capnp
|
||||
import socket
|
||||
@@ -24,7 +23,6 @@ at the given address and does some RPCs')
|
||||
|
||||
|
||||
class StatusSubscriber(thread_capnp.Example.StatusSubscriber.Server):
|
||||
|
||||
'''An implementation of the StatusSubscriber interface'''
|
||||
|
||||
def status(self, value, **kwargs):
|
||||
@@ -60,7 +58,7 @@ async def main(host):
|
||||
reader, writer = await asyncio.open_connection(
|
||||
addr, port,
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
print("Try IPv6")
|
||||
reader, writer = await asyncio.open_connection(
|
||||
addr, port,
|
||||
|
||||
@@ -72,7 +72,7 @@ async def main():
|
||||
myserver,
|
||||
addr, port,
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
print("Try IPv6")
|
||||
server = await asyncio.start_server(
|
||||
myserver,
|
||||
@@ -83,5 +83,6 @@ async def main():
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import print_function
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import threading
|
||||
import time
|
||||
import capnp
|
||||
import socket
|
||||
@@ -25,7 +24,6 @@ at the given address and does some RPCs')
|
||||
|
||||
|
||||
class StatusSubscriber(thread_capnp.Example.StatusSubscriber.Server):
|
||||
|
||||
'''An implementation of the StatusSubscriber interface'''
|
||||
|
||||
def status(self, value, **kwargs):
|
||||
@@ -66,7 +64,7 @@ async def main(host):
|
||||
addr, port,
|
||||
ssl=ctx,
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
print("Try IPv6")
|
||||
reader, writer = await asyncio.open_connection(
|
||||
addr, port,
|
||||
|
||||
@@ -78,7 +78,7 @@ async def main():
|
||||
addr, port,
|
||||
ssl=ctx,
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
print("Try IPv6")
|
||||
server = await asyncio.start_server(
|
||||
myserver,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import socket
|
||||
import capnp
|
||||
|
||||
import calculator_capnp
|
||||
@@ -302,5 +301,6 @@ def main(host):
|
||||
|
||||
print("PASS")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(parse_args().host)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import socket
|
||||
import random
|
||||
import capnp
|
||||
|
||||
import calculator_capnp
|
||||
@@ -136,5 +134,6 @@ def main():
|
||||
server = capnp.TwoPartyServer(address, bootstrap=CalculatorImpl())
|
||||
server.run_forever()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -54,5 +54,6 @@ def main(host):
|
||||
cap.longRunning().wait()
|
||||
print('main: {}'.format(time.time()))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(parse_args().host)
|
||||
|
||||
@@ -37,5 +37,6 @@ def main():
|
||||
server = capnp.TwoPartyServer(address, bootstrap=ExampleImpl())
|
||||
server.run_forever()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -41,4 +41,5 @@ def main():
|
||||
|
||||
globals()[command](**kwargs) # hacky way to get defined functions, and call function with name=command
|
||||
|
||||
|
||||
main()
|
||||
@@ -1,12 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import capnp
|
||||
import os
|
||||
import sys
|
||||
|
||||
import capnp
|
||||
capnp.add_import_hook([os.getcwd(), "/usr/local/include/"]) # change this to be auto-detected?
|
||||
|
||||
import test_capnp
|
||||
import test_capnp # noqa: E402
|
||||
|
||||
import sys
|
||||
|
||||
def decode(name):
|
||||
class_name = name[0].upper() + name[1:]
|
||||
@@ -18,6 +19,7 @@ def encode(name):
|
||||
message = getattr(test_capnp, class_name).from_dict(val.to_dict())
|
||||
print(message.to_bytes())
|
||||
|
||||
|
||||
if sys.argv[1] == 'decode':
|
||||
decode(sys.argv[2])
|
||||
else:
|
||||
|
||||
56
setup.py
56
setup.py
@@ -1,15 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
pycapnp distutils setup.py
|
||||
'''
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
use_cython = False
|
||||
|
||||
from setuptools import setup
|
||||
import os
|
||||
import sys
|
||||
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
||||
|
||||
from distutils.command.clean import clean as _clean
|
||||
from distutils.errors import CompileError
|
||||
from distutils.extension import Extension
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
||||
|
||||
use_cython = False
|
||||
|
||||
_this_dir = os.path.dirname(__file__)
|
||||
|
||||
MAJOR = 0
|
||||
@@ -20,10 +28,14 @@ VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
||||
|
||||
# Write version info
|
||||
def write_version_py(filename=None):
|
||||
'''
|
||||
Generate pycapnp version
|
||||
'''
|
||||
cnt = """\
|
||||
version = '%s'
|
||||
short_version = '%s'
|
||||
|
||||
# flake8: noqa E402 F401
|
||||
from .lib.capnp import _CAPNP_VERSION_MAJOR as LIBCAPNP_VERSION_MAJOR
|
||||
from .lib.capnp import _CAPNP_VERSION_MINOR as LIBCAPNP_VERSION_MINOR
|
||||
from .lib.capnp import _CAPNP_VERSION_MICRO as LIBCAPNP_VERSION_MICRO
|
||||
@@ -39,6 +51,7 @@ from .lib.capnp import _CAPNP_VERSION as LIBCAPNP_VERSION
|
||||
finally:
|
||||
a.close()
|
||||
|
||||
|
||||
write_version_py()
|
||||
|
||||
# Try to convert README using pandoc
|
||||
@@ -49,13 +62,14 @@ try:
|
||||
changelog = '\nChangelog\n=============\n' + changelog
|
||||
long_description += changelog
|
||||
except (IOError, ImportError):
|
||||
if len(sys.argv) and sys.argv[-1] == 'sdist':
|
||||
if sys.argv and sys.argv[-1] == 'sdist':
|
||||
raise
|
||||
long_description = ''
|
||||
|
||||
# Clean command, invoked with `python setup.py clean`
|
||||
from distutils.command.clean import clean as _clean
|
||||
class clean(_clean):
|
||||
'''
|
||||
Clean command, invoked with `python setup.py clean`
|
||||
'''
|
||||
def run(self):
|
||||
_clean.run(self)
|
||||
for x in [ 'capnp/lib/capnp.cpp', 'capnp/lib/capnp.h', 'capnp/version.py' ]:
|
||||
@@ -65,6 +79,7 @@ class clean(_clean):
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
# set use_cython if lib/capnp.cpp is not detected
|
||||
capnp_compiled_file = os.path.join(os.path.dirname(__file__), 'capnp', 'lib', 'capnp.cpp')
|
||||
if not os.path.isfile(capnp_compiled_file):
|
||||
@@ -87,7 +102,7 @@ try:
|
||||
libcapnp_url = sys.argv[libcapnp_url_index + 1]
|
||||
sys.argv.remove("--libcapnp-url")
|
||||
sys.argv.remove(libcapnp_url)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if use_cython:
|
||||
@@ -96,6 +111,9 @@ else:
|
||||
from distutils.command.build_ext import build_ext as build_ext_c
|
||||
|
||||
class build_libcapnp_ext(build_ext_c):
|
||||
'''
|
||||
Build capnproto library
|
||||
'''
|
||||
def build_extension(self, ext):
|
||||
build_ext_c.build_extension(self, ext)
|
||||
|
||||
@@ -114,7 +132,12 @@ class build_libcapnp_ext(build_ext_c):
|
||||
need_build = True
|
||||
|
||||
if need_build:
|
||||
info("*WARNING* no libcapnp detected or rebuild forced. Will download and 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.")
|
||||
info(
|
||||
"*WARNING* no libcapnp detected or rebuild forced. "
|
||||
"Will download and 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."
|
||||
)
|
||||
bundle_dir = os.path.join(_this_dir, "bundled")
|
||||
if not os.path.exists(bundle_dir):
|
||||
os.mkdir(bundle_dir)
|
||||
@@ -130,9 +153,10 @@ class build_libcapnp_ext(build_ext_c):
|
||||
|
||||
return build_ext_c.run(self)
|
||||
|
||||
|
||||
if use_cython:
|
||||
from Cython.Build import cythonize
|
||||
import Cython
|
||||
import Cython # noqa: F401
|
||||
extensions = cythonize('capnp/lib/*.pyx')
|
||||
else:
|
||||
extensions = [Extension("capnp.lib.capnp", ["capnp/lib/capnp.cpp"],
|
||||
@@ -145,7 +169,12 @@ setup(
|
||||
name="pycapnp",
|
||||
packages=["capnp"],
|
||||
version=VERSION,
|
||||
package_data={'capnp': ['*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h', 'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*']},
|
||||
package_data={
|
||||
'capnp': [
|
||||
'*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h',
|
||||
'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*'
|
||||
]
|
||||
},
|
||||
ext_modules=extensions,
|
||||
cmdclass={
|
||||
'clean': clean,
|
||||
@@ -172,12 +201,9 @@ setup(
|
||||
'Operating System :: POSIX',
|
||||
'Programming Language :: C++',
|
||||
'Programming Language :: Cython',
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
'Programming Language :: Python :: Implementation :: PyPy',
|
||||
'Topic :: Communications'],
|
||||
)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import time
|
||||
|
||||
import capnp
|
||||
import test_capability_capnp as capability
|
||||
|
||||
class Server(capability.TestInterface.Server):
|
||||
@@ -160,6 +159,7 @@ class BadPipelineServer(capability.TestPipeline.Server):
|
||||
_results = _context.results
|
||||
_results.s = response.x + '_foo'
|
||||
_results.outBox.cap = Server(100)
|
||||
|
||||
def _error(error):
|
||||
raise Exception('test was a success')
|
||||
|
||||
@@ -186,7 +186,7 @@ def test_pipeline_exception():
|
||||
pipelinePromise = outCap.foo(i=10)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
loop.wait(pipelinePromise)
|
||||
pipelinePromise.wait()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
remote.wait()
|
||||
@@ -194,7 +194,7 @@ def test_pipeline_exception():
|
||||
def test_casting():
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
client3 = client2.cast_as(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
client.upcast(capability.TestPipeline)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import pytest
|
||||
|
||||
import capnp
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
@@ -150,6 +151,7 @@ class BadPipelineServer:
|
||||
def _then(response):
|
||||
context.results.s = response.x + '_foo'
|
||||
context.results.outBox.cap = capability().TestInterface._new_server(Server(100))
|
||||
|
||||
def _error(error):
|
||||
raise Exception('test was a success')
|
||||
|
||||
@@ -176,7 +178,7 @@ def test_pipeline_exception_context(capability):
|
||||
pipelinePromise = outCap.foo(i=10)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
loop.wait(pipelinePromise)
|
||||
pipelinePromise.wait()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
remote.wait()
|
||||
@@ -184,7 +186,7 @@ def test_pipeline_exception_context(capability):
|
||||
def test_casting_context(capability):
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
client3 = client2.cast_as(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
client.upcast(capability.TestPipeline)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import pytest
|
||||
|
||||
import capnp
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
@@ -154,6 +155,7 @@ class BadPipelineServer:
|
||||
_results = _context.results
|
||||
_results.s = response.x + '_foo'
|
||||
_results.outBox.cap = capability().TestInterface._new_server(Server(100))
|
||||
|
||||
def _error(error):
|
||||
raise Exception('test was a success')
|
||||
|
||||
@@ -180,7 +182,7 @@ def test_pipeline_exception(capability):
|
||||
pipelinePromise = outCap.foo(i=10)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
loop.wait(pipelinePromise)
|
||||
pipelinePromise.wait()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
remote.wait()
|
||||
@@ -188,7 +190,7 @@ def test_pipeline_exception(capability):
|
||||
def test_casting(capability):
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
client3 = client2.cast_as(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
client.upcast(capability.TestPipeline)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import pytest
|
||||
import platform
|
||||
import capnp
|
||||
import os
|
||||
import platform
|
||||
import tempfile
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
import capnp
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
@@ -81,19 +82,3 @@ def test_large_read_mutltiple_bytes_memoryview(test_capnp):
|
||||
data = get_two_adjacent_messages(test_capnp) + b' '
|
||||
for m in test_capnp.Msg.read_multiple_bytes(memoryview(data)):
|
||||
pass
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 3, reason="Legacy buffer support only for python 2.7")
|
||||
def test_large_read_mutltiple_bytes_buffer(test_capnp):
|
||||
data = get_two_adjacent_messages(test_capnp)
|
||||
for m in test_capnp.Msg.read_multiple_bytes(buffer(data)):
|
||||
pass
|
||||
|
||||
with pytest.raises(capnp.KjException):
|
||||
data = get_two_adjacent_messages(test_capnp)[:-1]
|
||||
for m in test_capnp.Msg.read_multiple_bytes(buffer(data)):
|
||||
pass
|
||||
|
||||
with pytest.raises(capnp.KjException):
|
||||
data = get_two_adjacent_messages(test_capnp) + b' '
|
||||
for m in test_capnp.Msg.read_multiple_bytes(buffer(data)):
|
||||
pass
|
||||
|
||||
@@ -56,13 +56,13 @@ def test_failed_import():
|
||||
bar.foo = foo
|
||||
|
||||
def test_defualt_import_hook():
|
||||
import addressbook_capnp
|
||||
import addressbook_capnp # noqa: F401
|
||||
|
||||
def test_dash_import():
|
||||
import addressbook_with_dashes_capnp
|
||||
import addressbook_with_dashes_capnp # noqa: F401
|
||||
|
||||
def test_spaces_import():
|
||||
import addressbook_with_spaces_capnp
|
||||
import addressbook_with_spaces_capnp # noqa: F401
|
||||
|
||||
def test_add_import_hook():
|
||||
capnp.add_import_hook([this_dir])
|
||||
@@ -86,4 +86,4 @@ def test_remove_import_hook():
|
||||
del sys.modules['addressbook_capnp'] # hack to deal with it being imported already
|
||||
|
||||
with pytest.raises(ImportError):
|
||||
import addressbook_capnp
|
||||
import addressbook_capnp # noqa: F401
|
||||
|
||||
@@ -71,7 +71,7 @@ def test_addressbook_message_classes(addressbook):
|
||||
assert bobPhones[0].type == 'home'
|
||||
assert bobPhones[1].number == "555-7654"
|
||||
assert bobPhones[1].type == 'work'
|
||||
assert bob.employment.unemployed == None
|
||||
assert bob.employment.unemployed is None
|
||||
|
||||
f = open('example', 'w')
|
||||
writeAddressBook(f.fileno())
|
||||
@@ -130,7 +130,7 @@ def test_addressbook(addressbook):
|
||||
assert bobPhones[0].type == 'home'
|
||||
assert bobPhones[1].number == "555-7654"
|
||||
assert bobPhones[1].type == 'work'
|
||||
assert bob.employment.unemployed == None
|
||||
assert bob.employment.unemployed is None
|
||||
|
||||
|
||||
f = open('example', 'w')
|
||||
@@ -192,7 +192,7 @@ def test_addressbook_resizable(addressbook):
|
||||
assert bobPhones[0].type == 'home'
|
||||
assert bobPhones[1].number == "555-7654"
|
||||
assert bobPhones[1].type == 'work'
|
||||
assert bob.employment.unemployed == None
|
||||
assert bob.employment.unemployed is None
|
||||
|
||||
|
||||
f = open('example', 'w')
|
||||
@@ -262,7 +262,7 @@ def test_addressbook_explicit_fields(addressbook):
|
||||
assert bobPhones[1]._get_by_field(phone_fields['number']) == "555-7654"
|
||||
assert bobPhones[1]._get_by_field(phone_fields['type']) == 'work'
|
||||
employment = bob._get_by_field(person_fields['employment'])
|
||||
employment._get_by_field(addressbook.Person.Employment.schema.fields['unemployed']) == None
|
||||
employment._get_by_field(addressbook.Person.Employment.schema.fields['unemployed']) is None
|
||||
|
||||
|
||||
f = open('example', 'w')
|
||||
@@ -371,8 +371,8 @@ def check_list(reader, expected):
|
||||
assert reader[i] == v
|
||||
|
||||
def check_all_types(reader):
|
||||
assert reader.voidField == None
|
||||
assert reader.boolField == True
|
||||
assert reader.voidField is None
|
||||
assert reader.boolField
|
||||
assert reader.int8Field == -123
|
||||
assert reader.int16Field == -12345
|
||||
assert reader.int32Field == -12345678
|
||||
@@ -387,8 +387,8 @@ def check_all_types(reader):
|
||||
assert reader.dataField == b"bar"
|
||||
|
||||
subReader = reader.structField
|
||||
assert subReader.voidField == None
|
||||
assert subReader.boolField == True
|
||||
assert subReader.voidField is None
|
||||
assert subReader.boolField
|
||||
assert subReader.int8Field == -12
|
||||
assert subReader.int16Field == 3456
|
||||
assert subReader.int32Field == -78901234
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import time
|
||||
|
||||
import test_response_capnp
|
||||
|
||||
class FooServer(test_response_capnp.Foo.Server):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import socket
|
||||
|
||||
import test_capability_capnp
|
||||
@@ -30,7 +29,7 @@ def test_simple_rpc():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
restorer = SimpleRestorer()
|
||||
server = capnp.TwoPartyServer(write, restorer)
|
||||
_ = capnp.TwoPartyServer(write, restorer)
|
||||
client = capnp.TwoPartyClient(read)
|
||||
|
||||
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
|
||||
@@ -47,7 +46,7 @@ def test_simple_rpc_with_options():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
restorer = SimpleRestorer()
|
||||
server = capnp.TwoPartyServer(write, restorer)
|
||||
_ = capnp.TwoPartyServer(write, restorer)
|
||||
# This traversal limit is too low to receive the response in, so we expect
|
||||
# an exception during the call.
|
||||
client = capnp.TwoPartyClient(read, traversal_limit_in_words=1)
|
||||
@@ -58,13 +57,13 @@ def test_simple_rpc_with_options():
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
with pytest.raises(capnp.KjException):
|
||||
response = remote.wait()
|
||||
_ = remote.wait()
|
||||
|
||||
|
||||
def test_simple_rpc_restore_func():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
server = capnp.TwoPartyServer(write, restore_func)
|
||||
_ = capnp.TwoPartyServer(write, restore_func)
|
||||
client = capnp.TwoPartyClient(read)
|
||||
|
||||
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
|
||||
@@ -86,7 +85,7 @@ def text_restore_func(objectId):
|
||||
def test_ez_rpc():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
server = capnp.TwoPartyServer(write, text_restore_func)
|
||||
_ = capnp.TwoPartyServer(write, text_restore_func)
|
||||
client = capnp.TwoPartyClient(read)
|
||||
|
||||
cap = client.ez_restore('testInterface')
|
||||
@@ -108,7 +107,7 @@ def test_ez_rpc():
|
||||
def test_simple_rpc_bootstrap():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
server = capnp.TwoPartyServer(write, bootstrap=Server(100))
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server(100))
|
||||
client = capnp.TwoPartyClient(read)
|
||||
|
||||
cap = client.bootstrap()
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import capnp
|
||||
import gc
|
||||
import os
|
||||
import socket
|
||||
import gc
|
||||
import subprocess
|
||||
import sys # add examples dir to sys.path
|
||||
import time
|
||||
|
||||
import sys # add examples dir to sys.path
|
||||
import capnp
|
||||
|
||||
examples_dir = os.path.join(os.path.dirname(__file__), '..', 'examples')
|
||||
sys.path.append(examples_dir)
|
||||
import calculator_client
|
||||
import calculator_server
|
||||
|
||||
import calculator_client # noqa: E402
|
||||
import calculator_server # noqa: E402
|
||||
|
||||
|
||||
def test_calculator():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
server = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
calculator_client.main(read)
|
||||
|
||||
|
||||
@@ -57,7 +59,7 @@ def test_calculator_gc():
|
||||
evaluate_impl_orig = calculator_server.evaluate_impl
|
||||
calculator_server.evaluate_impl = new_evaluate_impl(evaluate_impl_orig)
|
||||
|
||||
server = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
calculator_client.main(read)
|
||||
|
||||
calculator_server.evaluate_impl = evaluate_impl_orig
|
||||
|
||||
@@ -42,7 +42,10 @@ def test_roundtrip_bytes(all_types):
|
||||
msg = all_types.TestAllTypes.from_bytes(message_bytes)
|
||||
test_regression.check_all_types(msg)
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="TODO: Investigate why this works on CPython but fails on PyPy.")
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="TODO: Investigate why this works on CPython but fails on PyPy."
|
||||
)
|
||||
def test_roundtrip_segments(all_types):
|
||||
msg = all_types.TestAllTypes.new_message()
|
||||
test_regression.init_all_types(msg)
|
||||
@@ -79,7 +82,10 @@ def test_roundtrip_bytes_fail(all_types):
|
||||
with pytest.raises(TypeError):
|
||||
all_types.TestAllTypes.from_bytes(42)
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="This works in PyPy 4.0.1 but travisci's version of PyPy has some bug that fails this test.")
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="This works in PyPy 4.0.1 but travisci's version of PyPy has some bug that fails this test."
|
||||
)
|
||||
def test_roundtrip_bytes_packed(all_types):
|
||||
msg = all_types.TestAllTypes.new_message()
|
||||
test_regression.init_all_types(msg)
|
||||
@@ -146,7 +152,10 @@ def test_roundtrip_bytes_multiple_packed(all_types):
|
||||
i += 1
|
||||
assert i == 3
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="This works on my local PyPy v2.5.0, but is for some reason broken on TravisCI. Skip for now.")
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="This works on my local PyPy v2.5.0, but is for some reason broken on TravisCI. Skip for now."
|
||||
)
|
||||
def test_roundtrip_dict(all_types):
|
||||
msg = all_types.TestAllTypes.new_message()
|
||||
test_regression.init_all_types(msg)
|
||||
|
||||
@@ -77,7 +77,10 @@ def test_which_reader(addressbook):
|
||||
addresses.which
|
||||
|
||||
|
||||
@pytest.mark.skipif(capnp.version.LIBCAPNP_VERSION < 5000, reason="Using ints as enums requires v0.5.0+ of the C++ capnp library")
|
||||
@pytest.mark.skipif(
|
||||
capnp.version.LIBCAPNP_VERSION < 5000,
|
||||
reason="Using ints as enums requires v0.5.0+ of the C++ capnp library"
|
||||
)
|
||||
def test_enum(addressbook):
|
||||
addresses = addressbook.AddressBook.new_message()
|
||||
people = addresses.init('people', 2)
|
||||
@@ -188,11 +191,6 @@ def test_set_dict_union(addressbook):
|
||||
|
||||
assert person.employment.employer.name == 'foo'
|
||||
|
||||
try:
|
||||
basestring # attempt to evaluate basestring
|
||||
def isstr(s):
|
||||
return isinstance(s, basestring)
|
||||
except NameError:
|
||||
def isstr(s):
|
||||
return isinstance(s, str)
|
||||
|
||||
@@ -227,7 +225,12 @@ def test_to_dict_verbose(addressbook):
|
||||
|
||||
|
||||
def test_to_dict_ordered(addressbook):
|
||||
person = addressbook.Person.new_message(**{'name': 'Alice', 'phones': [{'type': 'mobile', 'number': '555-1212'}], 'id': 123, 'employment': {'school': 'MIT'}, 'email': 'alice@example.com'})
|
||||
person = addressbook.Person.new_message(**{
|
||||
'name': 'Alice',
|
||||
'phones': [{'type': 'mobile', 'number': '555-1212'}],
|
||||
'id': 123,
|
||||
'employment': {'school': 'MIT'}, 'email': 'alice@example.com'
|
||||
})
|
||||
|
||||
if sys.version_info >= (2, 7):
|
||||
assert list(person.to_dict(ordered=True).keys()) == ['id', 'name', 'email', 'phones', 'employment']
|
||||
|
||||
@@ -1,20 +1,38 @@
|
||||
import capnp
|
||||
import pytest
|
||||
import test_capability_capnp
|
||||
'''
|
||||
thread test
|
||||
'''
|
||||
|
||||
import platform
|
||||
import socket
|
||||
import threading
|
||||
import platform
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="pycapnp's GIL handling isn't working properly at the moment for PyPy")
|
||||
import pytest
|
||||
|
||||
import capnp
|
||||
import test_capability_capnp
|
||||
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="pycapnp's GIL handling isn't working properly at the moment for PyPy"
|
||||
)
|
||||
def test_making_event_loop():
|
||||
'''
|
||||
Event loop test
|
||||
'''
|
||||
capnp.remove_event_loop(True)
|
||||
capnp.create_event_loop()
|
||||
|
||||
capnp.remove_event_loop()
|
||||
capnp.create_event_loop()
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="pycapnp's GIL handling isn't working properly at the moment for PyPy")
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="pycapnp's GIL handling isn't working properly at the moment for PyPy"
|
||||
)
|
||||
def test_making_threaded_event_loop():
|
||||
'''
|
||||
Threaded event loop test
|
||||
'''
|
||||
capnp.remove_event_loop(True)
|
||||
capnp.create_event_loop(True)
|
||||
|
||||
@@ -23,23 +41,40 @@ def test_making_threaded_event_loop():
|
||||
|
||||
|
||||
class Server(test_capability_capnp.TestInterface.Server):
|
||||
|
||||
'''
|
||||
Server
|
||||
'''
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, i, j, **kwargs):
|
||||
'''
|
||||
foo
|
||||
'''
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
|
||||
class SimpleRestorer(test_capability_capnp.TestSturdyRefObjectId.Restorer):
|
||||
'''
|
||||
SimpleRestorer
|
||||
'''
|
||||
|
||||
def restore(self, ref_id):
|
||||
'''
|
||||
Restore
|
||||
'''
|
||||
assert ref_id.tag == 'testInterface'
|
||||
return Server(100)
|
||||
|
||||
|
||||
@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="pycapnp's GIL handling isn't working properly at the moment for PyPy")
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="pycapnp's GIL handling isn't working properly at the moment for PyPy"
|
||||
)
|
||||
def test_using_threads():
|
||||
'''
|
||||
Thread test
|
||||
'''
|
||||
capnp.remove_event_loop(True)
|
||||
capnp.create_event_loop(True)
|
||||
|
||||
@@ -47,7 +82,7 @@ def test_using_threads():
|
||||
|
||||
def run_server():
|
||||
restorer = SimpleRestorer()
|
||||
server = capnp.TwoPartyServer(write, restorer)
|
||||
_ = capnp.TwoPartyServer(write, restorer)
|
||||
capnp.wait_forever()
|
||||
|
||||
server_thread = threading.Thread(target=run_server)
|
||||
|
||||
Reference in New Issue
Block a user