Permalink
Browse files

Merge pull request #5645 from geographika/python-mapscript-build2

Updated Python MapScript Build Process
  • Loading branch information...
geographika committed Aug 31, 2018
2 parents edf9693 + 421b0cb commit 04f8fc0a16fc6d5327f1fc930cca33f10be88caf
View
@@ -61,6 +61,7 @@ before_install:
script:
- make -j4 test
- make mspython-wheel
after_success:
# Only run coverage when it is safe to do so (not on pull requests), and only on master branch
View
@@ -37,6 +37,9 @@ query-testcase:
mspython-testcase:
test -f "$(PYTHON_MAPSCRIPT_PATH)/_mapscript.so" && (export PYTHONPATH="../../$(PYTHON_MAPSCRIPT_PATH)" && cd msautotest/mspython && python run_all_tests.py)
mspython-wheel:
cd build && cmake --build . --target pythonmapscript-wheel
php-testcase:
test -f "$(PHP_MAPSCRIPT)" && (export PHP_MAPSCRIPT_SO="../../$(PHP_MAPSCRIPT)" && cd msautotest/php && ./run_test.sh)
View
@@ -51,7 +51,8 @@ test_script:
- set PATH=%BUILD_FOLDER%/build/Release;%BUILD_FOLDER%/sdk/%SDK%/bin;%PATH%
- set PROJ_LIB=%BUILD_FOLDER%/sdk/%SDK%/bin/proj/SHARE
- set PYTHONPATH=%BUILD_FOLDER%/build/mapscript/python/Release;%BUILD_FOLDER%/build/mapscript/python
- cd %BUILD_FOLDER%/mapscript/python
- "%PYTHON_EXECUTABLE% -m pytest --ignore=tests/cases/fonttest.py --ignore=tests/cases/hashtest.py --ignore=tests/cases/pgtest.py --ignore=tests/cases/threadtest.py tests/cases"
- cd %BUILD_FOLDER%
- set TESTS_FOLDER=%BUILD_FOLDER%/mapscript/python/tests/cases
- "%PYTHON_EXECUTABLE% -m pytest --ignore=%TESTS_FOLDER%/fonttest.py --ignore=%TESTS_FOLDER%/hashtest.py --ignore=%TESTS_FOLDER%/pgtest.py --ignore=%TESTS_FOLDER%/threadtest.py %TESTS_FOLDER%"
deploy: off
@@ -1,7 +1,6 @@
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonInterp)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonInterp)
# Python library/header finding doesn't seem to honor the python
# interpreter that was found beforehand, and defaults to the system
@@ -21,27 +20,65 @@ find_library(PYTHON_LIBRARIES
#if that failed, fall back to the default cmake method of finding python dev files
if(NOT PYTHON_INCLUDE_PATH OR NOT PYTHON_LIBRARIES)
FIND_PACKAGE(PythonLibs)
find_package(PythonLibs)
endif(NOT PYTHON_INCLUDE_PATH OR NOT PYTHON_LIBRARIES)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${PROJECT_SOURCE_DIR}/mapscript/swiginc)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/python)
SWIG_ADD_MODULE(pythonmapscript python ../mapscript.i)
SWIG_LINK_LIBRARIES(pythonmapscript ${PYTHON_LIBRARIES} ${MAPSERVER_LIBMAPSERVER})
if (${PYTHON_VERSION_MAJOR} GREATER 2)
set_property(SOURCE ../mapscript.i PROPERTY SWIG_FLAGS "-py3")
endif (${PYTHON_VERSION_MAJOR} GREATER 2)
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
swig_add_library(pythonmapscript TYPE MODULE LANGUAGE python SOURCES ../mapscript.i)
else (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
swig_add_module(pythonmapscript python ../mapscript.i)
endif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
swig_link_libraries(pythonmapscript ${PYTHON_LIBRARIES} ${MAPSERVER_LIBMAPSERVER})
set_target_properties(${SWIG_MODULE_pythonmapscript_REAL_NAME} PROPERTIES PREFIX "")
set_target_properties(${SWIG_MODULE_pythonmapscript_REAL_NAME} PROPERTIES OUTPUT_NAME _mapscript)
execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SETUP_PY_IN "${PROJECT_SOURCE_DIR}/mapscript/python/setup.py.in")
set(SETUP_PY_TEMP "${CMAKE_CURRENT_BINARY_DIR}/setup.py.temp")
configure_file(${SETUP_PY_IN} ${SETUP_PY_TEMP} @ONLY)
file(READ ${SETUP_PY_TEMP} SETUP_CONTENT)
# each target (e.g. Debug, Release etc.) will have a copy of setup.py
file(GENERATE OUTPUT $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/setup.py INPUT ${SETUP_PY_TEMP})
set(BUILD_TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
set(TESTS_FOLDER ${PROJECT_SOURCE_DIR}/mapscript/python/tests/cases)
add_custom_target(pythonmapscript-wheel DEPENDS ${SWIG_MODULE_pythonmapscript_REAL_NAME} )
# copy all Python files to the output folder following build, and create a wheel
add_custom_command(
TARGET pythonmapscript-wheel POST_BUILD
if (WIN32)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
else()
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
endif()
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
COMMAND ${PYTHON_EXECUTABLE} -m pip install -r ${PROJECT_SOURCE_DIR}/mapscript/python/requirements-dev.txt
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/mapscript/python/mapscript" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/mapscript.py" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/mapscript.py
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${SWIG_MODULE_pythonmapscript_REAL_NAME}>" "$<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/$<TARGET_FILE_NAME:${SWIG_MODULE_pythonmapscript_REAL_NAME}>"
COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/mapscript/python/README.rst" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/README.rst
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/mapscript/python/examples" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/examples
COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index --find-links=${CMAKE_CURRENT_BINARY_DIR}/dist mapscript
COMMAND ${PYTHON_EXECUTABLE} -m pytest --ignore=${TESTS_FOLDER}/fonttest.py --ignore=${TESTS_FOLDER}/hashtest.py --ignore=${TESTS_FOLDER}/pgtest.py --ignore=${TESTS_FOLDER}/threadtest.py ${TESTS_FOLDER}/
)
get_target_property(LOC_MAPSCRIPT_LIB ${SWIG_MODULE_pythonmapscript_REAL_NAME} LOCATION)
set(mapscript_files ${LOC_MAPSCRIPT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/mapscript.py)
set(mapscript_files $<TARGET_FILE:${SWIG_MODULE_pythonmapscript_REAL_NAME}> $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/mapscript.py)
install(FILES ${mapscript_files} DESTINATION ${PYTHON_SITE_PACKAGES})
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mapscript.py DESTINATION ${PYTHON_SITE_PACKAGES})
#install(TARGETS mapscript DESTINATION ${PYTHON_SITE_PACKAGES})
View

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 04f8fc0

Please sign in to comment.