restore compiled modules to the plugins branch

This commit is contained in:
Emily Soth 2025-05-08 14:38:09 -07:00
parent c3fe609d4a
commit bf1726ec88
8 changed files with 63 additions and 89 deletions

View File

@ -132,22 +132,21 @@ jobs:
NATCAP_INVEST_GDAL_LIB_PATH="$CONDA_PREFIX/Library" python -m build --wheel
ls -la dist
# Uncomment this when we uncomment the C++ extensions
# # This produces a wheel that should work on any distro with glibc>=2.39.
# # This is a very recent version. If we want to support older versions, I
# # suspect we would need to build GDAL from source on an appropriate
# # system (such as a manylinux docker container) to ensure compatibility.
# # Symbols used in libgdal are the cause of the high minimum version,
# # possibly because of installing with conda.
# - name: Audit and repair wheel for manylinux
# if: matrix.os == 'ubuntu-latest'
# run: |
# ldd --version
# pip install auditwheel
# WHEEL=$(find dist -name "natcap[._-]invest*.whl")
# auditwheel show $WHEEL
# auditwheel repair $WHEEL --plat manylinux_2_39_x86_64 -w dist
# rm $WHEEL # remove the original wheel
# This produces a wheel that should work on any distro with glibc>=2.39.
# This is a very recent version. If we want to support older versions, I
# suspect we would need to build GDAL from source on an appropriate
# system (such as a manylinux docker container) to ensure compatibility.
# Symbols used in libgdal are the cause of the high minimum version,
# possibly because of installing with conda.
- name: Audit and repair wheel for manylinux
if: matrix.os == 'ubuntu-latest'
run: |
ldd --version
pip install auditwheel
WHEEL=$(find dist -name "natcap[._-]invest*.whl")
auditwheel show $WHEEL
auditwheel repair $WHEEL --plat manylinux_2_39_x86_64 -w dist
rm $WHEEL # remove the original wheel
- name: Install wheel and run model tests
run: |

View File

@ -16,27 +16,26 @@ _REQUIREMENTS = [req.split(';')[0].split('#')[0].strip() for req in
and len(req.strip()) > 0)]
include_dirs = [numpy.get_include(), 'src/natcap/invest/managed_raster']
# Commenting out for plugin development
# if platform.system() == 'Windows':
# compiler_args = ['/std:c++20']
# compiler_and_linker_args = []
# if 'NATCAP_INVEST_GDAL_LIB_PATH' not in os.environ:
# raise RuntimeError(
# 'env variable NATCAP_INVEST_GDAL_LIB_PATH is not defined. '
# 'This env variable is required when building on Windows. If '
# 'using conda to manage your gdal installation, you may set '
# 'NATCAP_INVEST_GDAL_LIB_PATH="$CONDA_PREFIX/Library".')
# library_dirs = [f'{os.environ["NATCAP_INVEST_GDAL_LIB_PATH"]}/lib']
# include_dirs.append(f'{os.environ["NATCAP_INVEST_GDAL_LIB_PATH"]}/include')
# else:
# compiler_args = [subprocess.run(
# ['gdal-config', '--cflags'], capture_output=True, text=True
# ).stdout.strip()]
# compiler_and_linker_args = ['-std=c++20']
# library_dirs = [subprocess.run(
# ['gdal-config', '--libs'], capture_output=True, text=True
# ).stdout.split()[0][2:]] # get the first argument which is the library path
if platform.system() == 'Windows':
compiler_args = ['/std:c++20']
compiler_and_linker_args = []
if 'NATCAP_INVEST_GDAL_LIB_PATH' not in os.environ:
raise RuntimeError(
'env variable NATCAP_INVEST_GDAL_LIB_PATH is not defined. '
'This env variable is required when building on Windows. If '
'using conda to manage your gdal installation, you may set '
'NATCAP_INVEST_GDAL_LIB_PATH="$CONDA_PREFIX/Library".')
library_dirs = [f'{os.environ["NATCAP_INVEST_GDAL_LIB_PATH"]}/lib']
include_dirs.append(f'{os.environ["NATCAP_INVEST_GDAL_LIB_PATH"]}/include')
else:
compiler_args = [subprocess.run(
['gdal-config', '--cflags'], capture_output=True, text=True
).stdout.strip()]
compiler_and_linker_args = ['-std=c++20']
library_dirs = [subprocess.run(
['gdal-config', '--libs'], capture_output=True, text=True
).stdout.split()[0][2:]] # get the first argument which is the library path
class build_py(_build_py):
"""Command to compile translation message catalogs before building."""
@ -60,35 +59,35 @@ class build_py(_build_py):
setup(
install_requires=_REQUIREMENTS,
# ext_modules=cythonize([
# Extension(
# name=f'natcap.invest.{package}.{module}',
# sources=[f'src/natcap/invest/{package}/{module}.pyx'],
# include_dirs=include_dirs,
# extra_compile_args=compiler_args + package_compiler_args + compiler_and_linker_args,
# extra_link_args=compiler_and_linker_args,
# language='c++',
# libraries=['gdal'],
# library_dirs=library_dirs,
# define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
# ) for package, module, package_compiler_args in [
# ('delineateit', 'delineateit_core', []),
# ('recreation', 'out_of_core_quadtree', []),
# # clang-14 defaults to -ffp-contract=on, which causes the
# # arithmetic of A*B+C to be implemented using a contraction, which
# # causes an unexpected change in the precision in some viewshed
# # tests on ARM64 (mac M1). See these issues for more details:
# # * https://github.com/llvm/llvm-project/issues/91824
# # * https://github.com/natcap/invest/issues/1562
# # * https://github.com/natcap/invest/pull/1564/files
# # Using this flag on gcc and on all versions of clang should work
# # as expected, with consistent results.
# ('scenic_quality', 'viewshed', ['-ffp-contract=off']),
# ('ndr', 'ndr_core', []),
# ('sdr', 'sdr_core', []),
# ('seasonal_water_yield', 'seasonal_water_yield_core', [])
# ]
# ], compiler_directives={'language_level': '3'}),
ext_modules=cythonize([
Extension(
name=f'natcap.invest.{package}.{module}',
sources=[f'src/natcap/invest/{package}/{module}.pyx'],
include_dirs=include_dirs,
extra_compile_args=compiler_args + package_compiler_args + compiler_and_linker_args,
extra_link_args=compiler_and_linker_args,
language='c++',
libraries=['gdal'],
library_dirs=library_dirs,
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
) for package, module, package_compiler_args in [
('delineateit', 'delineateit_core', []),
('recreation', 'out_of_core_quadtree', []),
# clang-14 defaults to -ffp-contract=on, which causes the
# arithmetic of A*B+C to be implemented using a contraction, which
# causes an unexpected change in the precision in some viewshed
# tests on ARM64 (mac M1). See these issues for more details:
# * https://github.com/llvm/llvm-project/issues/91824
# * https://github.com/natcap/invest/issues/1562
# * https://github.com/natcap/invest/pull/1564/files
# Using this flag on gcc and on all versions of clang should work
# as expected, with consistent results.
('scenic_quality', 'viewshed', ['-ffp-contract=off']),
('ndr', 'ndr_core', []),
('sdr', 'sdr_core', []),
('seasonal_water_yield', 'seasonal_water_yield_core', [])
]
], compiler_directives={'language_level': '3'}),
include_dirs=[numpy.get_include()],
cmdclass={
'build_py': build_py

View File

@ -25,10 +25,6 @@ REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
'delineateit')
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
@contextlib.contextmanager
def capture_logging(logger, level=logging.NOTSET):
"""Capture logging within a context manager.

View File

@ -17,10 +17,6 @@ gdal.UseExceptions()
REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'ndr')
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
class NDRTests(unittest.TestCase):
"""Regression tests for InVEST SDR model."""

View File

@ -43,10 +43,6 @@ SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
LOGGER = logging.getLogger('test_recreation')
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
def _timeout(max_timeout):
"""Timeout decorator, parameter in seconds."""
def timeout_decorator(target):

View File

@ -20,10 +20,6 @@ _SRS = osr.SpatialReference()
_SRS.ImportFromEPSG(32731) # WGS84 / UTM zone 31s
WKT = _SRS.ExportToWkt()
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
class ScenicQualityTests(unittest.TestCase):
"""Tests for the InVEST Scenic Quality model."""

View File

@ -15,10 +15,6 @@ REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'sdr')
SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
def assert_expected_results_in_vector(expected_results, vector_path):
"""Assert one feature vector maps to expected_results key/value pairs."""
watershed_results_vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR)

View File

@ -17,10 +17,6 @@ REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
'seasonal_water_yield')
# Skipping all compiled model tests temporarily for feature/plugins
pytestmark = pytest.mark.skip(
reason="Temporarily ignoring compiled models for feature/plugins")
def make_simple_shp(base_shp_path, origin):
"""Make a 100x100 ogr rectangular geometry shapefile.