Applying black formatting

- Fixing flake8 configuration to agree with black
- Adding black validation check to github actions
This commit is contained in:
Jacob Alexander
2021-10-01 11:00:22 -07:00
parent 5dade41aeb
commit 6e7fffd7de
51 changed files with 2536 additions and 1837 deletions

160
setup.py
View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
'''
"""
pycapnp distutils setup.py
'''
"""
import glob
import os
@@ -23,15 +23,15 @@ _this_dir = os.path.dirname(__file__)
MAJOR = 1
MINOR = 1
MICRO = 0
TAG = ''
VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, TAG)
TAG = ""
VERSION = "%d.%d.%d%s" % (MAJOR, MINOR, MICRO, TAG)
# Write version info
def write_version_py(filename=None):
'''
"""
Generate pycapnp version
'''
"""
cnt = """\
from .lib.capnp import _CAPNP_VERSION_MAJOR as LIBCAPNP_VERSION_MAJOR # noqa: F401
from .lib.capnp import _CAPNP_VERSION_MINOR as LIBCAPNP_VERSION_MINOR # noqa: F401
@@ -42,10 +42,9 @@ version = '%s'
short_version = '%s'
"""
if not filename:
filename = os.path.join(
os.path.dirname(__file__), 'capnp', 'version.py')
filename = os.path.join(os.path.dirname(__file__), "capnp", "version.py")
a = open(filename, 'w')
a = open(filename, "w")
try:
a.write(cnt % (VERSION, VERSION))
finally:
@@ -55,30 +54,31 @@ short_version = '%s'
write_version_py()
# Try to use README.md and CHANGELOG.md as description and changelog
with open('README.md', encoding='utf-8') as f:
with open("README.md", encoding="utf-8") as f:
long_description = f.read()
with open('CHANGELOG.md', encoding='utf-8') as f:
with open("CHANGELOG.md", encoding="utf-8") as f:
changelog = f.read()
changelog = '\nChangelog\n=============\n' + changelog
changelog = "\nChangelog\n=============\n" + changelog
long_description += changelog
class clean(_clean):
'''
"""
Clean command, invoked with `python setup.py clean`
'''
"""
def run(self):
_clean.run(self)
for x in [
os.path.join('capnp', 'lib', 'capnp.cpp'),
os.path.join('capnp', 'lib', 'capnp.h'),
os.path.join('capnp', 'version.py'),
'build',
'build32',
'build64',
'bundled'
] + glob.glob(os.path.join('capnp', '*.capnp')):
print('removing %s' % x)
os.path.join("capnp", "lib", "capnp.cpp"),
os.path.join("capnp", "lib", "capnp.h"),
os.path.join("capnp", "version.py"),
"build",
"build32",
"build64",
"bundled",
] + glob.glob(os.path.join("capnp", "*.capnp")):
print("removing %s" % x)
try:
os.remove(x)
except OSError:
@@ -109,9 +109,10 @@ from Cython.Distutils import build_ext as build_ext_c # noqa: E402
class build_libcapnp_ext(build_ext_c):
'''
"""
Build capnproto library
'''
"""
def build_extension(self, ext):
build_ext_c.build_extension(self, ext)
@@ -126,12 +127,16 @@ class build_libcapnp_ext(build_ext_c):
if capnp_executable:
capnp_dir = os.path.dirname(capnp_executable)
self.include_dirs += [os.path.join(capnp_dir, "..", "include")]
self.library_dirs += [os.path.join(capnp_dir, "..", "lib{}".format(8 * struct.calcsize("P")))]
self.library_dirs += [
os.path.join(
capnp_dir, "..", "lib{}".format(8 * struct.calcsize("P"))
)
]
self.library_dirs += [os.path.join(capnp_dir, "..", "lib")]
# Look for capnproto using pkg-config (and minimum version)
try:
if pkgconfig.installed('capnp', '>= 0.8.0'):
if pkgconfig.installed("capnp", ">= 0.8.0"):
need_build = False
else:
need_build = True
@@ -149,14 +154,16 @@ class build_libcapnp_ext(build_ext_c):
bundle_dir = os.path.join(_this_dir, "bundled")
if not os.path.exists(bundle_dir):
os.mkdir(bundle_dir)
build_dir = os.path.join(_this_dir, "build{}".format(8 * struct.calcsize("P")))
build_dir = os.path.join(
_this_dir, "build{}".format(8 * struct.calcsize("P"))
)
if not os.path.exists(build_dir):
os.mkdir(build_dir)
# Check if we've already built capnproto
capnp_bin = os.path.join(build_dir, 'bin', 'capnp')
if os.name == 'nt':
capnp_bin = os.path.join(build_dir, 'bin', 'capnp.exe')
capnp_bin = os.path.join(build_dir, "bin", "capnp")
if os.name == "nt":
capnp_bin = os.path.join(build_dir, "bin", "capnp.exe")
if not os.path.exists(capnp_bin):
# Not built, fetch and build
@@ -165,12 +172,14 @@ class build_libcapnp_ext(build_ext_c):
else:
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")))]
self.library_dirs += [os.path.join(build_dir, 'lib')]
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")]
# Copy .capnp files from source
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")
for file in src_glob:
print("copying {} -> {}".format(file, dst_dir))
@@ -179,64 +188,71 @@ class build_libcapnp_ext(build_ext_c):
return build_ext_c.run(self)
extra_compile_args = ['--std=c++14']
extra_compile_args = ["--std=c++14"]
extra_link_args = []
if os.name == 'nt':
extra_compile_args = ['/std:c++14', '/MD']
extra_link_args = ['/MANIFEST']
if os.name == "nt":
extra_compile_args = ["/std:c++14", "/MD"]
extra_link_args = ["/MANIFEST"]
import Cython.Build # noqa: E402
import Cython # noqa: E402
extensions = [Extension(
'*', ['capnp/helpers/capabilityHelper.cpp', 'capnp/lib/*.pyx'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language='c++',
)]
extensions = [
Extension(
"*",
["capnp/helpers/capabilityHelper.cpp", "capnp/lib/*.pyx"],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language="c++",
)
]
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/*'
"capnp": [
"*.pxd",
"*.h",
"*.capnp",
"helpers/*.pxd",
"helpers/*.h",
"includes/*.pxd",
"lib/*.pxd",
"lib/*.py",
"lib/*.pyx",
"templates/*",
]
},
ext_modules=Cython.Build.cythonize(extensions),
cmdclass={
'clean': clean,
'build_ext': build_libcapnp_ext
},
cmdclass={"clean": clean, "build_ext": build_libcapnp_ext},
install_requires=[],
entry_points={
"console_scripts": ["capnpc-cython = capnp._gen:main"]
},
entry_points={"console_scripts": ["capnpc-cython = capnp._gen:main"]},
# PyPi info
description="A cython wrapping of the C++ Cap'n Proto library",
long_description=long_description,
long_description_content_type="text/markdown",
license='BSD',
license="BSD",
# (setup.py only supports 1 author...)
author="Jacob Alexander", # <- Current maintainer; Original author -> Jason Paryani
author_email="haata@kiibohd.com",
url='https://github.com/capnproto/pycapnp',
download_url='https://github.com/haata/pycapnp/archive/v%s.zip' % VERSION,
keywords=['capnp', 'capnproto', "Cap'n Proto", 'pycapnp'],
url="https://github.com/capnproto/pycapnp",
download_url="https://github.com/haata/pycapnp/archive/v%s.zip" % VERSION,
keywords=["capnp", "capnproto", "Cap'n Proto", "pycapnp"],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows :: Windows 10',
'Operating System :: POSIX',
'Programming Language :: C++',
'Programming Language :: Cython',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Communications'],
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows :: Windows 10",
"Operating System :: POSIX",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Communications",
],
)