diff --git a/CMakeLists.txt b/CMakeLists.txt index 907d9100..c825aad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,22 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) include(VersionSource) find_package(GEOS REQUIRED) +if (GEOS_VERSION_MAJOR LESS 3 OR GEOS_VERSION_MINOR LESS 5) + message(FATAL_ERROR "GEOS version 3.5 or later is required.") +endif() + +message(STATUS "Source version: " ${EXACTEXTRACT_VERSION_SOURCE}) +set(SRC_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/generated) +configure_file(src/version.h.in ${SRC_GENERATED}/version.h) + +# Define coverage build type +set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-arcs -ftest-coverage") + +# Make sure we know our build type +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified") + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}") +endif() #Configure some options the various components this module can build option(BUILD_CLI "Build the exactextract cli binary" ON) #requires gdal, cli11 @@ -85,7 +101,7 @@ if(BUILD_CLI) subdivide PRIVATE ${GDAL_INCLUDE_DIR} - ${CMAKE_BINARY_DIR}/generated + ${SRC_GENERATED} ) target_link_libraries( @@ -98,7 +114,7 @@ if(BUILD_CLI) target_include_directories( ${BIN_NAME} PRIVATE - ${CMAKE_BINARY_DIR}/generated + ${SRC_GENERATED} ${CMAKE_SOURCE_DIR}/src ) @@ -178,21 +194,6 @@ if(BUILD_TEST) endif() #BUILD_TEST -message(STATUS "Source version: " ${EXACTEXTRACT_VERSION_SOURCE}) -configure_file(src/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h) - -if (GEOS_VERSION_MAJOR LESS 3 OR GEOS_VERSION_MINOR LESS 5) - message(FATAL_ERROR "GEOS version 3.5 or later is required.") -endif() - -# Define coverage build type -set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-arcs -ftest-coverage") - -# Make sure we know our build type -if(NOT CMAKE_BUILD_TYPE) - message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified") - set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}") -endif() set(PROJECT_SOURCES src/measures.cpp @@ -249,7 +250,7 @@ set(PROJECT_SOURCES src/weighted_quantiles.h src/weighted_quantiles.cpp src/variance.h - ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h + ${SRC_GENERATED}/version.h ) add_library(${LIB_NAME} ${PROJECT_SOURCES}) diff --git a/cmake/VersionSource.cmake b/cmake/VersionSource.cmake index 2601b74c..2848723a 100644 --- a/cmake/VersionSource.cmake +++ b/cmake/VersionSource.cmake @@ -33,5 +33,7 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD) endif() endif() +message("exactextract version: ${EXACTEXTRACT_VERSION_SOURCE}") + unset(dirty) unset(head) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 826b522f..1b1bdcbd 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -22,14 +22,16 @@ src/pybindings/processor_bindings.h src/pybindings/raster_source_bindings.cpp src/pybindings/raster_source_bindings.h src/pybindings/writer_bindings.cpp -src/pybindings/writer_bindings.h) +src/pybindings/writer_bindings.h +) pybind11_add_module(_exactextract MODULE ${PYBIND_SOURCES}) target_include_directories(_exactextract PRIVATE ${CMAKE_SOURCE_DIR}/src + ${SRC_GENERATED} ${GEOS_INCLUDE_DIR}) - set_property(TARGET ${LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) - target_link_libraries(_exactextract PRIVATE ${LIB_NAME} ${GEOS_LIBRARY}) +set_property(TARGET ${LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) +target_link_libraries(_exactextract PRIVATE ${LIB_NAME} ${GEOS_LIBRARY}) add_test(NAME "pybindings" COMMAND ${CMAKE_COMMAND} -E env diff --git a/python/project.ini b/python/project.ini index 05d66aad..0befb3f6 100644 --- a/python/project.ini +++ b/python/project.ini @@ -6,5 +6,4 @@ url = https://github.com/isciences/exactextract title = exactextract Documentation description = Fast and accurate raster zonal statistics long_description = exactextract provides a fast and accurate algorithm for summarizing values in the portion of a raster dataset that is covered by a polygon, often referred to as zonal statistics. Unlike other zonal statistics implementations, it takes into account raster cells that are partially covered by the polygon. -version = 0.2.0 tag = diff --git a/python/setup.py b/python/setup.py index 44f05fb8..7997ae1a 100644 --- a/python/setup.py +++ b/python/setup.py @@ -79,6 +79,15 @@ def move_output(self, ext): self.copy_file(str(source_path), str(dest_path)) +def find_version(): + version_script = os.path.abspath( + os.path.join(os.path.dirname(__file__), os.pardir, 'cmake', 'VersionSource.cmake')) + version = subprocess.run(['cmake', '-P', version_script], + capture_output=True, + text=True).stderr.split(':')[1].strip() + print(f"Version: {version}") + return version + # The information here can also be placed in setup.cfg - better separation of # logic and declaration, and simpler if you include description/version in a file. @@ -92,8 +101,8 @@ def move_output(self, ext): url = config['base']['url'] title = config['base']['title'] description = config['base']['description'] -version = config['base']['version'] tag = config['base']['tag'] +version = find_version() setup( name=project, diff --git a/python/src/exactextract/__init__.py b/python/src/exactextract/__init__.py index d3a972be..52bd26d1 100644 --- a/python/src/exactextract/__init__.py +++ b/python/src/exactextract/__init__.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Python bindings for exactextract """ +from _exactextract import __version__ from .exact_extract import exact_extract from .feature import Feature, GDALFeature, JSONFeature diff --git a/python/src/pybindings/bindings.cpp b/python/src/pybindings/bindings.cpp index 25aab05d..c501dc8a 100644 --- a/python/src/pybindings/bindings.cpp +++ b/python/src/pybindings/bindings.cpp @@ -18,6 +18,7 @@ #include "operation_bindings.h" #include "processor_bindings.h" #include "raster_source_bindings.h" +#include "version.h" #include "writer_bindings.h" namespace py = pybind11; @@ -25,6 +26,8 @@ namespace py = pybind11; namespace exactextract { PYBIND11_MODULE(_exactextract, m) { + m.attr("__version__") = version(); + bind_feature(m); bind_feature_source(m); bind_raster_source(m); diff --git a/python/tests/test_version.py b/python/tests/test_version.py new file mode 100644 index 00000000..df06e8f3 --- /dev/null +++ b/python/tests/test_version.py @@ -0,0 +1,6 @@ +import exactextract +import re + +def test_version(): + + assert re.match('[0-9]+[.][0-9]+[.][0-9]+', exactextract.__version__)