diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba55a0..5072d4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - '*' pull_request: env: - LATEST_PY_VERSION: '3.10' + LATEST_PY_VERSION: '3.12' jobs: tests: @@ -21,11 +21,12 @@ jobs: - '3.9' - '3.10' - '3.11' + - '3.12' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -59,9 +60,9 @@ jobs: runs-on: ubuntu-latest if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ env.LATEST_PY_VERSION }} diff --git a/pyproject.toml b/pyproject.toml index c56268b..ca11d42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ Documentation = "https://cogeotiff.github.io/rio-cogeo/" cogeo = "rio_cogeo.scripts.cli:cogeo" [build-system] -requires = ["flit>=3.2,<4"] +requires = ["flit_core>=3.2,<4"] build-backend = "flit_core.buildapi" [tool.flit.module] diff --git a/rio_cogeo/cogeo.py b/rio_cogeo/cogeo.py index 84e6b55..e0867f8 100644 --- a/rio_cogeo/cogeo.py +++ b/rio_cogeo/cogeo.py @@ -408,9 +408,9 @@ def cog_translate( # noqa: C901 tags.update( { "TILING_SCHEME_NAME": tms.id or "CUSTOM", - "TILING_SCHEME_ZOOM_LEVEL": zoom_level - if zoom_level is not None - else default_zoom, + "TILING_SCHEME_ZOOM_LEVEL": ( + zoom_level if zoom_level is not None else default_zoom + ), } ) if aligned_levels: @@ -445,7 +445,8 @@ def cog_translate( # noqa: C901 warnings.warn( "With GDAL COG driver, mask band will be translated to an alpha band." ) - + if overview_level == 0: + dst_kwargs["overviews"] = "NONE" dst_kwargs["overview_resampling"] = overview_resampling dst_kwargs["warp_resampling"] = resampling dst_kwargs["blocksize"] = tilesize @@ -772,9 +773,9 @@ def cog_info( Height=src_dst.height, Tiled=(src_dst.block_shapes[0][1] != src_dst.width), Dtype=src_dst.dtypes[0], - Interleave=src_dst.interleaving.value - if src_dst.interleaving - else "UNKNOWN", + Interleave=( + src_dst.interleaving.value if src_dst.interleaving else "UNKNOWN" + ), AlphaBand=utils.has_alpha_band(src_dst), InternalMask=utils.has_mask_band(src_dst), Nodata=src_dst.nodata, diff --git a/tests/conftest.py b/tests/conftest.py index 26da170..32cfcf8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ """``pytest`` configuration.""" +import os import pytest import rasterio @@ -11,8 +12,23 @@ # Define helpers to skip tests based on GDAL version gdal_version = GDALVersion.runtime() +webp_tiff_path_rgb = os.path.join( + os.path.dirname(__file__), "fixtures", "image_webp.tif" +) + +has_webp = False +try: + with rasterio.open(webp_tiff_path_rgb) as src: + pass + + has_webp = True + +except rasterio.RasterioIOError: + has_webp = False + + requires_webp = pytest.mark.skipif( - "WEBP" not in drivers.keys(), reason="Only relevant if WEBP drivers is supported" + has_webp is False, reason="Only relevant if WEBP drivers is supported" ) requires_gdal31 = pytest.mark.skipif( diff --git a/tests/fixtures/image_colormap.tif b/tests/fixtures/image_colormap.tif index a82a0b1..0a00c4f 100644 Binary files a/tests/fixtures/image_colormap.tif and b/tests/fixtures/image_colormap.tif differ diff --git a/tests/fixtures/image_nocolormap.tif b/tests/fixtures/image_nocolormap.tif index 01c50f0..ddc7119 100644 Binary files a/tests/fixtures/image_nocolormap.tif and b/tests/fixtures/image_nocolormap.tif differ diff --git a/tests/fixtures/image_webp.tif b/tests/fixtures/image_webp.tif new file mode 100644 index 0000000..902d5e4 Binary files /dev/null and b/tests/fixtures/image_webp.tif differ diff --git a/tests/test_cogeo.py b/tests/test_cogeo.py index e9bd60c..8100ae2 100644 --- a/tests/test_cogeo.py +++ b/tests/test_cogeo.py @@ -739,6 +739,37 @@ def test_gdal_cog_web_mask(runner): assert cog_validate("cogeo.tif") +@requires_gdal31 +def test_gdal_cog_overview(runner): + """Test GDAL COG.""" + with runner.isolated_filesystem(): + profile = cog_profiles.get("jpeg") + profile["blockxsize"] = 256 + profile["blockysize"] = 256 + + cog_translate( + raster_path_rgba, + "gdalcogeo.tif", + profile.copy(), + quiet=True, + use_cog_driver=True, + overview_level=0, + ) + with rasterio.open("gdalcogeo.tif") as src: + assert src.overviews(1) == [] + + cog_translate( + raster_path_rgba, + "gdalcogeo.tif", + profile.copy(), + quiet=True, + use_cog_driver=True, + overview_level=None, + ) + with rasterio.open("gdalcogeo.tif") as src: + assert src.overviews(1) == [2] + + def test_info_with_metadata(): """Make sure info returns band metadata.""" info = cog_info(raster_band_tags)