Skip to content
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

Python3 fixes (maintains python2 compatibility) #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ find_package(Conda)
if(CONDA_PREFIX)
message(STATUS "Set CONDA_PREFIX ${CONDA_PREFIX}")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CONDA_PREFIX})
set(Python_FIND_STRATEGY LOCATION) # might want to prefer conda over system python
else()
message(STATUS "Non conda exist, search library in default path")
endif()
Expand Down
11 changes: 6 additions & 5 deletions example/python/fmm_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
from fmm import Network,NetworkGraph,STMATCH,STMATCHConfig
network = Network("../data/edges.shp")
graph = NetworkGraph(network)
print graph.get_num_vertices()
print(graph.get_num_vertices())
model = STMATCH(network,graph)
wkt = "LINESTRING(0.200812146892656 2.14088983050848,1.44262005649717 2.14879943502825,3.06408898305084 2.16066384180791,3.06408898305084 2.7103813559322,3.70872175141242 2.97930790960452,4.11606638418078 2.62337570621469)"
config = STMATCHConfig()
Expand All @@ -11,7 +12,7 @@
config.vmax = 30;
config.factor =1.5
result = model.match_wkt(wkt,config)
print type(result)
print "Opath ",list(result.opath)
print "Cpath ",list(result.cpath)
print "WKT ",result.mgeom.export_wkt()
print(type(result))
print("Opath ",list(result.opath))
print("Cpath ",list(result.cpath))
print("WKT ",result.mgeom.export_wkt())
27 changes: 11 additions & 16 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,32 @@ else()
message(FATAL_ERROR "Swig not found!\n")
endif()

find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
if (PYTHONLIBS_FOUND)
message(STATUS "Python header found at ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Python library found at ${PYTHON_LIBRARIES}")
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Python COMPONENTS Interpreter Development)
if (Python_FOUND)
message(STATUS "Python header found at ${Python_INCLUDE_DIRS}")
message(STATUS "Python library found at ${Python_LIBRARIES}")
message(STATUS "Python packages ${Python_SITELIB}")
include_directories(${Python_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Python library not found!\n")
endif()

execute_process(
COMMAND python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Python packages ${PYTHON_SITE_PACKAGES}")

set_source_files_properties(
${PROJECT_SOURCE_DIR}/python/fmm.i PROPERTIES CPLUSPLUS ON)

if (${CMAKE_VERSION} VERSION_LESS 3.13.0)
message(STATUS "Using swig add module")
SWIG_ADD_MODULE(fmm python ${PROJECT_SOURCE_DIR}/python/fmm.i)
swig_link_libraries(fmm FMMLIB ${PYTHON_LIBRARIES})
install(TARGETS ${SWIG_MODULE_fmm_REAL_NAME} DESTINATION ${PYTHON_SITE_PACKAGES})
swig_link_libraries(fmm FMMLIB ${Python_LIBRARIES})
install(TARGETS ${SWIG_MODULE_fmm_REAL_NAME} DESTINATION ${Python_SITELIB})
else()
message(STATUS "Using swig add library")
SWIG_ADD_LIBRARY(pyfmm
LANGUAGE python
SOURCES ${PROJECT_SOURCE_DIR}/python/fmm.i)
set_property(TARGET pyfmm PROPERTY OUTPUT_NAME fmm)
swig_link_libraries(pyfmm FMMLIB ${PYTHON_LIBRARIES})
install(TARGETS pyfmm DESTINATION ${PYTHON_SITE_PACKAGES})
target_link_libraries(pyfmm FMMLIB Python::Module)
install(TARGETS pyfmm DESTINATION ${Python_SITELIB})
endif()

install(FILES ${CMAKE_BINARY_DIR}/python/fmm.py DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_BINARY_DIR}/python/fmm.py DESTINATION ${Python_SITELIB})