[segyio] 271/376: Add pycmake support

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit 2b2a0cf20b87438d96e1c7269100a29054f5cf98
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Wed Apr 19 09:30:17 2017 +0200

    Add pycmake support
    
    Use statoil/pycmake provided cmake files for cmake-python support.
    cmake-python integration is not specific for segyio at all, and is
    better maintained and reused as a separate project.
---
 .gitmodules                       |   3 +
 CMakeLists.txt                    |   1 +
 README.md                         |   5 +-
 appveyor.yml                      |   1 +
 cmake/find_python_module.cmake    |  27 ------
 cmake/python.cmake                | 152 ----------------------------------
 cmake/python_module_version.cmake | 168 --------------------------------------
 pycmake                           |   1 +
 python/CMakeLists.txt             |   5 +-
 9 files changed, 13 insertions(+), 350 deletions(-)

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..3226d54
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "pycmake"]
+	path = pycmake
+	url = https://github.com/statoil/pycmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9cfe4df..2e069da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
     set(WINDOWS TRUE)
 endif ()
 
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/pycmake)
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 include(check_includes)
 include(default_warnings)
diff --git a/README.md b/README.md
index 2199c29..c13235a 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ To build and use Segyio you need:
 To build and install Segyio, perform the following actions in your console:
 
 ```
-git clone https://github.com/Statoil/segyio
+git clone --recursive https://github.com/Statoil/segyio
 cd segyio
 mkdir build
 cd build
@@ -70,7 +70,8 @@ make install
 
 Make install must be done as root for a system install; if you want to install
 in your home directory, add `-DCMAKE_INSTALL_PREFIX=~/` or some other
-appropriate directory. Remember to update your $PATH!
+appropriate directory. Remember to update your $PATH! By default, only the
+python bindings are built.
 
 ##### Matlab support #####
 
diff --git a/appveyor.yml b/appveyor.yml
index a30ab38..5a463f6 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -28,6 +28,7 @@ init:
     - INSTALL_DIR: C:\projects\segyio-install
 
 install:
+  - git submodule update --init --recursive
   - IF DEFINED PYTHON (IF "%platform%" == "x64" SET PYTHON=%PYTHON%-x64)
   - IF DEFINED PYTHON %PYTHON%\python -m pip install --user numpy
 
diff --git a/cmake/find_python_module.cmake b/cmake/find_python_module.cmake
deleted file mode 100644
index aa48322..0000000
--- a/cmake/find_python_module.cmake
+++ /dev/null
@@ -1,27 +0,0 @@
-# Found from: github user ivansafrin
-#
-# Find if a Python module is installed
-# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
-# To use do: find_python_module(PyQt4 REQUIRED)
-function(find_python_module module)
-    string(TOUPPER ${module} module_upper)
-    if(NOT PY_${module_upper})
-        if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
-            set(${module}_FIND_REQUIRED TRUE)
-        endif()
-        # A module's location is usually a directory, but for binary modules
-        # it's a .so file.
-        execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
-                "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
-                RESULT_VARIABLE _${module}_status
-                OUTPUT_VARIABLE _${module}_location
-                ERROR_QUIET
-                OUTPUT_STRIP_TRAILING_WHITESPACE)
-
-        if(NOT _${module}_status)
-            set(PY_${module_upper} ${_${module}_location} CACHE STRING
-                    "Location of Python module ${module}")
-        endif()
-    endif(NOT PY_${module_upper})
-    find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
-endfunction(find_python_module)
\ No newline at end of file
diff --git a/cmake/python.cmake b/cmake/python.cmake
deleted file mode 100644
index ca61b25..0000000
--- a/cmake/python.cmake
+++ /dev/null
@@ -1,152 +0,0 @@
-include(find_python_module)
-include(python_module_version)
-include(CMakeParseArguments)
-
-find_package(PythonInterp)
-find_package(PythonLibs REQUIRED)
-
-if (EXISTS "/etc/debian_version")
-    set( PYTHON_PACKAGE_PATH "dist-packages")
-else()
-    set( PYTHON_PACKAGE_PATH "site-packages")
-endif()
-set(PYTHON_INSTALL_PREFIX "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_PACKAGE_PATH}" CACHE STRING "Subdirectory to install Python modules in")
-
-# 
-# usage: add_python_package(<target> <name>
-#                           [APPEND]
-#                           [SUBDIR <dir>] [PATH <path>]
-#                           [TARGETS <tgt>...] [SOURCES <src>...]
-#
-# Create a new target <target>, analogous to add_library. Creates a python
-# package <name>, optionally at the path specified with PATH. If SUBDIR <dir>
-# is used, then the files will be copied to $root/dir/*, in order to create
-# python sub namespaces - if subdir is not used then all files will be put in
-# $root/*. SOURCES <src> is the python files to be copied to the directory in
-# question, and <tgt> are regular cmake libraries (targets created by
-# add_library).
-#
-# Wuen the APPEND option is used, the files and targets given will be added
-# onto the same target package - it is necessary to use APPEND when you want
-# sub modules. Consider the package foo, with the sub module bar. In python,
-# you'd do: `from foo.bar import baz`. This means the directory structure is
-# `foo/bar/baz.py` in the package. This is accomplished with:
-# add_python_package(mypackage mypackage SOURCES __init__.py)
-# add_python_package(mypackage mypackage APPEND SOURCES baz.py)
-#
-# This command provides install targets, but no exports.
-function(add_python_package pkg NAME)
-    set(options APPEND)
-    set(unary PATH SUBDIR)
-    set(nary  TARGETS SOURCES)
-    cmake_parse_arguments(PP "${options}" "${unary}" "${nary}" "${ARGN}")
-
-    set(installpath ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/${NAME})
-
-    if (PP_PATH)
-        # obey an optional path to install into - but prefer the reasonable
-        # default of currentdir/name
-        set(dstpath ${PP_PATH})
-    else ()
-        set(dstpath ${NAME})
-    endif()
-
-    # if APPEND is passed, we *add* files/directories instead of creating it.
-    # this can be used to add sub directories to a package. If append is passed
-    # and the target does not exist - create it
-    if (TARGET ${pkg} AND NOT PP_APPEND)
-        set(problem "Target '${pkg}' already exists")
-        set(descr "To add more files to this package")
-        set(solution "${descr}, use add_python_package(<target> <name> APPEND)")
-        message(FATAL_ERROR "${problem}. ${solution}.")
-
-    elseif (NOT TARGET ${pkg})
-        add_custom_target(${pkg} ALL)
-
-        get_filename_component(abspath ${CMAKE_CURRENT_BINARY_DIR} ABSOLUTE)
-        set_target_properties(${pkg} PROPERTIES PACKAGE_INSTALL_PATH ${installpath})
-        set_target_properties(${pkg} PROPERTIES PACKAGE_BUILD_PATH ${abspath})
-    endif ()
-    # append subdir if requested
-    if (PP_SUBDIR)
-        set(dstpath ${dstpath}/${PP_SUBDIR})
-        set(installpath ${installpath}/${PP_SUBDIR})
-    endif ()
-
-    # copy all .py files into
-    foreach (file ${PP_SOURCES})
-        get_filename_component(absfile ${file} ABSOLUTE)
-        add_custom_command(TARGET ${pkg}
-            COMMAND ${CMAKE_COMMAND} -E make_directory ${dstpath}
-            COMMAND ${CMAKE_COMMAND} -E copy ${absfile} ${dstpath}/
-                )
-    endforeach ()
-
-    # targets are compiled as regular C/C++ libraries (via add_library), before
-    # we add some python specific stuff for the linker here.
-    if (MSVC)
-        # on windows, .pyd is used as extension instead of DLL
-        set(SUFFIX ".pyd")
-    elseif (APPLE)
-        # regular shared libraries on OS X are .dylib, but python wants .so
-        set(SUFFIX ".so")
-        # the spaces in LINK_FLAGS are important; otherwise APPEND_STRING to
-        # set_property seem to combine it with previously-set options or
-        # mangles it in some other way
-        set(LINK_FLAGS " -undefined dynamic_lookup ")
-    else()
-        set(LINK_FLAGS " -Xlinker -export-dynamic ")
-    endif()
-
-    # register all targets as python extensions
-    foreach (tgt ${PP_TARGETS})
-        set_target_properties(${tgt} PROPERTIES PREFIX "")
-        if (LINK_FLAGS)
-            set_property(TARGET ${tgt} APPEND_STRING PROPERTY LINK_FLAGS ${LINK_FLAGS})
-        endif()
-        if (SUFFIX)
-            set_property(TARGET ${tgt} APPEND_STRING PROPERTY SUFFIX ${SUFFIX})
-        endif()
-
-        # copy all targets into the package directory
-        add_custom_command(TARGET ${tgt} POST_BUILD
-            COMMAND ${CMAKE_COMMAND} -E make_directory ${dstpath}
-            COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${tgt}> ${dstpath}/
-        )
-    endforeach ()
-
-    if (NOT PP_SOURCES AND NOT PP_TARGETS AND NOT PP_APPEND)
-        message(FATAL_ERROR
-            "add_python_package called without .py files or C/C++ targets.")
-    endif()
-
-    if (PP_SOURCES)
-        install(FILES ${PP_SOURCES} DESTINATION ${installpath})
-    endif()
-
-    if (PP_TARGETS)
-        install(TARGETS ${PP_TARGETS} EXPORT ${pkg} DESTINATION ${installpath})
-    endif()
-endfunction()
-
-function(add_python_test TESTNAME PYTHON_TEST_FILE)
-    configure_file(${PYTHON_TEST_FILE} ${PYTHON_TEST_FILE} COPYONLY)
-    get_filename_component(name ${PYTHON_TEST_FILE} NAME)
-    get_filename_component(dir  ${PYTHON_TEST_FILE} DIRECTORY)
-
-    add_test(NAME ${TESTNAME}
-            COMMAND ${PYTHON_EXECUTABLE} -m unittest discover -vs ${dir} -p ${name}
-            )
-endfunction()
-
-function(add_python_example pkg TESTNAME PYTHON_TEST_FILE)
-    configure_file(${PYTHON_TEST_FILE} ${PYTHON_TEST_FILE} COPYONLY)
-
-    add_test(NAME ${TESTNAME}
-            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-            COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_TEST_FILE} ${ARGN})
-
-    get_target_property(buildpath ${pkg} PACKAGE_BUILD_PATH)
-    to_path_list(pythonpath "$ENV{PYTHONPATH}" ${buildpath})
-    set_tests_properties(${TESTNAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${pythonpath}")
-endfunction()
diff --git a/cmake/python_module_version.cmake b/cmake/python_module_version.cmake
deleted file mode 100644
index e3c830c..0000000
--- a/cmake/python_module_version.cmake
+++ /dev/null
@@ -1,168 +0,0 @@
-#  Copyright (C)  2016 Statoil ASA, Norway.
-#
-#  This file is part of ERT - Ensemble based Reservoir Tool.
-#
-#  ERT is free software: you can redistribute it and/or modify it under the
-#  terms of the GNU General Public License as published by the Free Software
-#  Foundation, either version 3 of the License, or (at your option) any later
-#  version.
-#
-#  ERT is distributed in the hope that it will be useful, but WITHOUT ANY
-#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-#  A PARTICULAR PURPOSE.
-#
-#  See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
-#  for more details
-
-
-
-# The basic assumption of this package is PEP 396 -- Module Version Numbers as
-# layed out in https://www.python.org/dev/peps/pep-0396/
-
-# Unfortunately, not all Python modules expose a version number, like inspect.
-# Other Python modules expose several version numbers, e.g. one for the
-# underlying software and one for the python packaging, like SQLite and PyQt.
-
-cmake_minimum_required (VERSION 2.8.1)
-
-
-
-# try import python module, if success, check its version, store as PY_module.
-# the module is imported as-is, hence the case (e.g. PyQt4) must be correct.
-#
-# if given a second argument, the accessor, we call accessor on the module
-# instead of the default __version__.
-#
-# (Yes, accessor could potentially be a function like "os.delete_everything()".)
-macro(python_module_version module)
-  set(PY_VERSION_ACCESSOR "__version__")
-  set(PY_module_name ${module})
-
-  if(${PY_module_name} STREQUAL "PyQt4")
-    set(PY_module_name "PyQt4.Qt")
-  endif()
-  if(${PY_module_name} STREQUAL "PyQt4.Qt")
-    set(PY_VERSION_ACCESSOR "PYQT_VERSION_STR")
-  endif()
-
-  if(${PY_module_name} STREQUAL "serial")
-    set(PY_VERSION_ACCESSOR "VERSION")
-  endif()
-
-  if(${PY_module_name} STREQUAL "sqlite")
-    set(PY_VERSION_ACCESSOR "version")
-  endif()
-
-
-  #  ARGUMENTS: module accessor
-  set (extra_macro_args ${ARGN})
-  list(LENGTH extra_macro_args num_extra_args)
-  if (${num_extra_args} GREATER 0)
-    list(GET extra_macro_args 0 accessor)
-    set(PY_VERSION_ACCESSOR ${accessor})
-  endif()
-
-  execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
-    "# set module's version to py_mv and print it
-import ${PY_module_name} as py_m
-py_mv = '0.0.0' # output if no accessor is found
-if hasattr(py_m, '${PY_VERSION_ACCESSOR}'):
-    py_mv = py_m.${PY_VERSION_ACCESSOR}
-print(py_mv)
-"
-    RESULT_VARIABLE _${module}_fail    # error code 0 if module is importable
-    OUTPUT_VARIABLE _${module}_version # module.accessor or "0.0.0" if no such
-    ERROR_VARIABLE stderr_output
-    OUTPUT_STRIP_TRAILING_WHITESPACE)
-  if(NOT _${module}_fail)
-    set(PY_${module} ${_${module}_version})
-  endif()
-
-  # clean up
-  unset(PY_VERSION_ACCESSOR)
-  unset(PY_module_name)
-  unset(extra_macro_args)
-endmacro()
-
-
-
-# If we find the correct module and new enough version, set PY_package, where
-# "package" is the given argument to the version we found else, display warning
-# and do not set any variables.
-macro(python_module package)
-
-  #  ARGUMENTS: package package_req module_version version_req accessor
-  set (extra_macro_args ${ARGN})
-  # Did we get any optional args?
-  list(LENGTH extra_macro_args num_extra_args)
-  if (${num_extra_args} GREATER 0)
-    list(GET extra_macro_args 0 package_req)
-  else()
-    set(package_req "REQUIRED") # requirement not set, is required
-  endif ()
-  if (${num_extra_args} GREATER 1)
-    list(GET extra_macro_args 1 module_version)
-  else()
-    set(module_version "0.0.0") # module_version not set, 0.0.0 is ok
-  endif ()
-  if (${num_extra_args} GREATER 2)
-    list(GET extra_macro_args 2 version_req)
-  else()
-    set(version_req "MINIMUM") # version requirement not set, is minimum
-  endif ()
-  if (${num_extra_args} GREATER 3)
-    list(GET extra_macro_args 3 accessor)
-  endif ()
-
-  # Setting warning/error output level
-  set(PY_MSG_ERR  SEND_ERROR)
-  set(PY_MSG_WARN WARNING)
-  if(${package_req} STREQUAL "QUIET")
-    set(PY_MSG_ERR  STATUS)
-    set(PY_MSG_WARN STATUS)
-  endif()
-
-  # We are done expanding the optional arguments
-
-  python_module_version(${package} ${accessor})
-
-  # package not found in system
-  if(NOT DEFINED PY_${package})
-    if(${package_req} STREQUAL "OPTIONAL")
-      message(${PY_MSG_WARN} "Could not find Python module " ${package})
-    else()
-      message(${PY_MSG_ERR} "Could not find Python module " ${package})
-    endif()
-
-  else()
-    # package found in system
-
-    if (${version_req} STREQUAL "EXACT" AND NOT ${PY_${package}} VERSION_EQUAL ${module_version})
-      message(${PY_MSG_ERR} "Python module ${package} not exact.  "
-        "Wanted EXACT ${module_version}, found ${PY_${package}}")
-    elseif (${version_req} STREQUAL "OPTIONAL" AND ${PY_${package}} VERSION_LESS ${module_version})
-      message(${PY_MSG_WARN} "Python module ${package} too old.  "
-        "Wanted ${module_version}, found ${PY_${package}}")
-    elseif (${version_req} STREQUAL "MINIMUM" AND ${PY_${package}} VERSION_LESS ${module_version})
-      message(${PY_MSG_ERR} "Python module ${package} too old.  "
-        "Wanted MINIMUM ${module_version}, found ${PY_${package}}")
-    else()
-      if(NOT DEFINED accessor)
-        message(STATUS "Found ${package}.  "
-                "${PY_${package}} >= ${module_version}")
-      else()
-        message(STATUS "Found ${package}.  "
-                "${PY_${package}} >= ${module_version} (" ${accessor} ")")
-      endif()
-    endif()
-  endif()
-
-  # clean up
-  unset(package_req)
-  unset(module_version)
-  unset(version_req)
-  unset(accessor)
-  unset(extra_macro_args)
-  set(PY_MSG_ERR)
-  set(PY_MSG_WARN)
-endmacro()
diff --git a/pycmake b/pycmake
new file mode 160000
index 0000000..2f87f47
--- /dev/null
+++ b/pycmake
@@ -0,0 +1 @@
+Subproject commit 2f87f47328453f19919aa44d1d9b8095f56f2b7b
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index fd322c8..66e839d 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -4,7 +4,10 @@ if (NOT BUILD_PYTHON)
     return()
 endif()
 
-include(python)
+find_package(PythonInterp REQUIRED)
+find_package(PythonLibs REQUIRED)
+include(FindPythonModule)
+include(PythonPackage)
 
 if (NOT DEFINED PYTHON_EXECUTABLE)
     message("Python interpreter not found - Python wrappers not enabled")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list