diff --git a/snakehouse/constants.py b/snakehouse/constants.py index c8af656eb98d70f6e5760dfcc0ac2048c9d67592..0afe778053d0e943d659f27cfaea01909e32cf5a 100644 --- a/snakehouse/constants.py +++ b/snakehouse/constants.py @@ -78,4 +78,9 @@ BOOTSTRAP_PYX_GET_DEFINITION_IF = """ if name == %s: BOOTSTRAP_PYX_GET_DEFINITION_ELIF = """ elif name == %s: return %s -""" \ No newline at end of file +""" + +INCLUDE_PYTHON_H = '#include "Python.h"\n' + +INCLUDE_PYINIT = 'PyObject* PyInit_%s();' + diff --git a/snakehouse/multibuild.py b/snakehouse/multibuild.py index f1d6dbe060374396f572a8363c6a66308373f39b..6888c61f82c1c985c4d0a5ef8b506a06d2458999 100644 --- a/snakehouse/multibuild.py +++ b/snakehouse/multibuild.py @@ -3,7 +3,7 @@ import os from setuptools import Extension from .constants import BOOTSTRAP_PYX_HEADER, BOOTSTRAP_PYX_PACKAGE_LOADER, INIT_PY_CONTENTS, \ BOOTSTRAP_PYX_CDEF, BOOTSTRAP_PYX_GET_DEFINITION_HEADER, BOOTSTRAP_PYX_GET_DEFINITION_IF, \ - BOOTSTRAP_PYX_GET_DEFINITION_ELIF + BOOTSTRAP_PYX_GET_DEFINITION_ELIF, INCLUDE_PYTHON_H, INCLUDE_PYINIT class Multibuild: @@ -33,14 +33,14 @@ class Multibuild: module_name = name.replace('.pyx', '') h_name = name.replace('.pyx', '.h') - exported_line = 'PyObject* PyInit_%s();' % (module_name,) + exported_line = INCLUDE_PYINIT % (module_name,) if os.path.exists(h_name): with open(os.path.join(path, h_name), 'r') as f_in: data = f_in.read() - if '#include "Python.h"' not in data: - data = '#include "Python.h"\n'+data + if INCLUDE_PYTHON_H not in data: + data = INCLUDE_PYTHON_H+data if exported_line not in data: data = data+'\n'+exported_line+'\n' @@ -49,7 +49,7 @@ class Multibuild: f_out.write(data) else: with open(os.path.join(path, h_name), 'w') as f_out: - f_out.write('#include "Python.h"\n') + f_out.write(INCLUDE_PYTHON_H) f_out.write('\n'+exported_line+'\n') def generate_bootstrap(self) -> str: