Python distutils.core.Extension() Examples
The following are 30
code examples of distutils.core.Extension().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
distutils.core
, or try the search function
.
Example #1
Source File: setupext.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def include_dirs_hook(): if hasattr(builtins, '__NUMPY_SETUP__'): del builtins.__NUMPY_SETUP__ import numpy importlib.reload(numpy) ext = Extension('test', []) # ext.include_dirs.append(numpy.get_include()) #iOS: ext.include_dirs.append('../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/') print("Include dirs found: ", numpy.get_include()) if not has_include_file( ext.include_dirs, os.path.join("numpy", "arrayobject.h")): warnings.warn( "The C headers for numpy could not be found. " "You may need to install the development package") #iOS: return ['../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/'] # return [numpy.get_include()]
Example #2
Source File: setupext.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def make_extension(name, files, *args, **kwargs): """ Make a new extension. Automatically sets include_dirs and library_dirs to the base directories appropriate for this platform. `name` is the name of the extension. `files` is a list of source files. Any additional arguments are passed to the `distutils.core.Extension` constructor. """ ext = DelayedExtension(name, files, *args, **kwargs) for dir in get_base_dirs(): include_dir = os.path.join(dir, 'include') if os.path.exists(include_dir): ext.include_dirs.append(include_dir) for lib in ('lib', 'lib64'): lib_dir = os.path.join(dir, lib) if os.path.exists(lib_dir): ext.library_dirs.append(lib_dir) ext.include_dirs.append('.') return ext
Example #3
Source File: configuration.py From efselab with GNU General Public License v3.0 | 6 votes |
def generate(self, run_cc=True, build_python=False, generate_c=True): filename = ('py'+self.name if build_python else self.name) + '.c' if generate_c: with open(filename, 'w') as f: print('Generating C code to %s...' % f.name, file=sys.stderr) self.c_emit(f, build_python) f.flush() if run_cc and not build_python: command = [self.cc] + self.cflags + [ '-I', os.path.realpath(os.path.dirname(sys.argv[0])), '-o', self.name, filename] print(' '.join(command), file=sys.stderr) subprocess.call(command) elif run_cc and build_python: from distutils.core import setup, Extension tagger = Extension( self.name, sources = [filename], libraries = [], extra_compile_args = self.cflags, extra_link_args = []) setup(name = self.name, ext_modules = [tagger], script_args = ['build_ext', '--inplace'])
Example #4
Source File: setuptools_ext.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not sys.flags.debug". (http://bugs.python.org/issue28401) """ if 'py_limited_api' not in kwds and not sys.flags.debug: import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #5
Source File: setuptools_ext.py From quickstart-git2s3 with Apache License 2.0 | 6 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) """ if 'py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #6
Source File: test_build_ext.py From Computable with MIT License | 6 votes |
def _fixup_command(self, cmd): # When Python was build with --enable-shared, -L. is not good enough # to find the libpython<blah>.so. This is because regrtest runs it # under a tempdir, not in the top level where the .so lives. By the # time we've gotten here, Python's already been chdir'd to the # tempdir. # # To further add to the fun, we can't just add library_dirs to the # Extension() instance because that doesn't get plumbed through to the # final compiler command. if (sysconfig.get_config_var('Py_ENABLE_SHARED') and not sys.platform.startswith('win')): runshared = sysconfig.get_config_var('RUNSHARED') if runshared is None: cmd.library_dirs = ['.'] else: name, equals, value = runshared.partition('=') cmd.library_dirs = value.split(os.pathsep)
Example #7
Source File: __init__.py From oss-ftp with MIT License | 6 votes |
def setUp(self): self.req = Require('Distutils','1.0.3','distutils') self.dist = makeSetup( features={ 'foo': Feature("foo",standard=True,require_features=['baz',self.req]), 'bar': Feature("bar", standard=True, packages=['pkg.bar'], py_modules=['bar_et'], remove=['bar.ext'], ), 'baz': Feature( "baz", optional=False, packages=['pkg.baz'], scripts = ['scripts/baz_it'], libraries=[('libfoo','foo/foofoo.c')] ), 'dwim': Feature("DWIM", available=False, remove='bazish'), }, script_args=['--without-bar', 'install'], packages = ['pkg.bar', 'pkg.foo'], py_modules = ['bar_et', 'bazish'], ext_modules = [Extension('bar.ext',['bar.c'])] )
Example #8
Source File: setup_package.py From astropy-healpix with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_extensions(): libraries = [] sources = [os.path.join(C_DIR, filename) for filename in C_FILES] sources.append(os.path.join(HEALPIX_ROOT, 'interpolation.c')) sources.append(os.path.join(HEALPIX_ROOT, '_core.c')) extension = Extension( name="astropy_healpix._core", sources=sources, include_dirs=C_DIRS, libraries=libraries, language="c", extra_compile_args=['-O2']) return [extension]
Example #9
Source File: __init__.py From pledgeservice with Apache License 2.0 | 6 votes |
def setUp(self): self.req = Require('Distutils','1.0.3','distutils') self.dist = makeSetup( features={ 'foo': Feature("foo",standard=True,require_features=['baz',self.req]), 'bar': Feature("bar", standard=True, packages=['pkg.bar'], py_modules=['bar_et'], remove=['bar.ext'], ), 'baz': Feature( "baz", optional=False, packages=['pkg.baz'], scripts = ['scripts/baz_it'], libraries=[('libfoo','foo/foofoo.c')] ), 'dwim': Feature("DWIM", available=False, remove='bazish'), }, script_args=['--without-bar', 'install'], packages = ['pkg.bar', 'pkg.foo'], py_modules = ['bar_et', 'bazish'], ext_modules = [Extension('bar.ext',['bar.c'])] )
Example #10
Source File: test_build_ext.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_get_source_files(self): modules = [Extension('foo', ['xxx'])] dist = Distribution({'name': 'xx', 'ext_modules': modules}) cmd = build_ext(dist) cmd.ensure_finalized() self.assertEqual(cmd.get_source_files(), ['xxx'])
Example #11
Source File: ffiplatform.py From quickstart-git2s3 with Apache License 2.0 | 5 votes |
def get_extension(srcfilename, modname, sources=(), **kwds): _hack_at_distutils() from distutils.core import Extension allsources = [srcfilename] for src in sources: allsources.append(os.path.normpath(src)) return Extension(name=modname, sources=allsources, **kwds)
Example #12
Source File: test_build_ext.py From datafari with Apache License 2.0 | 5 votes |
def test_get_source_files(self): modules = [Extension('foo', ['xxx'])] dist = Distribution({'name': 'xx', 'ext_modules': modules}) cmd = build_ext(dist) cmd.ensure_finalized() self.assertEqual(cmd.get_source_files(), ['xxx'])
Example #13
Source File: test_build_ext.py From datafari with Apache License 2.0 | 5 votes |
def test_build_ext_inplace(self): etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') etree_ext = Extension('lxml.etree', [etree_c]) dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]}) cmd = build_ext(dist) cmd.ensure_finalized() cmd.inplace = 1 cmd.distribution.package_dir = {'': 'src'} cmd.distribution.packages = ['lxml', 'lxml.html'] curdir = os.getcwd() ext = sysconfig.get_config_var("SO") wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext) path = cmd.get_ext_fullpath('lxml.etree') self.assertEqual(wanted, path)
Example #14
Source File: test_build_ext.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_setuptools_compat(self): import distutils.core, distutils.extension, distutils.command.build_ext saved_ext = distutils.extension.Extension try: # on some platforms, it loads the deprecated "dl" module test_support.import_module('setuptools_build_ext', deprecated=True) # theses import patch Distutils' Extension class from setuptools_build_ext import build_ext as setuptools_build_ext from setuptools_extension import Extension etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') etree_ext = Extension('lxml.etree', [etree_c]) dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]}) cmd = setuptools_build_ext(dist) cmd.ensure_finalized() cmd.inplace = 1 cmd.distribution.package_dir = {'': 'src'} cmd.distribution.packages = ['lxml', 'lxml.html'] curdir = os.getcwd() ext = sysconfig.get_config_var("SO") wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext) path = cmd.get_ext_fullpath('lxml.etree') self.assertEqual(wanted, path) finally: # restoring Distutils' Extension class otherwise its broken distutils.extension.Extension = saved_ext distutils.core.Extension = saved_ext distutils.command.build_ext.Extension = saved_ext
Example #15
Source File: setuptools_ext.py From quickstart-git2s3 with Apache License 2.0 | 5 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) On Windows, it's better not to use py_limited_api until issue #355 can be resolved (by having virtualenv copy PYTHON3.DLL). See also the start of _cffi_include.h. """ if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') and sys.platform != 'win32'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #16
Source File: setup.py From EdwardsLab with MIT License | 5 votes |
def main(): setup(name="RobRepeatFinder", version="1.0.0", description="Python interface for repeatFinder", author="Rob Edwards", author_email="raedwards@gmail.com", ext_modules=[Extension("RobRepeatFinder", sources=["repeatFinder.cpp"], language='c++')])
Example #17
Source File: setuptools_ext.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) On Windows, with CPython <= 3.4, it's better not to use py_limited_api because virtualenv *still* doesn't copy PYTHON3.DLL on these versions. For now we'll skip py_limited_api on all Windows versions to avoid an inconsistent mess. """ if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') and sys.platform != 'win32'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #18
Source File: test_build_ext.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_build_ext(self): global ALREADY_TESTED support.copy_xxmodule_c(self.tmp_dir) self.xx_created = True xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_ext = Extension('xx', [xx_c]) dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) dist.package_dir = self.tmp_dir cmd = build_ext(dist) support.fixup_build_ext(cmd) cmd.build_lib = self.tmp_dir cmd.build_temp = self.tmp_dir old_stdout = sys.stdout if not test_support.verbose: # silence compiler output sys.stdout = StringIO() try: cmd.ensure_finalized() cmd.run() finally: sys.stdout = old_stdout if ALREADY_TESTED: return else: ALREADY_TESTED = True import xx for attr in ('error', 'foo', 'new', 'roj'): self.assertTrue(hasattr(xx, attr)) self.assertEqual(xx.foo(2, 5), 7) self.assertEqual(xx.foo(13,15), 28) self.assertEqual(xx.new().demo(), None) if test_support.HAVE_DOCSTRINGS: doc = 'This is a template module just for instruction.' self.assertEqual(xx.__doc__, doc) self.assertTrue(isinstance(xx.Null(), xx.Null)) self.assertTrue(isinstance(xx.Str(), xx.Str))
Example #19
Source File: test_build_ext.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_get_source_files(self): modules = [Extension('foo', ['xxx'])] dist = Distribution({'name': 'xx', 'ext_modules': modules}) cmd = build_ext(dist) cmd.ensure_finalized() self.assertEqual(cmd.get_source_files(), ['xxx'])
Example #20
Source File: test_build_ext.py From datafari with Apache License 2.0 | 5 votes |
def test_build_ext(self): global ALREADY_TESTED support.copy_xxmodule_c(self.tmp_dir) self.xx_created = True xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_ext = Extension('xx', [xx_c]) dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) dist.package_dir = self.tmp_dir cmd = build_ext(dist) support.fixup_build_ext(cmd) cmd.build_lib = self.tmp_dir cmd.build_temp = self.tmp_dir old_stdout = sys.stdout if not test_support.verbose: # silence compiler output sys.stdout = StringIO() try: cmd.ensure_finalized() cmd.run() finally: sys.stdout = old_stdout if ALREADY_TESTED: self.skipTest('Already tested in %s' % ALREADY_TESTED) else: ALREADY_TESTED = type(self).__name__ import xx for attr in ('error', 'foo', 'new', 'roj'): self.assertTrue(hasattr(xx, attr)) self.assertEqual(xx.foo(2, 5), 7) self.assertEqual(xx.foo(13,15), 28) self.assertEqual(xx.new().demo(), None) if test_support.HAVE_DOCSTRINGS: doc = 'This is a template module just for instruction.' self.assertEqual(xx.__doc__, doc) self.assertIsInstance(xx.Null(), xx.Null) self.assertIsInstance(xx.Str(), xx.Str)
Example #21
Source File: setup.py From PhiSpy with MIT License | 5 votes |
def main(): setuptools.setup( name="PhiSpy", version=get_version(), description="Prophage finder using multiple metrics", long_description=long_description, long_description_content_type="text/markdown", author="Rob Edwards", platforms='any', keywords="phage prophage bioinformatics microbiology bacteria genome genomics", author_email="raedwards@gmail.com", url='https://github.com/linsalrob/PhiSpy', license='The MIT License (MIT)', scripts=['PhiSpy.py'], packages=setuptools.find_packages(), ext_modules=[Extension("PhiSpyRepeatFinder", sources=["src/repeatFinder.cpp"], language='c++')], include_package_data=True, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', 'Operating System :: Unix', 'Programming Language :: Python :: 3.0', 'Topic :: Scientific/Engineering :: Bio-Informatics', ], install_requires = [ 'biopython>=1.74', 'numpy>=1.17.0', 'scikit-learn>=0.21.3', ] )
Example #22
Source File: setup.py From Reasoning-RCNN with Apache License 2.0 | 5 votes |
def customize_compiler_for_nvcc(self): """inject deep into distutils to customize how the dispatch to cc/nvcc works. If you subclass UnixCCompiler, it's not trivial to get your subclass injected in, and still have the right customizations (i.e. distutils.sysconfig.customize_compiler) run on it. So instead of going the OO route, I have this. Note, it's kindof like a wierd functional subclassing going on.""" # tell the compiler it can processes .cu self.src_extensions.append('.cu') # save references to the default compiler_so and _comple methods default_compiler_so = self.compiler_so super = self._compile # now redefine the _compile method. This gets executed for each # object but distutils doesn't have the ability to change compilers # based on source extension: we add it. def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts): if osp.splitext(src)[1] == '.cu': # use the cuda for .cu files self.set_executable('compiler_so', 'nvcc') # use only a subset of the extra_postargs, which are 1-1 translated # from the extra_compile_args in the Extension class postargs = extra_postargs['nvcc'] else: postargs = extra_postargs['cc'] super(obj, src, ext, cc_args, postargs, pp_opts) # reset the default compiler_so, which we might have changed for cuda self.compiler_so = default_compiler_so # inject our redefined _compile method into the class self._compile = _compile # run the customize_compiler
Example #23
Source File: setup_package.py From banzai with GNU General Public License v3.0 | 5 votes |
def get_extensions(): med_sources = [str(os.path.join(UTIL_DIR, "median_utils.pyx")), str(os.path.join(UTIL_DIR, "quick_select.c"))] include_dirs = ['numpy', UTIL_DIR] libraries = [] ext_med = Extension(name=str('banzai.utils.median_utils'), sources=med_sources, include_dirs=include_dirs, libraries=libraries, language="c", extra_compile_args=['-g', '-O3', '-funroll-loops', '-ffast-math']) has_openmp, outputs = check_openmp() if has_openmp: if setup_helpers.get_compiler_option() == 'msvc': ext_med.extra_compile_args.append('-openmp') else: ext_med.extra_compile_args.append('-fopenmp') ext_med.extra_link_args = ['-g', '-fopenmp'] else: log.warn('OpenMP was not found. ' 'banzai will be compiled without OpenMP. ' '(Use the "-v" option of setup.py for more details.)') log.debug(('(Start of OpenMP info)\n' 'compiler stdout:\n{0}\n' 'compiler stderr:\n{1}\n' '(End of OpenMP info)').format(*outputs)) return [ext_med]
Example #24
Source File: test_build_ext.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_build_ext_inplace(self): etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') etree_ext = Extension('lxml.etree', [etree_c]) dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]}) cmd = build_ext(dist) cmd.ensure_finalized() cmd.inplace = 1 cmd.distribution.package_dir = {'': 'src'} cmd.distribution.packages = ['lxml', 'lxml.html'] curdir = os.getcwd() ext = sysconfig.get_config_var("SO") wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext) path = cmd.get_ext_fullpath('lxml.etree') self.assertEqual(wanted, path)
Example #25
Source File: ffiplatform.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def get_extension(srcfilename, modname, sources=(), **kwds): _hack_at_distutils() from distutils.core import Extension allsources = [srcfilename] for src in sources: allsources.append(os.path.normpath(src)) return Extension(name=modname, sources=allsources, **kwds)
Example #26
Source File: setuptools_ext.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) On Windows, with CPython <= 3.4, it's better not to use py_limited_api because virtualenv *still* doesn't copy PYTHON3.DLL on these versions. For now we'll skip py_limited_api on all Windows versions to avoid an inconsistent mess. """ if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') and sys.platform != 'win32'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #27
Source File: setuptools_ext.py From learn_python3_spider with MIT License | 5 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) On Windows, with CPython <= 3.4, it's better not to use py_limited_api because virtualenv *still* doesn't copy PYTHON3.DLL on these versions. For now we'll skip py_limited_api on all Windows versions to avoid an inconsistent mess. """ if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') and sys.platform != 'win32'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #28
Source File: ffiplatform.py From learn_python3_spider with MIT License | 5 votes |
def get_extension(srcfilename, modname, sources=(), **kwds): _hack_at_distutils() from distutils.core import Extension allsources = [srcfilename] for src in sources: allsources.append(os.path.normpath(src)) return Extension(name=modname, sources=allsources, **kwds)
Example #29
Source File: setuptools_ext.py From learn_python3_spider with MIT License | 5 votes |
def _set_py_limited_api(Extension, kwds): """ Add py_limited_api to kwds if setuptools >= 26 is in use. Do not alter the setting if it already exists. Setuptools takes care of ignoring the flag on Python 2 and PyPy. CPython itself should ignore the flag in a debugging version (by not listing .abi3.so in the extensions it supports), but it doesn't so far, creating troubles. That's why we check for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) On Windows, with CPython <= 3.4, it's better not to use py_limited_api because virtualenv *still* doesn't copy PYTHON3.DLL on these versions. For now we'll skip py_limited_api on all Windows versions to avoid an inconsistent mess. """ if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') and sys.platform != 'win32'): import setuptools try: setuptools_major_version = int(setuptools.__version__.partition('.')[0]) if setuptools_major_version >= 26: kwds['py_limited_api'] = True except ValueError: # certain development versions of setuptools # If we don't know the version number of setuptools, we # try to set 'py_limited_api' anyway. At worst, we get a # warning. kwds['py_limited_api'] = True return kwds
Example #30
Source File: test_build_ext.py From datafari with Apache License 2.0 | 5 votes |
def test_setuptools_compat(self): import distutils.core, distutils.extension, distutils.command.build_ext saved_ext = distutils.extension.Extension try: # on some platforms, it loads the deprecated "dl" module test_support.import_module('setuptools_build_ext', deprecated=True) # theses import patch Distutils' Extension class from setuptools_build_ext import build_ext as setuptools_build_ext from setuptools_extension import Extension etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') etree_ext = Extension('lxml.etree', [etree_c]) dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]}) cmd = setuptools_build_ext(dist) cmd.ensure_finalized() cmd.inplace = 1 cmd.distribution.package_dir = {'': 'src'} cmd.distribution.packages = ['lxml', 'lxml.html'] curdir = os.getcwd() ext = sysconfig.get_config_var("SO") wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext) path = cmd.get_ext_fullpath('lxml.etree') self.assertEqual(wanted, path) finally: # restoring Distutils' Extension class otherwise its broken distutils.extension.Extension = saved_ext distutils.core.Extension = saved_ext distutils.command.build_ext.Extension = saved_ext