From 60bba830c64b7fac520be48d145a98af6ba8f58f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Feb 2016 12:46:24 -0800 Subject: [PATCH 1/5] override POTHOS_PYTHON_DIR cmake variable --- Changelog.txt | 1 + cmake/PothosPythonUtil.cmake | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Changelog.txt b/Changelog.txt index 65d7498..7889444 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,6 +3,7 @@ This this the changelog file for the Pothos Python toolkit. Release 0.1.3 (pending) ========================== +- Ability to override POTHOS_PYTHON_DIR cmake variable - Added missing libpoco-dev to debian Build-Depends Release 0.1.2 (2015-12-16) diff --git a/cmake/PothosPythonUtil.cmake b/cmake/PothosPythonUtil.cmake index c79bbda..d6fe9a9 100644 --- a/cmake/PothosPythonUtil.cmake +++ b/cmake/PothosPythonUtil.cmake @@ -24,6 +24,8 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE POTHOS_PYTHON_DIR ) +set(POTHOS_PYTHON_DIR ${POTHOS_PYTHON_DIR} CACHE PATH "python install prefix") + file(TO_CMAKE_PATH "${POTHOS_PYTHON_DIR}" POTHOS_PYTHON_DIR) message(STATUS "POTHOS_PYTHON_DIR: \${prefix}/${POTHOS_PYTHON_DIR}") From 206ddaa185874d6ba963ac3a9dc0dded909fdfb9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Feb 2016 13:30:28 -0800 Subject: [PATCH 2/5] python version tuple for all registry paths --- CMakeLists.txt | 2 +- Changelog.txt | 1 + Pothos/Block.py | 6 +- Pothos/PothosModule.cpp | 21 +++--- ProxyHelpers.cpp | 7 +- PythonBlock.cpp | 5 +- PythonConvert.cpp | 101 +++++++++++++------------- PythonProxy.cpp | 4 +- PythonProxy.hpp | 5 +- PythonSupport.in.hpp | 6 +- TestBlocks/CMakeLists.txt | 6 +- TestPython.cpp | 23 +++--- TestPythonBlock.cpp | 21 +++--- cmake/PothosPythonBlockFactory.in.cpp | 4 +- cmake/PothosPythonUtil.cmake | 3 + 15 files changed, 116 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cff9979..4151109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ set(SOURCES ) POTHOS_MODULE_UTIL( - TARGET PythonSupport + TARGET Python${POTHOS_PYVER}Support SOURCES ${SOURCES} LIBRARIES ${PYTHON_LIBRARIES} DESTINATION proxy/environment diff --git a/Changelog.txt b/Changelog.txt index 7889444..24e3ac8 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,6 +3,7 @@ This this the changelog file for the Pothos Python toolkit. Release 0.1.3 (pending) ========================== +- Use the python version tuple for all registry paths - Ability to override POTHOS_PYTHON_DIR cmake variable - Added missing libpoco-dev to debian Build-Depends diff --git a/Pothos/Block.py b/Pothos/Block.py index 6f20050..82e7f70 100644 --- a/Pothos/Block.py +++ b/Pothos/Block.py @@ -1,4 +1,4 @@ -# Copyright (c) 2014-2014 Josh Blum +# Copyright (c) 2014-2016 Josh Blum # SPDX-License-Identifier: BSL-1.0 from . PothosModule import * @@ -6,12 +6,14 @@ from . OutputPort import OutputPort from . Label import Label, LabelIteratorRange import weakref +import sys class Block(object): def __init__(self): env = ProxyEnvironment("managed") reg = env.findProxy("Pothos/BlockRegistry") - self._block = reg.callProxy("/blocks/python_block") + pyname = "python%d%d"%(sys.version_info.major, sys.version_info.minor) + self._block = reg.callProxy("/%s/python_block"%pyname) self._block._setPyBlock(weakref.proxy(self)) def __getattr__(self, name): diff --git a/Pothos/PothosModule.cpp b/Pothos/PothosModule.cpp index 72069fc..fa39ab4 100644 --- a/Pothos/PothosModule.cpp +++ b/Pothos/PothosModule.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2014-2014 Josh Blum +// Copyright (c) 2014-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 +#include "PythonSupport.hpp" #include "PothosModule.hpp" #include #include @@ -19,9 +20,9 @@ static void initPyObjectUtilityConverters(void) try { Pothos::init(); //init here in case python is the caller - myPythonProxyEnv = Pothos::ProxyEnvironment::make("python"); - myPyObjectToProxyFcn = Pothos::PluginRegistry::get("/proxy_helpers/python/pyobject_to_proxy").getObject().extract(); - myProxyToPyObjectFcn = Pothos::PluginRegistry::get("/proxy_helpers/python/proxy_to_pyobject").getObject().extract(); + myPythonProxyEnv = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); + myPyObjectToProxyFcn = Pothos::PluginRegistry::get("/proxy_helpers/" POTHOS_PYNAME "/pyobject_to_proxy").getObject().extract(); + myProxyToPyObjectFcn = Pothos::PluginRegistry::get("/proxy_helpers/" POTHOS_PYNAME "/proxy_to_pyobject").getObject().extract(); registerPothosModuleConverters(); } catch (const Pothos::Exception &ex) @@ -32,17 +33,17 @@ static void initPyObjectUtilityConverters(void) static void handlePythonPluginEvent(const Pothos::Plugin &plugin, const std::string &event) { - if (event == "remove" and plugin.getPath() == Pothos::PluginPath("/proxy_helpers/python/pyobject_to_proxy")) + if (event == "remove" and plugin.getPath() == Pothos::PluginPath("/proxy_helpers/" POTHOS_PYNAME "/pyobject_to_proxy")) { myPythonProxyEnv.reset(); myPyObjectToProxyFcn = PyObjectToProxyFcn(); - Pothos::PluginRegistry::remove("/proxy/converters/python/proxy_to_pyproxy"); + Pothos::PluginRegistry::remove("/proxy/converters/" POTHOS_PYNAME "/proxy_to_pyproxy"); } - if (event == "remove" and plugin.getPath() == Pothos::PluginPath("/proxy_helpers/python/proxy_to_pyobject")) + if (event == "remove" and plugin.getPath() == Pothos::PluginPath("/proxy_helpers/" POTHOS_PYNAME "/proxy_to_pyobject")) { myPythonProxyEnv.reset(); myProxyToPyObjectFcn = ProxyToPyObjectFcn(); - Pothos::PluginRegistry::remove("/proxy/converters/python/pyproxy_to_proxy"); + Pothos::PluginRegistry::remove("/proxy/converters/" POTHOS_PYNAME "/pyproxy_to_proxy"); } } @@ -85,9 +86,9 @@ static Pothos::Proxy convertProxyToPyProxy(Pothos::ProxyEnvironment::Sptr env, c void registerPothosModuleConverters(void) { Pothos::PluginRegistry::addCall("/proxy_helpers/python", &handlePythonPluginEvent); - Pothos::PluginRegistry::addCall("/proxy/converters/python/proxy_to_pyproxy", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/proxy_to_pyproxy", &convertProxyToPyProxy); - Pothos::PluginRegistry::add("/proxy/converters/python/pyproxy_to_proxy", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pyproxy_to_proxy", Pothos::ProxyConvertPair("PothosProxy", &convertPyProxyToProxy)); } diff --git a/ProxyHelpers.cpp b/ProxyHelpers.cpp index 422be64..7c9e0bd 100644 --- a/ProxyHelpers.cpp +++ b/ProxyHelpers.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2014-2014 Josh Blum +// Copyright (c) 2014-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 +#include "PythonSupport.hpp" #include "PythonProxy.hpp" #include #include @@ -22,8 +23,8 @@ static PyObject *convertProxyToPyObject(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPyObjectHelpers) { - Pothos::PluginRegistry::add("/proxy_helpers/python/pyobject_to_proxy", + Pothos::PluginRegistry::add("/proxy_helpers/" POTHOS_PYNAME "/pyobject_to_proxy", PyObjectToProxyFcn(&convertPyObjectToProxy)); - Pothos::PluginRegistry::add("/proxy_helpers/python/proxy_to_pyobject", + Pothos::PluginRegistry::add("/proxy_helpers/" POTHOS_PYNAME "/proxy_to_pyobject", ProxyToPyObjectFcn(&convertProxyToPyObject)); } diff --git a/PythonBlock.cpp b/PythonBlock.cpp index 1fab72a..02b5ece 100644 --- a/PythonBlock.cpp +++ b/PythonBlock.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2014-2014 Josh Blum +// Copyright (c) 2014-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 +#include "PythonSupport.hpp" #include #include #include @@ -61,4 +62,4 @@ class PythonBlock : Pothos::Block }; static Pothos::BlockRegistry registerSocketSink( - "/blocks/python_block", &PythonBlock::make); + "/" POTHOS_PYNAME "/python_block", &PythonBlock::make); diff --git a/PythonConvert.cpp b/PythonConvert.cpp index 9f25af8..ae2c428 100644 --- a/PythonConvert.cpp +++ b/PythonConvert.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2014 Josh Blum +// Copyright (c) 2013-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include @@ -6,6 +6,7 @@ #include #include #include "PythonProxy.hpp" +#include "PythonSupport.hpp" /*********************************************************************** * None @@ -22,9 +23,9 @@ static Pothos::NullObject convertPyNoneToNull(const Pothos::Proxy &) pothos_static_block(pothosRegisterPythonNullConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/null_to_pynone", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/null_to_pynone", &convertNullToPyNone); - Pothos::PluginRegistry::add("/proxy/converters/python/pynone_to_null", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pynone_to_null", Pothos::ProxyConvertPair("NoneType", &convertPyNoneToNull)); } @@ -43,9 +44,9 @@ static bool convertPyBoolToBool(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonBoolConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/bool_to_pybool", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/bool_to_pybool", &convertBoolToPyBool); - Pothos::PluginRegistry::add("/proxy/converters/python/pybool_to_bool", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pybool_to_bool", Pothos::ProxyConvertPair("bool", &convertPyBoolToBool)); } @@ -73,29 +74,29 @@ static long convertPyIntToLong(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonIntConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/char_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/char_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/schar_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/schar_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/uchar_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/uchar_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/sshort_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/sshort_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/ushort_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/ushort_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/sint_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/sint_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/uint_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/uint_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/slong_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/slong_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::addCall("/proxy/converters/python/ulong_to_pyint", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/ulong_to_pyint", &convertIntNumToPyInt); - Pothos::PluginRegistry::add("/proxy/converters/python/pyint_to_long", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pyint_to_long", Pothos::ProxyConvertPair("int", &convertPyIntToLong)); } @@ -115,12 +116,12 @@ static long long convertPyLongToLongLong(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonLongConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/sllong_to_pylong", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/sllong_to_pylong", &convertLongLongToPyLong); - Pothos::PluginRegistry::addCall("/proxy/converters/python/ullong_to_pylong", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/ullong_to_pylong", &convertLongLongToPyLong); - Pothos::PluginRegistry::add("/proxy/converters/python/pylong_to_llong", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pylong_to_llong", Pothos::ProxyConvertPair("long", &convertPyLongToLongLong)); } @@ -140,12 +141,12 @@ static double convertPyFloatToDouble(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonFloatConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/float_to_pyfloat", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/float_to_pyfloat", &convertFloatNumToPyFloat); - Pothos::PluginRegistry::addCall("/proxy/converters/python/double_to_pyfloat", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/double_to_pyfloat", &convertFloatNumToPyFloat); - Pothos::PluginRegistry::add("/proxy/converters/python/pyfloat_to_double", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pyfloat_to_double", Pothos::ProxyConvertPair("float", &convertPyFloatToDouble)); } @@ -166,12 +167,12 @@ static std::complex convertPyComplexToComplex(const Pothos::Proxy &proxy pothos_static_block(pothosRegisterPythonComplexConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/complex64_to_pycomplex", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/complex64_to_pycomplex", &convertComplexToPyComplex); - Pothos::PluginRegistry::addCall("/proxy/converters/python/complex128_to_pycomplex", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/complex128_to_pycomplex", &convertComplexToPyComplex); - Pothos::PluginRegistry::add("/proxy/converters/python/pycomplex_to_complex128", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pycomplex_to_complex128", Pothos::ProxyConvertPair("complex", &convertPyComplexToComplex)); } @@ -198,11 +199,11 @@ static Pothos::Proxy convertStrVecToPyList(Pothos::ProxyEnvironment::Sptr env, c pothos_static_block(pothosRegisterPythonStringConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/string_to_pystring", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/string_to_pystring", &convertStringToPyString); - Pothos::PluginRegistry::add("/proxy/converters/python/pystring_to_string", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pystring_to_string", Pothos::ProxyConvertPair("str", &convertPyStringToString)); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecstring_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecstring_to_pylist", &convertStrVecToPyList); } @@ -225,13 +226,13 @@ static std::vector convertPyBytesToString(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonBytesConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecchar_to_pybytes", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecchar_to_pybytes", &convertByteVectorToPyBytes); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecschar_to_pybytes", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecschar_to_pybytes", &convertByteVectorToPyBytes); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecuchar_to_pybytes", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecuchar_to_pybytes", &convertByteVectorToPyBytes); - Pothos::PluginRegistry::add("/proxy/converters/python/pybytes_to_string", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pybytes_to_string", Pothos::ProxyConvertPair("bytes", &convertPyBytesToString)); } @@ -292,29 +293,29 @@ static Pothos::Proxy convertComplexVectorToPyList(Pothos::ProxyEnvironment::Sptr pothos_static_block(pothosRegisterPythonNumericConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecsshort_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecsshort_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecushort_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecushort_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecsint_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecsint_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecuint_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecuint_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecslong_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecslong_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/veculong_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/veculong_to_pylist", &convertIntVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecsllong_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecsllong_to_pylist", &convertLongLongVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecullong_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecullong_to_pylist", &convertLongLongVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecfloat_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecfloat_to_pylist", &convertFloatVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/vecdouble_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vecdouble_to_pylist", &convertFloatVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/veccomplexfloat_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/veccomplexfloat_to_pylist", &convertComplexVectorToPyList); - Pothos::PluginRegistry::addCall("/proxy/converters/python/veccomplexdouble_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/veccomplexdouble_to_pylist", &convertComplexVectorToPyList); } @@ -335,7 +336,7 @@ static Pothos::ProxyVector convertPyTupleToVector(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonTupleConversions) { - Pothos::PluginRegistry::add("/proxy/converters/python/pytuple_to_vector", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pytuple_to_vector", Pothos::ProxyConvertPair("tuple", &convertPyTupleToVector)); } @@ -367,9 +368,9 @@ static Pothos::ProxyVector convertPyListToVector(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonListConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/vector_to_pylist", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/vector_to_pylist", &convertVectorToPyList); - Pothos::PluginRegistry::add("/proxy/converters/python/pylist_to_vector", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pylist_to_vector", Pothos::ProxyConvertPair("list", &convertPyListToVector)); } @@ -403,9 +404,9 @@ static Pothos::ProxySet convertPySetToSet(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonSetConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/set_to_pyset", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/set_to_pyset", &convertSetToPySet); - Pothos::PluginRegistry::add("/proxy/converters/python/pyset_to_set", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pyset_to_set", Pothos::ProxyConvertPair("set", &convertPySetToSet)); } @@ -442,8 +443,8 @@ static Pothos::ProxyMap convertPyDictToMap(const Pothos::Proxy &proxy) pothos_static_block(pothosRegisterPythonDictConversions) { - Pothos::PluginRegistry::addCall("/proxy/converters/python/map_to_pydict", + Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/map_to_pydict", &convertMapToPyDict); - Pothos::PluginRegistry::add("/proxy/converters/python/pydict_to_map", + Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pydict_to_map", Pothos::ProxyConvertPair("dict", &convertPyDictToMap)); } diff --git a/PythonProxy.cpp b/PythonProxy.cpp index bcb8a90..181bba2 100644 --- a/PythonProxy.cpp +++ b/PythonProxy.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 Josh Blum +// Copyright (c) 2013-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include "PythonSupport.hpp" @@ -161,6 +161,6 @@ Pothos::ProxyEnvironment::Sptr makePythonProxyEnvironment(const Pothos::ProxyEnv pothos_static_block(pothosRegisterPythonProxy) { Pothos::PluginRegistry::addCall( - "/proxy/environment/python", + "/proxy/environment/" POTHOS_PYNAME, &makePythonProxyEnvironment); } diff --git a/PythonProxy.hpp b/PythonProxy.hpp index 5ab92f0..af136c6 100644 --- a/PythonProxy.hpp +++ b/PythonProxy.hpp @@ -1,7 +1,8 @@ -// Copyright (c) 2013-2014 Josh Blum +// Copyright (c) 2013-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 #pragma once +#include "PythonSupport.hpp" #include "PyObjectUtils.hpp" #include #include @@ -62,7 +63,7 @@ class PythonProxyEnvironment : std::string getName(void) const { - return "python"; + return POTHOS_PYNAME; } Pothos::Proxy findProxy(const std::string &name); diff --git a/PythonSupport.in.hpp b/PythonSupport.in.hpp index a69ed5b..8dc9dcd 100644 --- a/PythonSupport.in.hpp +++ b/PythonSupport.in.hpp @@ -1,6 +1,10 @@ -// Copyright (c) 2015-2015 Josh Blum +// Copyright (c) 2015-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 #pragma once +//! The prefix directory (example lib/pythonXX/site-packages) #define POTHOS_PYTHON_DIR "@POTHOS_PYTHON_DIR@" + +//! The name with version tuple used in registry paths (example python27) +#define POTHOS_PYNAME "python@POTHOS_PYVER@" diff --git a/TestBlocks/CMakeLists.txt b/TestBlocks/CMakeLists.txt index 9b08d9d..dbde767 100644 --- a/TestBlocks/CMakeLists.txt +++ b/TestBlocks/CMakeLists.txt @@ -18,9 +18,9 @@ POTHOS_PYTHON_UTIL( Forwarder.py SimpleSigSlots.py FACTORIES - "/python/forwarder:Forwarder" - "/python/simple_signal_emitter:SimpleSignalEmitter" - "/python/simple_slot_acceptor:SimpleSlotAcceptor" + "/python${POTHOS_PYVER}/forwarder:Forwarder" + "/python${POTHOS_PYVER}/simple_signal_emitter:SimpleSignalEmitter" + "/python${POTHOS_PYVER}/simple_slot_acceptor:SimpleSlotAcceptor" DESTINATION PothosTestBlocks ENABLE_DOCS ) diff --git a/TestPython.cpp b/TestPython.cpp index 42a91eb..4fa6d6c 100644 --- a/TestPython.cpp +++ b/TestPython.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2013-2014 Josh Blum +// Copyright (c) 2013-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 +#include "PythonSupport.hpp" #include #include #include @@ -8,9 +9,9 @@ #include #include -POTHOS_TEST_BLOCK("/proxy/python/tests", test_basic_types) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_basic_types) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); auto noneProxy = env->convertObjectToProxy(Pothos::Object()); auto nullObject = env->convertProxyToObject(noneProxy); @@ -35,9 +36,9 @@ POTHOS_TEST_BLOCK("/proxy/python/tests", test_basic_types) POTHOS_TEST_EQUAL(env->makeProxy(strVal).convert(), strVal); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_compare_to) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_compare_to) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); auto int0 = env->makeProxy(0); auto int1 = env->makeProxy(1); @@ -60,9 +61,9 @@ POTHOS_TEST_BLOCK("/proxy/python/tests", test_compare_to) POTHOS_TEST_EQUAL(int2.compareTo(int2Again), 0); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_containers) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_containers) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); //make test vector Pothos::ProxyVector testVec; @@ -113,9 +114,9 @@ POTHOS_TEST_BLOCK("/proxy/python/tests", test_containers) POTHOS_TEST_EQUAL(find1->second.convert(), 2); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_call_module) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_call_module) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); auto re = env->findProxy("re"); auto m = re.callProxy("search", "(?<=abc)def", "abcdef"); @@ -128,9 +129,9 @@ POTHOS_TEST_BLOCK("/proxy/python/tests", test_call_module) myDict[env->makeProxy(1)] = env->makeProxy(2); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_serialization) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_serialization) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); //make test dictionary Pothos::ProxyMap testDict; diff --git a/TestPythonBlock.cpp b/TestPythonBlock.cpp index ff9b4b9..754cf4a 100644 --- a/TestPythonBlock.cpp +++ b/TestPythonBlock.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2014-2015 Josh Blum +// Copyright (c) 2014-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 +#include "PythonSupport.hpp" #include #include #include @@ -8,25 +9,25 @@ #include #include -POTHOS_TEST_BLOCK("/proxy/python/tests", python_module_import) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", python_module_import) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); env->findProxy("Pothos"); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_python_module) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_python_module) { - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make(POTHOS_PYNAME); env->findProxy("Pothos.TestPothos").callProxy("main"); } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_python_block) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_python_block) { auto env = Pothos::ProxyEnvironment::make("managed"); auto reg = env->findProxy("Pothos/BlockRegistry"); auto feeder = reg.callProxy("/blocks/feeder_source", "int"); auto collector = reg.callProxy("/blocks/collector_sink", "int"); - auto forwarder = reg.callProxy("/python/forwarder", Pothos::DType("int")); + auto forwarder = reg.callProxy("/" POTHOS_PYNAME "/forwarder", Pothos::DType("int")); //create a test plan Poco::JSON::Object::Ptr testPlan(new Poco::JSON::Object()); @@ -49,12 +50,12 @@ POTHOS_TEST_BLOCK("/proxy/python/tests", test_python_block) std::cout << "run done\n"; } -POTHOS_TEST_BLOCK("/proxy/python/tests", test_signals_and_slots) +POTHOS_TEST_BLOCK("/proxy/" POTHOS_PYNAME "/tests", test_signals_and_slots) { auto env = Pothos::ProxyEnvironment::make("managed"); auto reg = env->findProxy("Pothos/BlockRegistry"); - auto emitter = reg.callProxy("/python/simple_signal_emitter"); - auto acceptor = reg.callProxy("/python/simple_slot_acceptor"); + auto emitter = reg.callProxy("/" POTHOS_PYNAME "/simple_signal_emitter"); + auto acceptor = reg.callProxy("/" POTHOS_PYNAME "/simple_slot_acceptor"); //run the topology { diff --git a/cmake/PothosPythonBlockFactory.in.cpp b/cmake/PothosPythonBlockFactory.in.cpp index 9f95bba..0a2fdce 100644 --- a/cmake/PothosPythonBlockFactory.in.cpp +++ b/cmake/PothosPythonBlockFactory.in.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 Josh Blum +// Copyright (c) 2014-2016 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include @@ -7,7 +7,7 @@ static Pothos::Object @class_name@Factory(const Pothos::Object *args, const size_t numArgs) { //create python environment - auto env = Pothos::ProxyEnvironment::make("python"); + auto env = Pothos::ProxyEnvironment::make("python@POTHOS_PYVER@"); //convert arguments into proxy environment std::vector proxyArgs(numArgs); diff --git a/cmake/PothosPythonUtil.cmake b/cmake/PothosPythonUtil.cmake index d6fe9a9..e23eee9 100644 --- a/cmake/PothosPythonUtil.cmake +++ b/cmake/PothosPythonUtil.cmake @@ -26,6 +26,9 @@ execute_process( ) set(POTHOS_PYTHON_DIR ${POTHOS_PYTHON_DIR} CACHE PATH "python install prefix") +set(POTHOS_PYVER "${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}") +message(STATUS "POTHOS_PYVER: ${POTHOS_PYVER}") + file(TO_CMAKE_PATH "${POTHOS_PYTHON_DIR}" POTHOS_PYTHON_DIR) message(STATUS "POTHOS_PYTHON_DIR: \${prefix}/${POTHOS_PYTHON_DIR}") From 1619dc03213905a09fd3d9d95911d73e49e88d29 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Feb 2016 13:33:07 -0800 Subject: [PATCH 3/5] forgot POTHOS_PYVER in test blocks --- TestBlocks/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestBlocks/CMakeLists.txt b/TestBlocks/CMakeLists.txt index dbde767..353c5a0 100644 --- a/TestBlocks/CMakeLists.txt +++ b/TestBlocks/CMakeLists.txt @@ -12,7 +12,7 @@ include(PothosPythonUtil) ## Build and install tester blocks for python bindings ######################################################################## POTHOS_PYTHON_UTIL( - TARGET PythonTestBlocks + TARGET Python${POTHOS_PYVER}TestBlocks SOURCES __init__.py Forwarder.py From f62227d09925a8e35118d158a5a020983f075cec Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Feb 2016 13:54:11 -0800 Subject: [PATCH 4/5] forgot POTHOS_PYVER in module hook --- Pothos/PothosModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pothos/PothosModule.cpp b/Pothos/PothosModule.cpp index fa39ab4..9d846dd 100644 --- a/Pothos/PothosModule.cpp +++ b/Pothos/PothosModule.cpp @@ -85,7 +85,7 @@ static Pothos::Proxy convertProxyToPyProxy(Pothos::ProxyEnvironment::Sptr env, c void registerPothosModuleConverters(void) { - Pothos::PluginRegistry::addCall("/proxy_helpers/python", &handlePythonPluginEvent); + Pothos::PluginRegistry::addCall("/proxy_helpers/" POTHOS_PYNAME, &handlePythonPluginEvent); Pothos::PluginRegistry::addCall("/proxy/converters/" POTHOS_PYNAME "/proxy_to_pyproxy", &convertProxyToPyProxy); Pothos::PluginRegistry::add("/proxy/converters/" POTHOS_PYNAME "/pyproxy_to_proxy", From 4f47fc3a511a2f10b5f8596668112d2386cabb4c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Feb 2016 14:26:50 -0800 Subject: [PATCH 5/5] Python_ADDITIONAL_VERSIONS helper when not set --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4151109..0418688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,11 @@ find_package(Pothos CONFIG REQUIRED) list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake) include(PothosPythonUtil) +#help find_package(PythonLibs) by setting Python_ADDITIONAL_VERSIONS from PYTHON_VERSION_STRING +if(PYTHONINTERP_FOUND AND DEFINED PYTHON_VERSION_STRING AND NOT DEFINED Python_ADDITIONAL_VERSIONS) + string(SUBSTRING "${PYTHON_VERSION_STRING}" 0 3 Python_ADDITIONAL_VERSIONS) +endif() + ######################################################################## ## Find python ########################################################################