Skip to content

Commit

Permalink
chore(setup): try adding pep517 support and cython autocompile if pos…
Browse files Browse the repository at this point in the history
…sible
  • Loading branch information
CaselIT committed Mar 31, 2020
1 parent b437e5e commit bedc2fb
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 57 deletions.
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[build-system]
requires = [
"setuptools",
"wheel",
# Skip cython when using pypy
"cython; python_implementation == 'CPython'"
]
build-backend = "setuptools.build_meta"

[tool.towncrier]
package = "falcon"
package_dir = ""
Expand Down
179 changes: 122 additions & 57 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import glob
import importlib
import io
import os
from os import path
Expand All @@ -10,8 +9,12 @@

MYDIR = path.abspath(os.path.dirname(__file__))

VERSION = importlib.import_module('falcon.version')
VERSION = VERSION.__version__
with open(path.join(path.dirname(__file__), 'falcon', 'version.py')) as v_file:
VERSION = (
re.compile(r""".*__version__ = ["'](.*?)['"]""", re.S)
.match(v_file.read())
.group(1)
)

REQUIRES = []

Expand All @@ -30,7 +33,39 @@
except ImportError:
CYTHON = False

if CYTHON:

class BuildFailed(Exception):
pass


def getCythonOptions():
# from sqlalchemy setup.py
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
if sys.platform == 'win32':
# Work around issue https://github.com/pypa/setuptools/issues/1902
ext_errors += (IOError, TypeError)

class ve_build_ext(build_ext):
# This class allows Cython building to fail.

def run(self):
try:
super().run()
except DistutilsPlatformError:
raise BuildFailed()

def build_extension(self, ext):
try:
super().build_extension(ext)
except ext_errors as e:
raise BuildFailed() from e
except ValueError as e:
# this can happen on Windows 64 bit, see Python issue 7511
if "'path'" in str(e):
raise BuildFailed() from e
raise

def list_modules(dirname, pattern):
filenames = glob.glob(path.join(dirname, pattern))

Expand Down Expand Up @@ -89,11 +124,8 @@ def list_modules(dirname, pattern):
for ext_mod in ext_modules:
ext_mod.cython_directives = {'language_level': '3'}

cmdclass = {'build_ext': build_ext}

else:
cmdclass = {}
ext_modules = []
cmdclass = {'build_ext': ve_build_ext}
return cmdclass, ext_modules


def load_description():
Expand Down Expand Up @@ -131,51 +163,84 @@ def load_description():
return ''.join(description_lines)


setup(
name='falcon',
version=VERSION,
description='An unladen web framework for building APIs and app backends.',
long_description=load_description(),
long_description_content_type='text/x-rst',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Natural Language :: English',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Topic :: Internet :: WWW/HTTP :: WSGI',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Programming Language :: Python',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords='wsgi web api framework rest http cloud',
author='Kurt Griffiths',
author_email='mail@kgriffs.com',
url='https://falconframework.org',
license='Apache 2.0',
packages=find_packages(exclude=['tests']),
include_package_data=True,
zip_safe=False,
python_requires='>=3.5',
install_requires=REQUIRES,
cmdclass=cmdclass,
ext_modules=ext_modules,
tests_require=['testtools', 'requests', 'pyyaml', 'pytest', 'pytest-runner'],
entry_points={
'console_scripts': [
'falcon-bench = falcon.cmd.bench:main',
'falcon-inspect-app = falcon.cmd.inspect_app:main',
'falcon-print-routes = falcon.cmd.inspect_app:route_main',
]
}
)
def run_setup(CYTHON):
if CYTHON:
cmdclass, ext_modules = getCythonOptions()
else:
cmdclass, ext_modules = {}, []

setup(
name='falcon',
version=VERSION,
description='An unladen web framework for building APIs and app backends.',
long_description=load_description(),
long_description_content_type='text/x-rst',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Natural Language :: English',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Topic :: Internet :: WWW/HTTP :: WSGI',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Programming Language :: Python',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords='wsgi web api framework rest http cloud',
author='Kurt Griffiths',
author_email='mail@kgriffs.com',
url='https://falconframework.org',
license='Apache 2.0',
packages=find_packages(exclude=['tests']),
include_package_data=True,
zip_safe=False,
python_requires='>=3.5',
install_requires=REQUIRES,
cmdclass=cmdclass,
ext_modules=ext_modules,
tests_require=['testtools', 'requests', 'pyyaml', 'pytest', 'pytest-runner'],
entry_points={
'console_scripts': [
'falcon-bench = falcon.cmd.bench:main',
'falcon-inspect-app = falcon.cmd.inspect_app:main',
'falcon-print-routes = falcon.cmd.inspect_app:route_main',
]
}
)


def status_msgs(*msgs):
print('*' * 75, *msgs, '*' * 75, sep='\n')


if not CYTHON:
run_setup(False)
if not PYPY:
status_msgs('Cython compilation not supported in this environment')
else:
try:
run_setup(True)
except BuildFailed as exc:
status_msgs(
exc.__cause__,
'Cython compilation could not be compiled, speedups are not enabled.',
'Failure information, if any, is above.',
'Retrying the build without the C extension now.'
)

run_setup(False)

status_msgs(
'Cython compilation could not be compiled, speedups are not enabled.',
'Plain-Python build succeeded.'
)

0 comments on commit bedc2fb

Please sign in to comment.