diff --git a/.github/workflows/ctests.yml b/.github/workflows/ctests.yml new file mode 100644 index 0000000000000000000000000000000000000000..9c37be7065730639579b2078d15dfa566c9e16e4 --- /dev/null +++ b/.github/workflows/ctests.yml @@ -0,0 +1,61 @@ +name: CMake + +on: [push, pull_request] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build-library: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + python-version: ["3.7", "3.8", "3.9", "3.10"] + defaults: + run: + shell: bash -l {0} + env: + SSPICE_DEBUG: y + steps: + - uses: actions/checkout@v2 + - uses: conda-incubator/setup-miniconda@v2 + with: + miniconda-version: "latest" + activate-environment: csmswig + environment-file: environment.yml + python-version: ${{ matrix.python-version }} + auto-activate-base: false + auto-update-conda: true + + - name: Conda info + run: | + conda info + conda list + + - name: Create Build Environment + # Some projects don't allow in-source building, so createa separate build directory + # we'll use it as our working directory for subsequent commands. + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build wrapper + working-directory: ${{github.workspace}}/build + # Execute the build. You can specify a specific target with "--target <NAME>" + run: cmake --build . --config $BUILD_TYPE + + - name: Install wrapper + working-directory: ${{github.workspace}}/build/python + # Execute the build. You can specify a specific target with "--target <NAME>" + run: python setup.py install + + - name: Test + working-directory: ${{github.workspace}}/build/python + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -VV -C $BUILD_TYPE \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e787474147293d3f86b54563b6e36528360331aa..0000000000000000000000000000000000000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -language: generic - -os: - - linux - - osx - -env: - - PYTHON_VERSION=3.5 - - PYTHON_VERSION=3.6 - - PYTHON_VERSION=3.7 - -before_install: - # Install a supported cmake version (>= 3.10) - - | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; - else - curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh; - fi - - bash miniconda.sh -b -p $HOME/miniconda - - export PATH="$HOME/miniconda/bin:$PATH" - - # Set up the env - - conda create -q -n test -y python=$PYTHON_VERSION - - source activate test - - # Add the necessary channels - - conda config --add channels usgs-astrogeology - - conda config --add channels conda-forge - -install: -# Setup to do the build - - conda env update -n test -f environment.yml - - conda install -c conda-forge -y pytest - - | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - conda install -y -c conda-forge/label/gcc7 python=$PYTHON_VERSION - conda install -y gcc_linux-64 gxx_linux-64; - else - conda install -y -c conda-forge python=$PYTHON_VERSION - fi - -script: - - mkdir build && cd build - - cmake .. && make - - cd python && python setup.py install && cd .. - - | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - pytest python/tests/ --lib fixture/libfixturecsm.so; - else - pytest python/tests/ --lib fixture/libfixturecsm.dylib; - fi - -after_success: - # - source deactivate - - conda install -y -q conda-build anaconda-client - - cd ../ # Step out of the python dir and out of the build dir - - if [ "${TRAVIS_PULL_REQUEST}" = "false" ] ;then - conda config --set anaconda_upload yes; - conda build --token $CONDA_UPLOAD_TOKEN --python $PYTHON_VERSION recipe -q; - else - conda build recipe -q; - fi diff --git a/CMakeLists.txt b/CMakeLists.txt index d81112e22a2db8b06ee3daf13ad3e387dcfd1c55..131f9c802ab6af972fadf23570fd2506b0decf23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) + +project(swigcsm VERSION 1.0.1 DESCRIPTION "SWIG wrappers for the Community Sensor Model API") find_package(SWIG REQUIRED) -include(${SWIG_USE_FILE}) +include(UseSWIG) add_subdirectory(python) add_subdirectory(fixture) \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000000000000000000000000000000000000..fa9472f6a5945ef306dc988644489972da88963a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,44 @@ +Unless otherwise noted, this project is in the public domain in the +United States. + +It contains materials that originally came from the United States +Geological Survey, an agency of the United States Department of +Interior. For more information on their copyright policies, see +https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits + +It also contains materials from contributors that have waived their +copyright interest to the public domain. + +Additionally, the authors waive copyright and related rights in the +work worldwide through the CC0 1.0 Universal public domain dedication. + +CC0 1.0 Universal Summary +------------------------- + +This is a human-readable summary of the [Legal Code (read the full +text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode). + + +### No Copyright + +The authors have associated their contributions to the swigcsm project +with this deed, and have dedicated the work to the public domain +by waiving all of their rights to the work worldwide under copyright +law, including all related and neighboring rights, to the extent +allowed by law. + +You can copy, modify, distribute and perform the work, even for +commercial purposes, all without asking permission. + + +### Other Information + +In no way are the patent or trademark rights of any person affected +by CC0, nor are the rights that other persons may have in the work +or in how the work is used, such as publicity or privacy rights. + +Unless expressly stated otherwise, the authors who have associated +the swigcsm project with this deed make no warranties about the work, +and disclaim liability for all uses of the work, to the fullest +extent permitted by applicable law. When using or citing the work, +you should not imply endorsement by the authors. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 68a49daad8ff7e35068f2b7a97d643aab440eaec..0000000000000000000000000000000000000000 --- a/LICENSE.txt +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to <http://unlicense.org/> diff --git a/README.md b/README.md index de115ff6390bea1e018b1b17c3f9edf14ce610c9..e8a573e3708c64891e32a3477d3c5c9e8b0f4ff9 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,19 @@ This repository contains SWIG wrappers for the CSM. The wrappers are currently only be created for Python, though many other languages can be supported. -## Building & Installing +## Building, Installing, and Testing - Ensure that the library is installed - (Optional) Install the USGS CSM_CameraModel libraries to ensure that this wrapper is able to do something. - mkdir build - cd build - cmake .. -- make +- cmake --build . - cd python - python setup.py install +- ctest -## +## Usage The CSM is designed so that plugins with a common insterface are dynamically loaded. This wrapper is designed to continue that philosophy. Therefore, loading an implementation of the interface is a little different than a @@ -25,12 +26,12 @@ import csmapi import ctypes # THis dynamically registers this plugin with the CSM API. -lib = ctypes.CDLL('path_to_the_libusgscsm.so') +lib = ctypes.CDLL('path_to_the_csm_plugin_library.so') # The two methods that are implemented are getList and findPlugin plugin_list = csmapi.Plugin.getList() -# Should be 2 assuming the USGS CSM-CameraModel was used +# Should be greater than 0 print(len(plugin_list)) ``` diff --git a/environment.yml b/environment.yml index 611d6f01873bb232c8f786c8172fdcd2704077b9..74f70fe8a921831835a715d7e8c1d9e248c07483 100644 --- a/environment.yml +++ b/environment.yml @@ -2,8 +2,8 @@ name: csmswig channels: - conda-forge dependencies: - - cmake >= 3.10 + - cmake >= 3.14 - csm - - python + - python >= 3 + - pytest - swig - - numpy diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 06a458ba1a19b39adc27c9262f7c86b6fe7ee937..1c9e0a97afeafdd86e0ed6aa36e5a0b4911373ae 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,18 +1,14 @@ -# Include python -include(FindPythonAnaconda.cmake) -include_directories(${PYTHON_INCLUDE_DIR}) - set(CMAKE_SWIG_FLAGS "") +list(APPEND CMAKE_SWIG_FLAGS "-py3;-DPY3") set(CMAKE_SWIG_OUTDIR csmapi) set_source_files_properties(../csmapi.i PROPERTIES CPLUSPLUS ON) #Find dependencies +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) find_path(CSM_INCLUDE_DIR NAMES csm.h - PATH_SUFFIXES csm - PATHS ${PYTHON_INCLUDE_DIR}/../) -find_library(CSM_LIBRARY NAMES csmapi - PATHS ${PYTHON_LIBRARY}/../) + PATH_SUFFIXES csm) +find_library(CSM_LIBRARY NAMES csmapi) message("-- Found CSM Include: ${CSM_INCLUDE_DIR}") message("-- Found CSM Lib: ${CSM_LIBRARY}") include_directories(${CSM_INCLUDE_DIR}) @@ -21,17 +17,15 @@ include_directories(${CSM_INCLUDE_DIR}) swig_add_library(csmapi LANGUAGE python SOURCES ../csmapi.i) +swig_link_libraries(csmapi ${CSM_LIBRARY} Python3::Module) +set_property(TARGET csmapi PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) -set_target_properties(_csmapi PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR}) +set_target_properties(csmapi PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR}) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") if (APPLE) - set_target_properties(_csmapi PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") - # On OSX, do not link python - this causes segfaults - swig_link_libraries(csmapi ${CSM_LIBRARY}) -else() - swig_link_libraries(csmapi ${CSM_LIBRARY} ${PYTHON_LIBRARY}) + set_target_properties(csmapi PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") endif() # Build out a standard directory structure @@ -39,12 +33,13 @@ endif() # Move the static files to move configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/setup.py - COPYONLY) + ${CMAKE_CURRENT_BINARY_DIR}/setup.py) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/csmapi/__init__.py COPYONLY) -# Move the tests -file(COPY ${CMAKE_SOURCE_DIR}/python/tests - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +# Setup the tests +enable_testing() +add_test(NAME python-wrapper-tests + COMMAND python -m pytest ${CMAKE_SOURCE_DIR}/python/tests --lib ${CMAKE_CURRENT_BINARY_DIR}/../fixture/libfixturecsm${CMAKE_SHARED_LIBRARY_SUFFIX} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file diff --git a/python/FindPythonAnaconda.cmake b/python/FindPythonAnaconda.cmake deleted file mode 100644 index d59ada6542a752d469c5e61835df678a3d245617..0000000000000000000000000000000000000000 --- a/python/FindPythonAnaconda.cmake +++ /dev/null @@ -1,102 +0,0 @@ -# tested on OSX Yosemite and Ubuntu 14.04 LTS -# handle anaconda dependencies -cmake_minimum_required(VERSION 3.7) - -option(ANACONDA_PYTHON_VERBOSE "Anaconda dependency info" OFF) - -if(NOT CMAKE_FIND_ANACONDA_PYTHON_INCLUDED) - set(CMAKE_FIND_ANACONDA_PYTHON_INCLUDED 1) - - # find anaconda installation - set(_cmd conda info --root) - execute_process( - COMMAND ${_cmd} - RESULT_VARIABLE _r - OUTPUT_VARIABLE _o - ERROR_VARIABLE _e - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE - ) - - if(ANACONDA_PYTHON_VERBOSE) - message("Executing conda info --root") - message("_r = ${_r}") - message("_o = ${_o}") - message("_e = ${_e}") - endif() - - IF(IS_DIRECTORY ${_o}) - set(ANACONDA_PYTHON_FOUND True) - endif() - - if(ANACONDA_PYTHON_FOUND) - set( ANACONDA_PYTHON_DIR ${_o} ) - message( "Found anaconda root directory ${ANACONDA_PYTHON_DIR}" ) - - # find python version - # - set(_cmd python --version) - execute_process( - COMMAND ${_cmd} - RESULT_VARIABLE _r - OUTPUT_VARIABLE _o - ERROR_VARIABLE _o - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE - ) - - if(ANACONDA_PYTHON_VERBOSE) - message("Executing python --version") - message("_r = ${_r}") - # Different python version pipe to stdout vs. stderr - message("_o = ${_o}") - message("_e = ${_o}") - endif() - - string (REGEX MATCH "Python ([0-9]+)[.]([0-9]+)[.]([0-9]+)" _py_version_found "${_o}") - #message("_py_version_found = ${_py_version_found}") - #message("CMAKE_MATCH_0 = ${CMAKE_MATCH_0}") - set( _py_version_major ${CMAKE_MATCH_1} ) - set( _py_version_minor ${CMAKE_MATCH_2} ) - set( _py_version_patch ${CMAKE_MATCH_3} ) - set( ANACONDA_PYTHON_VERSION ${_py_version_major}.${_py_version_minor} ) - - - if( (${_py_version_major} MATCHES 2) OR - (${_py_version_major} MATCHES 3 AND ${_py_version_minor} MATCHES 8) ) - set( _py_ext "") - else() - set( _py_ext "m") - endif() - - set(_py_id "python${ANACONDA_PYTHON_VERSION}${_py_ext}") - - if( NOT DEFINED ENV{CONDA_PREFIX} ) - set( env_CONDA_DEFAULT_ENV "root" ) - message( WARNING "Could not find anaconda environment setting; using default root" ) - else() - set( env_CONDA_DEFAULT_ENV $ENV{CONDA_PREFIX} ) - endif() - - message( "Using anaconda ${env_CONDA_DEFAULT_ENV} environment" ) - if( env_CONDA_DEFAULT_ENV STREQUAL "root" ) - set(PYTHON_INCLUDE_DIR "${ANACONDA_PYTHON_DIR}/include/${_py_id}" CACHE INTERNAL "") - set(PYTHON_LIBRARY "${ANACONDA_PYTHON_DIR}/lib/lib${_py_id}${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "") - else() - set(PYTHON_INCLUDE_DIR "${env_CONDA_DEFAULT_ENV}/include/${_py_id}" CACHE INTERNAL "") - set(PYTHON_LIBRARY "${env_CONDA_DEFAULT_ENV}/lib/lib${_py_id}${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "") - endif() - - set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") - set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") - - set(FOUND_PYTHONLIBS TRUE) - else() - message( "Not found: anaconda root directory..." ) - message( "Trying system python install..." ) - FindPythonLibs() - endif() - - message( "PYTHON_INCLUDE_DIR = ${PYTHON_INCLUDE_DIR}") - message( "PYTHON_LIBRARY = ${PYTHON_LIBRARY}") -endif() diff --git a/python/setup.py.in b/python/setup.py.in index 19bf5733650c0f5828abbf51a74e6a788a5dbe75..a406f11e871edd6ce464f8cccbadc2d911b71be2 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -3,11 +3,11 @@ import setuptools if __name__ == '__main__': setuptools.setup( name='csmapi', - version='0.1.0', + version='${CMAKE_PROJECT_VERSION}', packages=['csmapi'], package_data={'':['_csmapi.so']}, zip_safe=False, # Some OSes can not dynamically load an so from an egg (zipfile) - license='UnLicense', + license='CC0-1.0', author='jlaura', author_email='jlaura@usgs.gov' ) diff --git a/recipe/build.sh b/recipe/build.sh index 316b747f7b97472bd8b13a2b0ee0ca30db2e57ed..9ca05955d0e4da319b7a7c8c1275a519bfc8a8a4 100644 --- a/recipe/build.sh +++ b/recipe/build.sh @@ -1,8 +1,8 @@ #!/bin/bash mkdir -p build && cd build -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DANACONDA_PYTHON_VERBOSE=ON .. -make +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .. +cmake --build . cd python $PYTHON setup.py install --single-version-externally-managed --record=/tmp/record.txt cd .. diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 5bb357230889414c5d9a8d3ec73ce3bd2e6ac290..0da5eaa003f66a3821145cef8b037bfad582c79a 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -11,16 +11,14 @@ build: requirements: build: - {{ compiler('cxx') }} # [linux] - - cmake >=3.10 + - cmake >=3.14 + - swig - python host: - - csm - - python - - swig + - python >= 3 run: - csm - - python - - numpy + - python test: imports: @@ -28,5 +26,6 @@ test: about: home: https://github.com/USGS-Astrogeology/CSM-Swig - license: None -summary: "SWIG Wrapper to generate bindings to the Community Sensor Model" + license: CC0-1.0 + license_file: LICENSE.md + summary: "SWIG Wrapper to generate bindings to the Community Sensor Model"