From 7764061037fc91b7642bbedae1e5ce48c68709f1 Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Wed, 7 Aug 2019 17:32:49 +0300 Subject: [PATCH 1/6] support conda python --- build/config-mac.def | 13 +++++---- build/gnumake-mac-gcc.inc | 57 ++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/build/config-mac.def b/build/config-mac.def index 0a59aa9..9fbc4a2 100644 --- a/build/config-mac.def +++ b/build/config-mac.def @@ -1,6 +1,9 @@ -# set PY_DEFAULT=0 if you manually installed Python on your system -# (overriding the one that came with OS X by default) -PY_DEFAULT=1 +# which kind of Python installation to use +# system - macOS system default +# local - local installation +# conda - conda environment; specify the environment root dir using the +# PY_CONDA_ROOT environment variable +PY_KIND=conda ######################################################################### @@ -11,7 +14,7 @@ PY_DEFAULT=1 # Mac OSX 10.6 -> default Python version (major.minor) = 2.6 PY_MAJOR_VERSION=2 -PY_MINOR_VERSION=6 +PY_MINOR_VERSION=7 ######################################################################### @@ -19,7 +22,7 @@ PY_MINOR_VERSION=6 # for info see http://numeric.scipy.org # numarray and numeric are outdated -# PY_NUMPY=1 +PY_NUMPY=1 # PY_NUMARRAY=1 # PY_NUMERIC=1 diff --git a/build/gnumake-mac-gcc.inc b/build/gnumake-mac-gcc.inc index 8806024..34495a4 100644 --- a/build/gnumake-mac-gcc.inc +++ b/build/gnumake-mac-gcc.inc @@ -1,3 +1,41 @@ +DEFS += -DPY_EXPORTS + +ifdef PY_NUMPY +DEFS += -DPY_NUMPY +endif + +ifdef PY_NUMARRAY +DEFS += -DPY_NUMARRAY +endif + +ifdef PY_NUMERIC +DEFS += -DPY_NUMERIC +endif + +ifdef PY_USE_GIL +DEFS += -DPY_USE_GIL +endif + +ifdef PY_USE_INOFFICIAL +DEFS += -DPY_USE_INOFFICIAL +endif + +ifeq ($(PY_KIND),conda) + +ifndef PY_CONDA_ROOT +$(error PY_CONDA_ROOT is undefined) +endif + +LIBS += $(PY_CONDA_ROOT)/lib/libpython$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION).dylib +INCPATH += -I$(PY_CONDA_ROOT)/include +INCPATH += -I$(PY_CONDA_ROOT)/include/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) + +ifdef PY_NUMPY +INCPATH += -I$(PY_CONDA_ROOT)/lib/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)/site-packages/numpy/core/include +endif + +else + # don't use -framework Python, since this will stick to the default system version _LOCAL_FRAMEWORK := /Library/Frameworks/Python.framework/Versions/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) @@ -5,10 +43,9 @@ _SYSTEM_FRAMEWORK := /System/Library/Frameworks/Python.framework/Versions/$(PY_M _LOCAL_LIBRARY := /Library/Python/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) _SYSTEM_LIBRARY := /System/Library/Python/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) -DEFS += -DPY_EXPORTS INCPATH += -F/Library/Frameworks -framework Python -ifeq ($(PY_DEFAULT),1) +ifeq ($(PY_KIND),system) LIBS += $(_SYSTEM_FRAMEWORK)/Python INCPATH += -I$(_SYSTEM_FRAMEWORK)/Headers else @@ -16,27 +53,15 @@ LIBS += $(_LOCAL_FRAMEWORK)/Python INCPATH += -I$(_LOCAL_FRAMEWORK)/Headers endif -ifdef PY_NUMARRAY -DEFS += -DPY_NUMARRAY -endif ifdef PY_NUMPY -DEFS += -DPY_NUMPY INCPATH += -I$(_LOCAL_LIBRARY)/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)/site-packages/numpy/core/include -ifeq ($(PY_DEFAULT),1) + +ifeq ($(PY_KIND),system) INCPATH += -I$(_SYSTEM_FRAMEWORK)/lib/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)/site-packages/numpy/core/include INCPATH += -I$(_SYSTEM_FRAMEWORK)/Extras/lib/python/numpy/core/include else INCPATH += -I$(_LOCAL_FRAMEWORK)/lib/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)/site-packages/numpy/core/include endif endif -ifdef PY_NUMERIC -DEFS += -DPY_NUMERIC -endif -ifdef PY_USE_GIL -DEFS += -DPY_USE_GIL -endif - -ifdef PY_USE_INOFFICIAL -DEFS += -DPY_USE_INOFFICIAL endif From 21e3b3271f7c6a3e4f65660512b04aa2216a3dbc Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Thu, 8 Aug 2019 14:55:42 +0300 Subject: [PATCH 2/6] add conda lib dir to rpath --- build/gnumake-mac-gcc.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/build/gnumake-mac-gcc.inc b/build/gnumake-mac-gcc.inc index 34495a4..d93ae5f 100644 --- a/build/gnumake-mac-gcc.inc +++ b/build/gnumake-mac-gcc.inc @@ -29,6 +29,7 @@ endif LIBS += $(PY_CONDA_ROOT)/lib/libpython$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION).dylib INCPATH += -I$(PY_CONDA_ROOT)/include INCPATH += -I$(PY_CONDA_ROOT)/include/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) +LDFLAGS += -rpath $(PY_CONDA_ROOT)/lib ifdef PY_NUMPY INCPATH += -I$(PY_CONDA_ROOT)/lib/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)/site-packages/numpy/core/include From ac328cdcd85b9fb5ed93ca5bb7427702ca90dc94 Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Wed, 14 Aug 2019 17:15:32 +0300 Subject: [PATCH 3/6] add dummy StdOut_Flush() method to make absl logging happy --- source/pybase.cpp | 7 +++++++ source/pybase.h | 1 + 2 files changed, 8 insertions(+) diff --git a/source/pybase.cpp b/source/pybase.cpp index 826e6a4..cb3ea97 100644 --- a/source/pybase.cpp +++ b/source/pybase.cpp @@ -18,6 +18,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. static PyMethodDef StdOut_Methods[] = { { "write", pybase::StdOut_Write, 1 }, + { "flush", pybase::StdOut_Flush, 1 }, { NULL, NULL, } }; @@ -776,6 +777,12 @@ PyObject* pybase::StdOut_Write(PyObject* self, PyObject* args) return Py_None; } +// dummy flush method, since some logging libraries call this +PyObject* pybase::StdOut_Flush(PyObject* self, PyObject* args) +{ + Py_INCREF(Py_None); + return Py_None; +} class work_data { diff --git a/source/pybase.h b/source/pybase.h index 8a3105e..cfda6bf 100644 --- a/source/pybase.h +++ b/source/pybase.h @@ -269,6 +269,7 @@ class pybase }; static PyObject* StdOut_Write(PyObject* Self, PyObject* Args); + static PyObject* StdOut_Flush(PyObject* Self, PyObject* Args); }; #endif From 1f7e520e4147e1c9cbfe480f669b563f4d0a566a Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Fri, 16 Aug 2019 11:03:20 +0300 Subject: [PATCH 4/6] call Py_SetProgramName() when building for conda env --- build/gnumake-mac-gcc.inc | 1 + source/pybase.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/build/gnumake-mac-gcc.inc b/build/gnumake-mac-gcc.inc index d93ae5f..bc2ec27 100644 --- a/build/gnumake-mac-gcc.inc +++ b/build/gnumake-mac-gcc.inc @@ -26,6 +26,7 @@ ifndef PY_CONDA_ROOT $(error PY_CONDA_ROOT is undefined) endif +DEFS += -DPY_INTERPRETER=$(PY_CONDA_ROOT)/bin/python LIBS += $(PY_CONDA_ROOT)/lib/libpython$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION).dylib INCPATH += -I$(PY_CONDA_ROOT)/include INCPATH += -I$(PY_CONDA_ROOT)/include/python$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) diff --git a/source/pybase.cpp b/source/pybase.cpp index cb3ea97..6694d3e 100644 --- a/source/pybase.cpp +++ b/source/pybase.cpp @@ -15,6 +15,9 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include #endif +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + static PyMethodDef StdOut_Methods[] = { { "write", pybase::StdOut_Write, 1 }, @@ -99,8 +102,17 @@ void initsymbol(); void initsamplebuffer(); void initbundle(); + + void pybase::lib_setup() -{ +{ +#ifdef PY_INTERPRETER + { + static char py_program_name[] = TOSTRING(PY_INTERPRETER); + Py_SetProgramName(py_program_name); + } +#endif + post(""); post("------------------------------------------------"); post("py/pyext %s - python script objects",PY__VERSION); From 8308d8af67fc53a02427dcac9e7209eae5962b7e Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Tue, 27 Aug 2019 16:52:00 +0300 Subject: [PATCH 5/6] don't include when using conda --- build/gnumake-mac-gcc.inc | 2 ++ source/pybuffer.h | 2 +- source/pybundle.h | 2 +- source/pyprefix.h | 2 +- source/pysymbol.h | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build/gnumake-mac-gcc.inc b/build/gnumake-mac-gcc.inc index bc2ec27..1ebf47a 100644 --- a/build/gnumake-mac-gcc.inc +++ b/build/gnumake-mac-gcc.inc @@ -38,6 +38,8 @@ endif else +DEFS += -DPY_USE_FRAMEWORK + # don't use -framework Python, since this will stick to the default system version _LOCAL_FRAMEWORK := /Library/Frameworks/Python.framework/Versions/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION) diff --git a/source/pybuffer.h b/source/pybuffer.h index 5869d13..d7ad071 100644 --- a/source/pybuffer.h +++ b/source/pybuffer.h @@ -15,7 +15,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #error You need at least flext version 0.5.0 #endif -#if FLEXT_OS == FLEXT_OS_MAC +#ifdef PY_USE_FRAMEWORK #include #else #include diff --git a/source/pybundle.h b/source/pybundle.h index b397ffb..f862235 100644 --- a/source/pybundle.h +++ b/source/pybundle.h @@ -15,7 +15,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #error You need at least flext version 0.5.0 #endif -#if FLEXT_OS == FLEXT_OS_MAC +#ifdef PY_USE_FRAMEWORK #include #else #include diff --git a/source/pyprefix.h b/source/pyprefix.h index 8b242a4..e9a624c 100644 --- a/source/pyprefix.h +++ b/source/pyprefix.h @@ -16,7 +16,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. // otherwise some functions don't get defined #include -#if FLEXT_OS == FLEXT_OS_MAC +#ifdef PY_USE_FRAMEWORK #include #else #include diff --git a/source/pysymbol.h b/source/pysymbol.h index 0febfde..0b66138 100644 --- a/source/pysymbol.h +++ b/source/pysymbol.h @@ -15,7 +15,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #error You need at least flext version 0.5.0 #endif -#if FLEXT_OS == FLEXT_OS_MAC +#ifdef PY_USE_FRAMEWORK #include #else #include From 0c800aa49caa840650791073e7183b85859afa6d Mon Sep 17 00:00:00 2001 From: Miranda Kastemaa Date: Tue, 27 Aug 2019 16:57:00 +0300 Subject: [PATCH 6/6] more conda fixing --- source/pybuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/pybuffer.cpp b/source/pybuffer.cpp index 4690381..81bb456 100644 --- a/source/pybuffer.cpp +++ b/source/pybuffer.cpp @@ -18,7 +18,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifdef PY_ARRAYS #ifdef PY_NUMARRAY -# if FLEXT_OS == FLEXT_OS_MAC +# ifdef PY_USE_FRAMEWORK # include # else # include @@ -31,7 +31,7 @@ inline bool arrsupport() { return numtype != tAny; } # if defined(PY_NUMPY) # include # else -# if FLEXT_OS == FLEXT_OS_MAC +# ifdef PY_USE_FRAMEWORK # include # else # include @@ -60,7 +60,7 @@ PyObject *pybase::py_arraysupport(PyObject *self,PyObject *args) // PD defines a T_OBJECT symbol #undef T_OBJECT -#if FLEXT_OS == FLEXT_OS_MAC +#ifdef PY_USE_FRAMEWORK #include "Python/bufferobject.h" #include "Python/structmember.h" #else