From 07d2130bf0483cacaee5439430ed9cbeaee04aff Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 19 Aug 2020 13:16:42 +0200 Subject: [PATCH] hybrid C++/Python package / Add Makefile --- Makefile | 19 ++++++++++ setup.py | 40 +++++++++------------- src/pEp/__init__.py | 30 ++++++++++++++++ src/{ => pEp/native_pEp}/adapter.cc | 0 src/{ => pEp/native_pEp}/adapter.hh | 0 src/{ => pEp/native_pEp}/basic_api.cc | 0 src/{ => pEp/native_pEp}/basic_api.hh | 0 src/{ => pEp/native_pEp}/identity.cc | 0 src/{ => pEp/native_pEp}/identity.hh | 0 src/{ => pEp/native_pEp}/locked_queue.hh | 0 src/{ => pEp/native_pEp}/message.cc | 0 src/{ => pEp/native_pEp}/message.hh | 0 src/{ => pEp/native_pEp}/message_api.cc | 0 src/{ => pEp/native_pEp}/message_api.hh | 0 src/{ => pEp/native_pEp}/pEpmodule.cc | 2 +- src/{ => pEp/native_pEp}/pEpmodule.hh | 0 src/{ => pEp/native_pEp}/str_attr.cc | 0 src/{ => pEp/native_pEp}/str_attr.hh | 0 src/{ => pEp/native_pEp}/user_interface.cc | 0 src/{ => pEp/native_pEp}/user_interface.hh | 0 test/pyadpt-81.py | 6 ++++ 21 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 Makefile create mode 100644 src/pEp/__init__.py rename src/{ => pEp/native_pEp}/adapter.cc (100%) rename src/{ => pEp/native_pEp}/adapter.hh (100%) rename src/{ => pEp/native_pEp}/basic_api.cc (100%) rename src/{ => pEp/native_pEp}/basic_api.hh (100%) rename src/{ => pEp/native_pEp}/identity.cc (100%) rename src/{ => pEp/native_pEp}/identity.hh (100%) rename src/{ => pEp/native_pEp}/locked_queue.hh (100%) rename src/{ => pEp/native_pEp}/message.cc (100%) rename src/{ => pEp/native_pEp}/message.hh (100%) rename src/{ => pEp/native_pEp}/message_api.cc (100%) rename src/{ => pEp/native_pEp}/message_api.hh (100%) rename src/{ => pEp/native_pEp}/pEpmodule.cc (99%) rename src/{ => pEp/native_pEp}/pEpmodule.hh (100%) rename src/{ => pEp/native_pEp}/str_attr.cc (100%) rename src/{ => pEp/native_pEp}/str_attr.hh (100%) rename src/{ => pEp/native_pEp}/user_interface.cc (100%) rename src/{ => pEp/native_pEp}/user_interface.hh (100%) create mode 100644 test/pyadpt-81.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..24c251d --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +PREFIX = /home/heck/local-default/ +DEBUG = 0 +BUILD_DIR = ./build + +BUILD_EXT_OPTS = --prefix=$(PREFIX) + +ifeq ($(DEBUG),1) + BUILD_EXT_OPTS+=--debug +endif + +.PHONY: all build clean + +all: build_ext + +build_ext: + python3 setup.py build_ext $(BUILD_EXT_OPTS) + +clean: + rm -r $(BUILD_DIR) \ No newline at end of file diff --git a/setup.py b/setup.py index 7f64886..7268c4e 100644 --- a/setup.py +++ b/setup.py @@ -18,18 +18,16 @@ from glob import glob from setuptools.command.build_ext import build_ext -verboseLevel = 0 def pEpLog(*msg): - if verboseLevel > 0: - import inspect - msgstr = '' - separator = ' ' - for m in msg: - msgstr += str(m) - msgstr += separator - func = inspect.currentframe().f_back.f_code - print(func.co_filename + " : " + func.co_name + " : " + msgstr) + import inspect + msgstr = '' + separator = ' ' + for m in msg: + msgstr += str(m) + msgstr += separator + func = inspect.currentframe().f_back.f_code + print(func.co_filename + " : " + func.co_name + " : " + msgstr) class BuildExtCommand(build_ext): @@ -39,13 +37,11 @@ class BuildExtCommand(build_ext): ] def initialize_options(self): - pEpLog("called") build_ext.initialize_options(self) self.local = None != environ.get('PER_USER_DIRECTORY') self.prefix = getattr(self, "prefix=", None) def windowsGetInstallLocation(self): - pEpLog("called") # Note: should be installed to 'C:\Program Files (x86)' while a 32-bit distro # TODO: Try desktop adapter location first, then COM server # FIXME: This is wrong, we should chase the COM server, not the Outlook Plugin (even if they're in the same place) @@ -138,17 +134,12 @@ class BuildExtCommand(build_ext): return (home, sys_includes, sys_libdirs, libs) def finalize_options(self): - pEpLog("called") build_ext.finalize_options(self) - pEpLog("verbose: ", self.verbose) pEpLog("local: ", self.local) pEpLog("prefix: ", self.prefix) pEpLog("sys.platform: ", sys.platform) - global verboseLevel - verboseLevel = self.verbose - # get build information for platform if sys.platform == 'winnt': build_info = self.get_build_info_winnt() @@ -220,14 +211,14 @@ if sys.version_info[0] < 3: module_pEp = Extension( - 'pEp', + 'native_pEp', sources = [ - 'src/pEpmodule.cc', - 'src/basic_api.cc', - 'src/identity.cc', - 'src/message.cc', - 'src/message_api.cc', - 'src/str_attr.cc', + 'src/pEp/native_pEp/pEpmodule.cc', + 'src/pEp/native_pEp/basic_api.cc', + 'src/pEp/native_pEp/identity.cc', + 'src/pEp/native_pEp/message.cc', + 'src/pEp/native_pEp/message_api.cc', + 'src/pEp/native_pEp/str_attr.cc', # 'src/user_interface.cc', # 'src/adapter.cc' ], @@ -242,6 +233,7 @@ setup( author_email="vb@pep-project.org", maintainer="Heck", maintainer_email="heck@pep.foundation", + package_dir='src', ext_modules=[module_pEp], cmdclass={ 'build_ext': BuildExtCommand, diff --git a/src/pEp/__init__.py b/src/pEp/__init__.py new file mode 100644 index 0000000..1990cc0 --- /dev/null +++ b/src/pEp/__init__.py @@ -0,0 +1,30 @@ +# pEp package +# This file is being exectued upon 'import pEp' +# +# __all__ could be used to limit the symbols exported when using from import * + + +# Import all symbols EXCEPT the ones beginning with underscore into the current namespace +from native_pEp import * + +# import the module +import native_pEp + + + + + +# Executed on module import +def init(): + print("init() called") + # native_pEp._init() + +# Executed when run as script +def main(): + print("I am being run as a script") + +# MAIN +if __name__ == "__main__": + main() +else: + init() \ No newline at end of file diff --git a/src/adapter.cc b/src/pEp/native_pEp/adapter.cc similarity index 100% rename from src/adapter.cc rename to src/pEp/native_pEp/adapter.cc diff --git a/src/adapter.hh b/src/pEp/native_pEp/adapter.hh similarity index 100% rename from src/adapter.hh rename to src/pEp/native_pEp/adapter.hh diff --git a/src/basic_api.cc b/src/pEp/native_pEp/basic_api.cc similarity index 100% rename from src/basic_api.cc rename to src/pEp/native_pEp/basic_api.cc diff --git a/src/basic_api.hh b/src/pEp/native_pEp/basic_api.hh similarity index 100% rename from src/basic_api.hh rename to src/pEp/native_pEp/basic_api.hh diff --git a/src/identity.cc b/src/pEp/native_pEp/identity.cc similarity index 100% rename from src/identity.cc rename to src/pEp/native_pEp/identity.cc diff --git a/src/identity.hh b/src/pEp/native_pEp/identity.hh similarity index 100% rename from src/identity.hh rename to src/pEp/native_pEp/identity.hh diff --git a/src/locked_queue.hh b/src/pEp/native_pEp/locked_queue.hh similarity index 100% rename from src/locked_queue.hh rename to src/pEp/native_pEp/locked_queue.hh diff --git a/src/message.cc b/src/pEp/native_pEp/message.cc similarity index 100% rename from src/message.cc rename to src/pEp/native_pEp/message.cc diff --git a/src/message.hh b/src/pEp/native_pEp/message.hh similarity index 100% rename from src/message.hh rename to src/pEp/native_pEp/message.hh diff --git a/src/message_api.cc b/src/pEp/native_pEp/message_api.cc similarity index 100% rename from src/message_api.cc rename to src/pEp/native_pEp/message_api.cc diff --git a/src/message_api.hh b/src/pEp/native_pEp/message_api.hh similarity index 100% rename from src/message_api.hh rename to src/pEp/native_pEp/message_api.hh diff --git a/src/pEpmodule.cc b/src/pEp/native_pEp/pEpmodule.cc similarity index 99% rename from src/pEpmodule.cc rename to src/pEp/native_pEp/pEpmodule.cc index df58271..e15d520 100644 --- a/src/pEpmodule.cc +++ b/src/pEp/native_pEp/pEpmodule.cc @@ -140,7 +140,7 @@ namespace pEp { } } -BOOST_PYTHON_MODULE(pEp) +BOOST_PYTHON_MODULE(native_pEp) { using namespace boost::python; using namespace boost::locale; diff --git a/src/pEpmodule.hh b/src/pEp/native_pEp/pEpmodule.hh similarity index 100% rename from src/pEpmodule.hh rename to src/pEp/native_pEp/pEpmodule.hh diff --git a/src/str_attr.cc b/src/pEp/native_pEp/str_attr.cc similarity index 100% rename from src/str_attr.cc rename to src/pEp/native_pEp/str_attr.cc diff --git a/src/str_attr.hh b/src/pEp/native_pEp/str_attr.hh similarity index 100% rename from src/str_attr.hh rename to src/pEp/native_pEp/str_attr.hh diff --git a/src/user_interface.cc b/src/pEp/native_pEp/user_interface.cc similarity index 100% rename from src/user_interface.cc rename to src/pEp/native_pEp/user_interface.cc diff --git a/src/user_interface.hh b/src/pEp/native_pEp/user_interface.hh similarity index 100% rename from src/user_interface.hh rename to src/pEp/native_pEp/user_interface.hh diff --git a/test/pyadpt-81.py b/test/pyadpt-81.py new file mode 100644 index 0000000..c78cc10 --- /dev/null +++ b/test/pyadpt-81.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import pEp + +pEp.is_sync_active() \ No newline at end of file