Skip to content

Commit

Permalink
REGRESSION Automatic introspection broken by making setup run on import
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfletch committed Aug 29, 2022
1 parent 0b029cb commit edea11d
Showing 1 changed file with 64 additions and 54 deletions.
118 changes: 64 additions & 54 deletions accelerate/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,103 +8,113 @@
from Cython.Distutils import build_ext
except ImportError:
have_cython = False
build_ext = False
else:
have_cython = True

import sys, os

HERE = os.path.normpath(os.path.abspath(os.path.dirname( __file__ )))
HERE = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))

extensions = [
]
extensions = []

def cython_extension( name, include_dirs = (), ):

def cython_extension(
name,
include_dirs=(),
):
"""Create a cython extension object"""
filenames = '%(name)s.c'%locals(), '%(name)s.pyx'%locals()
filenames = "%(name)s.c" % locals(), "%(name)s.pyx" % locals()
filename = filenames[bool(have_cython)]
return Extension(
"OpenGL_accelerate.%(name)s"%locals(),
"OpenGL_accelerate.%(name)s" % locals(),
[
os.path.join(
'src',
filename
),
os.path.join("src", filename),
],
include_dirs = [
os.path.join(HERE,'src'),
include_dirs=[
os.path.join(HERE, "src"),
HERE,
]+ list(include_dirs),
define_macros = [
# *cython* itself is using the deprecated api, and the
# deprecated APIs are actually providing the attributes
]
+ list(include_dirs),
define_macros=[
# *cython* itself is using the deprecated api, and the
# deprecated APIs are actually providing the attributes
# that we use throughout our code...
# ('NPY_NO_DEPRECATED_API','NPY_1_7_API_VERSION'),
# ('NPY_NO_DEPRECATED_API','NPY_1_7_API_VERSION'),
],
)


extensions.extend([
cython_extension( 'wrapper' ),
cython_extension( 'formathandler' ),
cython_extension( 'arraydatatype' ),
cython_extension( 'errorchecker' ),
cython_extension( 'vbo' ),
cython_extension( 'nones_formathandler' ),
cython_extension( 'latebind' ),
])
if sys.version_info[:2] >= (2,7):
extensions.extend([
cython_extension( 'buffers_formathandler' ),
])
extensions.extend(
[
cython_extension("wrapper"),
cython_extension("formathandler"),
cython_extension("arraydatatype"),
cython_extension("errorchecker"),
cython_extension("vbo"),
cython_extension("nones_formathandler"),
cython_extension("latebind"),
]
)
if sys.version_info[:2] >= (2, 7):
extensions.extend(
[
cython_extension("buffers_formathandler"),
]
)

try:
import numpy
except ImportError:
sys.stderr.write(
"""Unable to import numpy, skipping numpy extension building\n"""
)
sys.stderr.write("""Unable to import numpy, skipping numpy extension building\n""")
else:
if hasattr( numpy, 'get_include' ):
if hasattr(numpy, "get_include"):
includeDirectories = [
numpy.get_include(),
]
else:
includeDirectories = [
os.path.join(
os.path.dirname( numpy.__file__ ),
'core',
'include',
os.path.dirname(numpy.__file__),
"core",
"include",
),
]
extensions.append( cython_extension(
'numpy_formathandler', includeDirectories,

) )
extensions.append(
cython_extension(
"numpy_formathandler",
includeDirectories,
)
)

if True: # minimise Git diff
if ( # Prevents running of setup during code introspection imports
__name__ == "__main__"
):
# Workaround for Broken apple Python build params echoed in distutils
# Approach taken from the PyMongo driver. OS-X Python builds were created with
# non-existent flag, and distutils passes those flags to the extension
# Approach taken from the PyMongo driver. OS-X Python builds were created with
# non-existent flag, and distutils passes those flags to the extension
# build, newer clangs now treat those flags as errors rather than warnings.
import platform, sys
if sys.platform == 'darwin' and 'clang' in platform.python_compiler().lower():

if sys.platform == "darwin" and "clang" in platform.python_compiler().lower():
from distutils.sysconfig import get_config_vars

res = get_config_vars()
for key in ('CFLAGS', 'PY_CFLAGS'):
for key in ("CFLAGS", "PY_CFLAGS"):
if key in res:
res[key] = res[key].replace('-mno-fused-madd', '')
res[key] = res[key].replace("-mno-fused-madd", "")

extraArguments = {}
### Now the actual set up call
if have_cython:
extraArguments['cmdclass'] = {
'build_ext': build_ext,
extraArguments["cmdclass"] = {
"build_ext": build_ext,
}
setup (
options = {
'sdist': {
'formats': ['gztar','zip'],
'force_manifest': True,
setup(
options={
"sdist": {
"formats": ["gztar", "zip"],
"force_manifest": True,
},
},
ext_modules=extensions,
Expand Down

0 comments on commit edea11d

Please sign in to comment.