From f72f7abc29c4daa3aba06bc276dfa27d8998d9bb Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 3 Aug 2018 06:52:44 +0200 Subject: [PATCH 1/2] backport optional extension building for python 2.7 --- setup.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 41707c2..071895a 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,15 @@ try: from setuptools import setup, Extension + from setuptolls.command.build_ext import build_ext as base_build_ext except ImportError: from distutils.core import setup, Extension - + from distutils.command.build_ext import build_ext as base_build_ext import os import re +import sys +import logging # Get version without importing scandir because that will lock the # .pyd file (if scandir is already installed) so it can't be @@ -25,8 +28,18 @@ long_description = f.read() -# the extension is optional since in case of lack of c the api -# there is a ctypes fallback and a slow python fallback +class BuildExt(base_build_ext): + + # the extension is optional since in case of lack of c the api + # there is a ctypes fallback and a slow python fallback + + def build_extension(self, ext): + try: + base_build_ext.build_extension(self, ext) + except Exception: + exception = sys.exc_info()[0] + logging.warn("building the %s failed with %s", ext.name, exception) + extension = Extension('_scandir', ['_scandir.c'], optional=True) @@ -58,5 +71,5 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', - ] + ], cmdclass={'build_ext': BuildExt}, ) From 75ca98c48a248a4f55acf28fa27c40a867f425fa Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 3 Aug 2018 12:19:23 +0200 Subject: [PATCH 2/2] fix typo and add warning when setuptools import fails --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 071895a..5987c54 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,13 @@ try: from setuptools import setup, Extension - from setuptolls.command.build_ext import build_ext as base_build_ext + from setuptools.command.build_ext import build_ext as base_build_ext except ImportError: + import warnings + import sys + val = sys.exc_info()[1] + + warnings.warn("import of setuptools failed %r" % val) from distutils.core import setup, Extension from distutils.command.build_ext import build_ext as base_build_ext