Skip to content
Snippets Groups Projects
Unverified Commit e62d100b authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Clean-up for code review (#28)

* Updated python setup

* Relicense to CC-0

* Moved to github actions

* Fixed license language

* Fix recipe cmake pin
parent e0bfc184
No related branches found
No related tags found
No related merge requests found
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
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
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
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.
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/>
......@@ -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))
```
......
......@@ -2,8 +2,8 @@ name: csmswig
channels:
- conda-forge
dependencies:
- cmake >= 3.10
- cmake >= 3.14
- csm
- python
- python >= 3
- pytest
- swig
- numpy
# 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
# 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()
......@@ -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'
)
......
#!/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 ..
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment