-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ngeiswei/add-python-bindings
Add python bindings (only atom types for now)
- Loading branch information
Showing
8 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 1,6 @@ | ||
|
||
ADD_SUBDIRECTORY (spacetime) | ||
|
||
IF (HAVE_CYTHON) | ||
ADD_SUBDIRECTORY (cython) | ||
ENDIF (HAVE_CYTHON) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,6 @@ | ||
# | ||
ADD_SUBDIRECTORY (opencog) | ||
|
||
# module init | ||
file(MAKE_DIRECTORY opencog) | ||
file(COPY opencog/__init__.py DESTINATION opencog) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,17 @@ | ||
# Python bindings for PLN | ||
|
||
## Requirements | ||
|
||
* Python 2.7, Python 3 recommended. | ||
* Cython 0.14 or later. http://www.cython.org/ | ||
|
||
The bindings are written mostly using Cython, which allows writing | ||
code that looks pythonic but gets compiled to C. It also makes it | ||
trivial to access both Python objects and C objects without using a | ||
bunch of extra Python library API calls. | ||
|
||
## Package structure | ||
|
||
Currently the package structure looks like this: | ||
|
||
opencog.spacetime |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,58 @@ | ||
|
||
# Need to use -fno-strict-aliasing when compiling cython code, in order | ||
# to avoid nasty compiler warnings about aliasing. Cython explicitly | ||
# performs aliasing, in order to emulate python object inheritance. | ||
# See, for example, | ||
# https://groups.google.com/forum/#!topic/cython-users/JV1-KvIUeIg | ||
# | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") | ||
|
||
INCLUDE_DIRECTORIES( | ||
${ATOMSPACE_INCLUDE_DIR} | ||
${PYTHON_INCLUDE_DIRS} | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
IF (${PYTHONLIBS_VERSION_STRING} VERSION_LESS 3.0.0) | ||
SET(CYTHON_FLAGS "-2" "-f" "-Wextra" # "-Werror" | ||
"-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython" | ||
"-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython/opencog") | ||
ELSE () | ||
SET(CYTHON_FLAGS "-3" "-f" "-Wextra" # "-Werror" | ||
"-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython" | ||
"-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython/opencog") | ||
ENDIF () | ||
|
||
# Use this as a guide: | ||
# https://github.com/OpenKinect/libfreenect/blob/master/wrappers/python/CMakeLists.txt | ||
|
||
##################### SpaceTime Types ################## | ||
|
||
CYTHON_ADD_MODULE_PYX(spacetime | ||
"spacetime_types.pyx" | ||
) | ||
|
||
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES "spacetime_types.cpp") | ||
|
||
# opencog.spacetime Python bindings | ||
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) | ||
|
||
ADD_LIBRARY(spacetime_cython SHARED | ||
spacetime.cpp | ||
) | ||
|
||
ADD_DEPENDENCIES(spacetime_cython spacetime-types) | ||
|
||
TARGET_LINK_LIBRARIES(spacetime_cython | ||
spacetime-types | ||
${ATOMSPACE_LIBRARIES} | ||
${PYTHON_LIBRARIES} | ||
) | ||
|
||
SET_TARGET_PROPERTIES(spacetime_cython PROPERTIES | ||
PREFIX "" | ||
OUTPUT_NAME spacetime) | ||
|
||
INSTALL (TARGETS spacetime_cython | ||
DESTINATION "${PYTHON_DEST}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,2 @@ | ||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,8 @@ | ||
# Cython/distutils can only handle a single file as the source for | ||
# a python module. Since it is helpful to be able to split the binding | ||
# code into separate files, we just include them here. | ||
# | ||
# Note that the ordering of include statements may influence whether | ||
# things work or not | ||
|
||
include "spacetime_types.pyx" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,10 @@ | ||
from opencog.atomspace import get_refreshed_types | ||
from opencog.utilities import add_node, add_link | ||
|
||
cdef extern : | ||
void spacetime_types_init() | ||
|
||
spacetime_types_init() | ||
types = get_refreshed_types() | ||
|
||
include "opencog/spacetime/atom-types/spacetime_types.pyx" |