Numpy 2 compatibility (#3061)

* Numpy 2 compatibility

* Update PR ref in change log

* Add missing vsiopener test dependencies

* Change log update
This commit is contained in:
Sean Gillies 2024-04-08 16:04:02 -06:00 committed by GitHub
parent 7fb4442c40
commit 64b6fe03b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 107 additions and 46 deletions

View File

@ -42,6 +42,51 @@ jobs:
python -m pip install pre-commit
pre-commit run --show-diff-on-failure --all-files
numpy_compat_test:
runs-on: ubuntu-latest
name: Build with Numpy 2.0.0rc1, test with 1.23.5
container: ghcr.io/osgeo/gdal:ubuntu-small-${{ matrix.gdal-version }}
env:
DEBIAN_FRONTEND: noninteractive
strategy:
fail-fast: false
matrix:
python-version: ['3.10']
gdal-version: ['3.8.4']
steps:
- uses: actions/checkout@v2
- name: Update
run: |
apt-get update
apt-get -y install software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt-get update
- name: Set up Python ${{ matrix.python-version }}
run: |
apt-get install -y --no-install-recommends \
python${{ matrix.python-version }} \
python${{ matrix.python-version }}-dev \
python${{ matrix.python-version }}-venv \
python3-pip \
g++
- name: build wheel with Numpy 2
run: |
python${{ matrix.python-version }} -m venv testenv
. testenv/bin/activate
python -m pip install --upgrade pip
python -m pip install build
python -m build
- name: run tests with Numpy 1
run: |
. testenv/bin/activate
python -m pip install numpy==1.23.5
python -m pip wheel -r requirements-dev.txt
python -m pip install dist/*.whl
python -m pip install aiohttp boto3 fsspec hypothesis packaging pytest shapely
rm -rf rasterio
python -m pytest -v -m "not wheel" -rxXs
docker_tests:
needs: linting
runs-on: ubuntu-latest
@ -86,7 +131,6 @@ jobs:
python${{ matrix.python-version }} -m venv testenv
. testenv/bin/activate
python -m pip install --upgrade pip
python -m pip wheel -r requirements-dev.txt
python -m pip install --no-deps --force-reinstall -e .[test]
- name: run tests

View File

@ -1,11 +1,22 @@
Changes
=======
Next (TBD)
----------
1.4a3 (2024-04-15)
------------------
This version is compatible with recent versions of Numpy 1.x and Numpy
2.0.0rc1.
Packaging:
- Wheels will be built using Numpy 2.0.0rc1 or a newer version and will be
compatible with the oldest supported Numpy 1.x.
Bug fixes:
- The use of approximate transformers is disable in the geolocation array
warping case, as they already are for RPCs (#3056).
- All use of pkg_resouces has been eliminated (#3061).
- Non-strings may once again be used as values of the dtype keyword argument of
rasterize(), fixing a bug introduced in 1.4a1 (#3045).

View File

@ -35,6 +35,9 @@ dockertestimage:
dockertest: dockertestimage
docker run --rm -it -v $(shell pwd):/app -v /tmp:/tmp --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash rasterio:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python setup.py develop && /venv/bin/python -B -m pytest -m "not wheel" --cov rasterio --cov-report term-missing $(OPTS)'
dockernumpytest: dockertestimage
docker run -it -v $(shell pwd):/app --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash rasterio:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python -m build && /venv/bin/python -m pip install numpy==1.23.5 && /venv/bin/python -m pip install dist/*.whl && /venv/bin/python -B -m pytest -m "not wheel" --cov rasterio --cov-report term-missing $(OPTS)'
dockershell: dockertestimage
docker run -it -v $(shell pwd):/app --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash rasterio:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python setup.py develop && /bin/bash'

View File

@ -1,5 +1,10 @@
[build-system]
requires = ["setuptools>=67.8", "cython~=3.0.2", "numpy>=1.25,<2"]
requires = [
"setuptools>=67.8",
"wheel",
"cython~=3.0.2",
"numpy>=2.0.0rc1"
]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]

View File

@ -46,6 +46,8 @@ from rasterio._err cimport exc_wrap_int, exc_wrap_pointer, exc_wrap_vsilfile, St
cimport numpy as np
np.import_array()
log = logging.getLogger(__name__)
gdal33_version_checked = False

View File

@ -42,6 +42,8 @@ from rasterio._io cimport (
from rasterio._features cimport GeomBuilder, OGRGeomBuilder
from rasterio.crs cimport CRS
np.import_array()
log = logging.getLogger(__name__)
# Gauss (7) is not supported for warp
@ -50,6 +52,7 @@ SUPPORTED_RESAMPLING = [r for r in Resampling if r.value != 7 and r.value <= 13]
if GDALVersion.runtime().at_least('3.3'):
SUPPORTED_RESAMPLING.append(Resampling.rms)
def recursive_round(val, precision):
"""Recursively round coordinates."""
if isinstance(val, (int, float)):

View File

@ -30,15 +30,19 @@ Please add yours to the registry
so that other ``rio`` users may find it.
"""
import itertools
import logging
from pkg_resources import iter_entry_points
import sys
from click_plugins import with_plugins
import click
import cligj
if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
import rasterio
from rasterio.session import AWSSession
@ -65,9 +69,10 @@ def show_versions_cb(ctx, param, value):
@with_plugins(
ep
for ep in list(iter_entry_points("rasterio.rio_commands"))
+ list(iter_entry_points("rasterio.rio_plugins"))
itertools.chain(
entry_points(group="rasterio.rio_commands"),
entry_points(group="rasterio.rio_plugins"),
)
)
@click.group()
@cligj.verbose_opt

View File

@ -2,6 +2,7 @@
# development specific requirements
aiohttp
build
cython>=3.0
delocate
fsspec

View File

@ -8,6 +8,7 @@ click~=8.0
click-plugins
cligj>=0.5
matplotlib
numpy>=1.21,<2
# numpy>=1.21,<2
numpy==2.0.0rc1
setuptools>=20.0
pyparsing~=3.1

View File

@ -224,40 +224,26 @@ log.debug('ext_options:\n%s', pprint.pformat(ext_options))
ext_modules = None
if "clean" not in sys.argv:
extensions = [
Extension("rasterio._base", ["rasterio/_base.pyx"], **ext_options),
Extension("rasterio._io", ["rasterio/_io.pyx"], **ext_options),
Extension("rasterio._features", ["rasterio/_features.pyx"], **ext_options),
Extension("rasterio._env", ["rasterio/_env.pyx"], **ext_options),
Extension("rasterio._warp", ["rasterio/_warp.pyx"], **cpp_ext_options),
Extension("rasterio._fill", ["rasterio/_fill.pyx"], **cpp_ext_options),
Extension("rasterio._err", ["rasterio/_err.pyx"], **ext_options),
Extension("rasterio._example", ["rasterio/_example.pyx"], **ext_options),
Extension("rasterio._version", ["rasterio/_version.pyx"], **ext_options),
Extension("rasterio.crs", ["rasterio/crs.pyx"], **ext_options),
Extension("rasterio.shutil", ["rasterio/shutil.pyx"], **ext_options),
Extension("rasterio._transform", ["rasterio/_transform.pyx"], **ext_options),
Extension("rasterio._filepath", ["rasterio/_filepath.pyx"], **cpp_ext_options),
Extension(
'rasterio._base', ['rasterio/_base.pyx'], **ext_options),
Extension(
'rasterio._io', ['rasterio/_io.pyx'], **ext_options),
Extension(
'rasterio._features', ['rasterio/_features.pyx'], **ext_options),
Extension(
'rasterio._env', ['rasterio/_env.pyx'], **ext_options),
Extension(
'rasterio._warp', ['rasterio/_warp.pyx'], **cpp_ext_options),
Extension(
'rasterio._fill', ['rasterio/_fill.pyx'], **cpp_ext_options),
Extension(
'rasterio._err', ['rasterio/_err.pyx'], **ext_options),
Extension(
'rasterio._example', ['rasterio/_example.pyx'], **ext_options),
Extension(
'rasterio._version', ['rasterio/_version.pyx'], **ext_options),
Extension(
'rasterio.crs', ['rasterio/crs.pyx'], **ext_options),
Extension(
'rasterio.shutil', ['rasterio/shutil.pyx'], **ext_options),
Extension(
'rasterio._transform', ['rasterio/_transform.pyx'], **ext_options)]
if gdal_major_version >= 3:
# VSI Plugins are only 3.0+
extensions.append(
Extension(
'rasterio._filepath', ['rasterio/_filepath.pyx'], **cpp_ext_options))
extensions.append(
Extension(
'rasterio._vsiopener', ['rasterio/_vsiopener.pyx'], **cpp_ext_options))
"rasterio._vsiopener", ["rasterio/_vsiopener.pyx"], **cpp_ext_options
),
]
ext_modules = cythonize(
extensions, quiet=True, compile_time_env=compile_time_env, **cythonize_options)
extensions, quiet=True, compile_time_env=compile_time_env, **cythonize_options
)
with open("README.rst", encoding="utf-8") as f:
@ -270,7 +256,7 @@ inst_reqs = [
"certifi",
"click>=4.0",
"cligj>=0.5",
"numpy<2",
"numpy",
"click-plugins",
"pyparsing",
"setuptools",

View File

@ -1,7 +1,7 @@
from pkg_resources import iter_entry_points
"""Tests CLI command version and entry points."""
import rasterio
from rasterio.rio.main import main_group
from rasterio.rio.main import entry_points, main_group
def test_version(runner):
@ -14,5 +14,5 @@ def test_all_registered():
# This test makes sure that all of the subcommands defined in the
# rasterio.rio_commands entry-point are actually registered to the main
# cli group.
for ep in iter_entry_points('rasterio.rio_commands'):
for ep in entry_points(group="rasterio.rio_commands"):
assert ep.name in main_group.commands