From 0f7d27bd5ac3062f1763b575b17e07e4f284d6e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Wed, 18 Mar 2020 19:56:27 +0100
Subject: [PATCH] move constants to separate files

---
 snakehouse/constants.py  |  7 ++++++-
 snakehouse/multibuild.py | 10 +++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/snakehouse/constants.py b/snakehouse/constants.py
index c8af656..0afe778 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 f1d6dbe..6888c61 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:
-- 
GitLab