forked from PlusToolkit/ndicapi
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C extension module supports Python 3 #14
Merged
dzhoshkun
merged 33 commits into
master
from
11-python-3-support-for-the-extension-module
Mar 1, 2018
Merged
C extension module supports Python 3 #14
dzhoshkun
merged 33 commits into
master
from
11-python-3-support-for-the-extension-module
Mar 1, 2018
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 tasks
dzhoshkun
changed the title
C extension module supports Python 3
WIP: C extension module supports Python 3
Feb 25, 2018
…the Python extension
…but not as a shared library
Testing on Mac:
|
The following patch on WherePy (054e952470462523d41224e37402b5b52fc33194) seems to solve it for Python 3: diff --git a/wherepy/io/__init__.py b/wherepy/io/__init__.py
index bda405b..e56f318 100644
--- a/wherepy/io/__init__.py
+++ b/wherepy/io/__init__.py
@@ -47,10 +47,10 @@ def display_status(connected, quality=None, error=None, msg=None, utf=False):
# pylint:disable=relative-import
if utf:
- import _symbols_unicode
+ from . import _symbols_unicode
symbols = _symbols_unicode.INDICATOR_SYMBOLS
else:
- import _symbols_ascii
+ from . import _symbols_ascii
symbols = _symbols_ascii.INDICATOR_SYMBOLS
if connected:
connection_status = symbols['connection_status']['connected']
diff --git a/wherepy/track/ndi/_tracker.py b/wherepy/track/ndi/_tracker.py
index 0389a35..6f6145b 100644
--- a/wherepy/track/ndi/_tracker.py
+++ b/wherepy/track/ndi/_tracker.py
@@ -124,7 +124,7 @@ class Tracker(wherepy.track.Tracker):
' was: {}'.format(command, ndiErrorString(error)))
# acquire transform
- transform = ndiGetGXTransform(self.device, str(tool_id))
+ transform = ndiGetGXTransform(self.device, bytes(str(tool_id), 'utf-8'))
error = ndiGetError(self.device)
if error != NDI_OKAY:
raise IOError('Could not capture tool with ID {}. The error was:'
|
…as pip will remove the installed *.so file when uninstalling)
Using the following automated bash script for testing: #!/usr/bin/env bash
NDICAPI_REPO_DIR=$HOME/ws/ndicapi
NDICAPI_INSTALL_PREFIX=$HOME/ws/_install/ndicapi
NDICAPI_BUILD_DIR=$HOME/ws/_build/ndicapi
echo "[C++] Attempting to re-install ndicapi..."
rm -rf $NDICAPI_INSTALL_PREFIX
cd $NDICAPI_BUILD_DIR
rm -rf $NDICAPI_BUILD_DIR/*
cmake -D CMAKE_INSTALL_PREFIX=$NDICAPI_INSTALL_PREFIX -D CMAKE_BUILD_TYPE=Release -D BUILD_PYTHON=ON $NDICAPI_REPO_DIR
make install
echo "...DONE"
echo "[Python 2] Attempting to install ndicapy..."
cd $NDICAPI_REPO_DIR
pip2 install .
echo "...DONE"
echo "[Python 2] Attempting to test ndicapy..."
python2 Applications/ndiBasicExample.py
pip2 uninstall -y wherepy
pip2 install $HOME/ws/wherepy
# TODO wherepy-indicator-cli -x
SESSION_LOG=$HOME/tmp/py2-$(date +"%Y-%m-%d-%H-%M-%S").yml
wherepy-collector-cli -x -p 5 -o $SESSION_LOG
cat $SESSION_LOG
pip2 uninstall -y wherepy
pip2 uninstall -y ndicapi
echo "...DONE"
echo "[Python 3] Attempting to install ndicapy..."
pip3 install .
echo "...DONE"
echo "[Python 3] Attempting to test ndicapy..."
python3 Applications/ndiBasicExample.py
pip3 uninstall -y wherepy
pip3 install $HOME/ws/wherepy
# TODO wherepy-indicator-cli -x
SESSION_LOG=$HOME/tmp/py3-$(date +"%Y-%m-%d-%H-%M-%S").yml
wherepy-collector-cli -x -p 5 -o $SESSION_LOG
cat $SESSION_LOG
pip3 uninstall -y wherepy
pip3 uninstall -y ndicapi
echo "...DONE" |
dzhoshkun
changed the title
WIP: C extension module supports Python 3
C extension module supports Python 3
Mar 1, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The C extension module has been refactored with C macros that enable conditional compilation based on the Python version (closes #11).
The changes have been tested with both Python versions on:
The tests included:
ndiBasicExample.py
with Python 2 and Python 3Other notable changes this PR introduces:
setup.py
file.pip install
. This is a cleaner way to install the extension module, as it takes care of removing all components (including the installed dynamic library file, i.e.ndicapy.so
on Linux) whenpip install ndicapi
is called.BUILD_SHARED_LIBS
is nowON
by default (the Python extension module requires a shared library).pyndicapi
tondicapy
as the latter is shorter and more Pythonic. Closes Rename pyndicapi to ndicapy #13The following guidelines / documentation links are useful for porting Python 2 extension modules to Python 3: