From 5a6dbad645f6f33a844371489e7f817d9597dfae Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 09:12:37 +1200 Subject: [PATCH 01/10] Update packaging, tests to test packaging, and package version --- .github/workflows/linux-test.yml | 1 + pyproject.toml | 4 ++-- setup.py | 12 ------------ src/geoapis/__init__.py | 2 +- tests/test_lidar/{test_lidar.py => test.py} | 2 +- .../{test_lidar_by_name.py => test.py} | 2 +- .../{test_lidar_subfolders.py => test.py} | 2 +- .../{test_raster_linz_in_bounds.py => test.py} | 2 +- .../{test_raster_lris_in_bounds.py => test.py} | 2 +- .../{test_vector_linz.py => test.py} | 2 +- .../{test_vector_linz_in_bounds.py => test.py} | 2 +- .../{test_vector_lris.py => test.py} | 2 +- .../{test_vector_lris_in_bounds.py => test.py} | 2 +- .../{test_vector_stats_nz.py => test.py} | 2 +- .../{test_vector_stats_nz_in_bounds.py => test.py} | 2 +- 15 files changed, 15 insertions(+), 26 deletions(-) delete mode 100644 setup.py rename tests/test_lidar/{test_lidar.py => test.py} (99%) rename tests/test_lidar_by_name/{test_lidar_by_name.py => test.py} (99%) rename tests/test_lidar_subfolders/{test_lidar_subfolders.py => test.py} (99%) rename tests/test_raster_linz_in_bounds/{test_raster_linz_in_bounds.py => test.py} (99%) rename tests/test_raster_lris_in_bounds/{test_raster_lris_in_bounds.py => test.py} (99%) rename tests/test_vector_linz/{test_vector_linz.py => test.py} (99%) rename tests/test_vector_linz_in_bounds/{test_vector_linz_in_bounds.py => test.py} (99%) rename tests/test_vector_lris/{test_vector_lris.py => test.py} (99%) rename tests/test_vector_lris_in_bounds/{test_vector_lris_in_bounds.py => test.py} (99%) rename tests/test_vector_stats_nz/{test_vector_stats_nz.py => test.py} (99%) rename tests/test_vector_stats_nz_in_bounds/{test_vector_stats_nz_in_bounds.py => test.py} (99%) diff --git a/.github/workflows/linux-test.yml b/.github/workflows/linux-test.yml index f1aa9e0..dd7b564 100644 --- a/.github/workflows/linux-test.yml +++ b/.github/workflows/linux-test.yml @@ -73,4 +73,5 @@ jobs: - name: Run tests with pytest run: | + pip install . pytest diff --git a/pyproject.toml b/pyproject.toml index e8abee3..55cbf10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [build-system] requires = [ - "setuptools>=61.0.0", + "setuptools>=64", "wheel" ] build-backend = "setuptools.build_meta" [project] name = "geoapis" -version = "0.3.3" +version = "0.3.4" description = "A package for downloading geospatial data from web APIs." readme = "README.md" authors = [{ name = "Rose pearson", email = "rose.pearson@niwa.co.nz" }] diff --git a/setup.py b/setup.py deleted file mode 100644 index 8ef9667..0000000 --- a/setup.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jun 30 11:22:08 2021 - -@author: pearsonra -""" -import setuptools - -setuptools.setup( - package_dir={"": "src"}, - packages=setuptools.find_packages(where="src"), -) diff --git a/src/geoapis/__init__.py b/src/geoapis/__init__.py index e840111..04838bb 100644 --- a/src/geoapis/__init__.py +++ b/src/geoapis/__init__.py @@ -4,4 +4,4 @@ @author: pearsonra """ -__version__ = "0.3.3" +__version__ = "0.3.4" diff --git a/tests/test_lidar/test_lidar.py b/tests/test_lidar/test.py similarity index 99% rename from tests/test_lidar/test_lidar.py rename to tests/test_lidar/test.py index 31ffe49..21dab23 100644 --- a/tests/test_lidar/test_lidar.py +++ b/tests/test_lidar/test.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTest(unittest.TestCase): diff --git a/tests/test_lidar_by_name/test_lidar_by_name.py b/tests/test_lidar_by_name/test.py similarity index 99% rename from tests/test_lidar_by_name/test_lidar_by_name.py rename to tests/test_lidar_by_name/test.py index 66fcae1..505faa6 100644 --- a/tests/test_lidar_by_name/test_lidar_by_name.py +++ b/tests/test_lidar_by_name/test.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTestByName(unittest.TestCase): diff --git a/tests/test_lidar_subfolders/test_lidar_subfolders.py b/tests/test_lidar_subfolders/test.py similarity index 99% rename from tests/test_lidar_subfolders/test_lidar_subfolders.py rename to tests/test_lidar_subfolders/test.py index 8a3a596..dc01b8e 100644 --- a/tests/test_lidar_subfolders/test_lidar_subfolders.py +++ b/tests/test_lidar_subfolders/test.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTestSubfolders(unittest.TestCase): diff --git a/tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py b/tests/test_raster_linz_in_bounds/test.py similarity index 99% rename from tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py rename to tests/test_raster_linz_in_bounds/test.py index 5a7c2e7..8dbe839 100644 --- a/tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py +++ b/tests/test_raster_linz_in_bounds/test.py @@ -15,7 +15,7 @@ import os import logging -from src.geoapis import raster +from geoapis import raster class LinzRasterTest(unittest.TestCase): diff --git a/tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py b/tests/test_raster_lris_in_bounds/test.py similarity index 99% rename from tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py rename to tests/test_raster_lris_in_bounds/test.py index 102d0a2..cc30b1c 100644 --- a/tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py +++ b/tests/test_raster_lris_in_bounds/test.py @@ -15,7 +15,7 @@ import os import logging -from src.geoapis import raster +from geoapis import raster class LrisRasterTest(unittest.TestCase): diff --git a/tests/test_vector_linz/test_vector_linz.py b/tests/test_vector_linz/test.py similarity index 99% rename from tests/test_vector_linz/test_vector_linz.py rename to tests/test_vector_linz/test.py index 2c8fd8f..8eef9e2 100644 --- a/tests/test_vector_linz/test_vector_linz.py +++ b/tests/test_vector_linz/test.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class LinzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py b/tests/test_vector_linz_in_bounds/test.py similarity index 99% rename from tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py rename to tests/test_vector_linz_in_bounds/test.py index aba72aa..9636922 100644 --- a/tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py +++ b/tests/test_vector_linz_in_bounds/test.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class LinzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_lris/test_vector_lris.py b/tests/test_vector_lris/test.py similarity index 99% rename from tests/test_vector_lris/test_vector_lris.py rename to tests/test_vector_lris/test.py index 33734e5..5576ff2 100644 --- a/tests/test_vector_lris/test_vector_lris.py +++ b/tests/test_vector_lris/test.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class LrisVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py b/tests/test_vector_lris_in_bounds/test.py similarity index 99% rename from tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py rename to tests/test_vector_lris_in_bounds/test.py index 7eae5f3..1d67f86 100644 --- a/tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py +++ b/tests/test_vector_lris_in_bounds/test.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class LrisVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_stats_nz/test_vector_stats_nz.py b/tests/test_vector_stats_nz/test.py similarity index 99% rename from tests/test_vector_stats_nz/test_vector_stats_nz.py rename to tests/test_vector_stats_nz/test.py index dda7b8c..7db2421 100644 --- a/tests/test_vector_stats_nz/test_vector_stats_nz.py +++ b/tests/test_vector_stats_nz/test.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class StatsNzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py b/tests/test_vector_stats_nz_in_bounds/test.py similarity index 99% rename from tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py rename to tests/test_vector_stats_nz_in_bounds/test.py index 2cf9a41..9331fd4 100644 --- a/tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py +++ b/tests/test_vector_stats_nz_in_bounds/test.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class StatsNzVectorsTest(unittest.TestCase): From d6eef49cfde5033c485ab93b02179a367f8f59ac Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 09:17:54 +1200 Subject: [PATCH 02/10] updated packaging --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 55cbf10..40bd97d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,9 +31,6 @@ dependencies = [ ] requires-python = ">=3.6" -[tool.setuptools] -packages = ["geoapis"] - [project.optional-dependencies] dev = ["black", "python-dotenv", "pip-tools", "pytest"] From 2e14cd5d0cd14c02f3141496967d03c3dcbfd85c Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 09:38:18 +1200 Subject: [PATCH 03/10] Updated test names and workflow to cache --- .github/workflows/linux-test.yml | 37 ++++++++++--------- tests/test_lidar/{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 .../{test.py => test_case.py} | 0 12 files changed, 19 insertions(+), 18 deletions(-) rename tests/test_lidar/{test.py => test_case.py} (100%) rename tests/test_lidar_by_name/{test.py => test_case.py} (100%) rename tests/test_lidar_subfolders/{test.py => test_case.py} (100%) rename tests/test_raster_linz_in_bounds/{test.py => test_case.py} (100%) rename tests/test_raster_lris_in_bounds/{test.py => test_case.py} (100%) rename tests/test_vector_linz/{test.py => test_case.py} (100%) rename tests/test_vector_linz_in_bounds/{test.py => test_case.py} (100%) rename tests/test_vector_lris/{test.py => test_case.py} (100%) rename tests/test_vector_lris_in_bounds/{test.py => test_case.py} (100%) rename tests/test_vector_stats_nz/{test.py => test_case.py} (100%) rename tests/test_vector_stats_nz_in_bounds/{test.py => test_case.py} (100%) diff --git a/.github/workflows/linux-test.yml b/.github/workflows/linux-test.yml index dd7b564..757b4a1 100644 --- a/.github/workflows/linux-test.yml +++ b/.github/workflows/linux-test.yml @@ -19,36 +19,37 @@ jobs: steps: - name: Checkout github repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Create LFS file list + run: git lfs ls-files --long | cut -d ' ' -f1 | sort > .lfs-assets-id - - name: Cache conda - uses: actions/cache@v2 - env: - cache-name: cache-conda-env + - name: LFS Cache + uses: actions/cache@v3 with: - path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('environment.yml') }} + path: .git/lfs/objects + key: ${{ matrix.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} + restore-keys: | + ${{ matrix.os }}-lfs- + - name: Git LFS Pull + run: git lfs pull - - name: Install package dependencies with setup-miniconda@v2 + - name: Setup miniconda uses: conda-incubator/setup-miniconda@v2 with: - python-version: ${{ matrix.python-version }} + auto-update-conda: true miniforge-variant: Mambaforge - channels: conda-forge - channel-priority: true + channels: conda-forge # defaults automatically added + python-version: ${{ matrix.python-version }} activate-environment: geoapis environment-file: environment.yml + use-mamba: true auto-activate-base: false - use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! - - run: | - conda info - conda list - conda config --show-sources - conda config --show - printenv | sort + - name: Conda list + shell: pwsh + run: conda list - name: Install test dependencies run: | diff --git a/tests/test_lidar/test.py b/tests/test_lidar/test_case.py similarity index 100% rename from tests/test_lidar/test.py rename to tests/test_lidar/test_case.py diff --git a/tests/test_lidar_by_name/test.py b/tests/test_lidar_by_name/test_case.py similarity index 100% rename from tests/test_lidar_by_name/test.py rename to tests/test_lidar_by_name/test_case.py diff --git a/tests/test_lidar_subfolders/test.py b/tests/test_lidar_subfolders/test_case.py similarity index 100% rename from tests/test_lidar_subfolders/test.py rename to tests/test_lidar_subfolders/test_case.py diff --git a/tests/test_raster_linz_in_bounds/test.py b/tests/test_raster_linz_in_bounds/test_case.py similarity index 100% rename from tests/test_raster_linz_in_bounds/test.py rename to tests/test_raster_linz_in_bounds/test_case.py diff --git a/tests/test_raster_lris_in_bounds/test.py b/tests/test_raster_lris_in_bounds/test_case.py similarity index 100% rename from tests/test_raster_lris_in_bounds/test.py rename to tests/test_raster_lris_in_bounds/test_case.py diff --git a/tests/test_vector_linz/test.py b/tests/test_vector_linz/test_case.py similarity index 100% rename from tests/test_vector_linz/test.py rename to tests/test_vector_linz/test_case.py diff --git a/tests/test_vector_linz_in_bounds/test.py b/tests/test_vector_linz_in_bounds/test_case.py similarity index 100% rename from tests/test_vector_linz_in_bounds/test.py rename to tests/test_vector_linz_in_bounds/test_case.py diff --git a/tests/test_vector_lris/test.py b/tests/test_vector_lris/test_case.py similarity index 100% rename from tests/test_vector_lris/test.py rename to tests/test_vector_lris/test_case.py diff --git a/tests/test_vector_lris_in_bounds/test.py b/tests/test_vector_lris_in_bounds/test_case.py similarity index 100% rename from tests/test_vector_lris_in_bounds/test.py rename to tests/test_vector_lris_in_bounds/test_case.py diff --git a/tests/test_vector_stats_nz/test.py b/tests/test_vector_stats_nz/test_case.py similarity index 100% rename from tests/test_vector_stats_nz/test.py rename to tests/test_vector_stats_nz/test_case.py diff --git a/tests/test_vector_stats_nz_in_bounds/test.py b/tests/test_vector_stats_nz_in_bounds/test_case.py similarity index 100% rename from tests/test_vector_stats_nz_in_bounds/test.py rename to tests/test_vector_stats_nz_in_bounds/test_case.py From babcbba6a28cba9a8ecc9ead30f3dc3f403bb106 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 10:04:05 +1200 Subject: [PATCH 04/10] addressed test --- environment.yml | 3 --- tests/test_lidar_subfolders/test_case.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/environment.yml b/environment.yml index ffa8e30..4430159 100644 --- a/environment.yml +++ b/environment.yml @@ -3,7 +3,6 @@ name: geoapis channels: - conda-forge - - defaults dependencies: - pip - geopandas @@ -12,5 +11,3 @@ dependencies: - python-dotenv - pytest - tqdm - -prefix: C:\ProgramData\Anaconda3\envs\geoapis diff --git a/tests/test_lidar_subfolders/test_case.py b/tests/test_lidar_subfolders/test_case.py index dc01b8e..7a796ed 100644 --- a/tests/test_lidar_subfolders/test_case.py +++ b/tests/test_lidar_subfolders/test_case.py @@ -51,7 +51,7 @@ class OpenTopographyTestSubfolders(unittest.TestCase): f"{DATASETS[3]}_TileIndex.zip": 120930, }, DATASETS[4]: { - f"{DATASETS[4]}_TileIndex.zip": 3389130, + f"{DATASETS[4]}_TileIndex.zip": 4033009, }, } From 4ad75dd13b0a7465cb179d940865c28a319da7e0 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 14:17:38 +1200 Subject: [PATCH 05/10] made reobust to raster out of bounds error --- src/geoapis/raster.py | 12 ++++++++++-- src/geoapis/vector.py | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index 3f76e7d..477e9f4 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -148,7 +148,15 @@ def run(self, layer: int) -> pathlib.Path: response = requests.post( url=f"{self.base_url}/exports/", headers=headers, json=api_query ) - query_id = response.json()["id"] + json_query = response.json() + if not json_query["is_valid"]: + logging.warning( + "Invalid initial query. Check layer exists and is within bounds. " + f"json_query['invalid_reasons']: {json_query['invalid_reasons']}. " + f"json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + ) + return [] + query_id = json_query["id"] # Check the state of your exports until the triggered raster exports completes logging.info("Check status of download request") @@ -173,7 +181,7 @@ def run(self, layer: int) -> pathlib.Path: logging.warning( f"Could not download raster. Ended with status {element['state']}" ) - return + return [] # Download the completed export logging.info(f"Downloading {element['download_url']} to {self.cache_path}") with requests.get( diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 6e80f19..76ac87d 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -153,10 +153,12 @@ def get_json_response_in_bounds(self, layer: int, bounds, geometry_name: str): logging.info( f"Layer: {layer} is not `geometry_name`: {geometry_name}." ) - assert False, ( - f"No geometry types matching that of layer: {layer} tried. The" - " geometry_name's tried are: +{geometry_type_list}" + message = ( + f"No geometry types matching that of layer: {layer}. " + f"The geometry_name's tried are: {geometry_type_list}." ) + logging.error(message) + raise ValueError(message) def get_features_inside_catchment( self, layer: int, geometry_name: str From 21eea312f0ce9ebec0b2b136d4aceab942ec4670 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 14:36:52 +1200 Subject: [PATCH 06/10] add error checks for missing crs in the vector module --- src/geoapis/vector.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 76ac87d..d99eb42 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -72,10 +72,21 @@ def __init__( def _set_up(self): """Ensure the bouding_polygon and CRS are in agreement.""" + error_message = "Either the crs or the bounding_polygon with a CRS mus be specified." + if self.crs is None and self.bounding_polygon is None: + logging.error(error_message) + raise ValueError(error_message) + # Set the crs from the bounding_polygon if it's not been set - if self.crs is None and self.bounding_polygon is not None: - self.crs = self.bounding_polygon.crs.to_epsg() - # Set the bounding_polygon crs from the crs if they differ + if self.bounding_polygon is not None: + if self.crs is None and self.bounding_polygon.crs is not None: + self.crs = self.bounding_polygon.crs.to_epsg() + elif self.crs is not None and self.bounding_polygon.crs is None: + self.bounding_polygon.set_crs(self.crs, inplace=True) + elif self.crs is None and self.bounding_polygon.crs is None: + logging.error(error_message) + raise ValueError(error_message) + # Convert the bounding_polygon crs from the crs if they differ if ( self.bounding_polygon is not None and self.crs != self.bounding_polygon.crs.to_epsg() From 1737528b6ef0a969c30c570d9e0fdebe4eb481e8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 3 Sep 2024 02:38:54 +0000 Subject: [PATCH 07/10] fixup: Format Python code with Black --- src/geoapis/vector.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index d99eb42..0e0d7e3 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -72,7 +72,9 @@ def __init__( def _set_up(self): """Ensure the bouding_polygon and CRS are in agreement.""" - error_message = "Either the crs or the bounding_polygon with a CRS mus be specified." + error_message = ( + "Either the crs or the bounding_polygon with a CRS mus be specified." + ) if self.crs is None and self.bounding_polygon is None: logging.error(error_message) raise ValueError(error_message) @@ -164,7 +166,7 @@ def get_json_response_in_bounds(self, layer: int, bounds, geometry_name: str): logging.info( f"Layer: {layer} is not `geometry_name`: {geometry_name}." ) - message = ( + message = ( f"No geometry types matching that of layer: {layer}. " f"The geometry_name's tried are: {geometry_type_list}." ) From 0f9f1f584533ab3de34853add480e11c52d37469 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 14:42:26 +1200 Subject: [PATCH 08/10] fixed typo --- src/geoapis/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 0e0d7e3..c303b84 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -168,7 +168,7 @@ def get_json_response_in_bounds(self, layer: int, bounds, geometry_name: str): ) message = ( f"No geometry types matching that of layer: {layer}. " - f"The geometry_name's tried are: {geometry_type_list}." + f"The geometry_name's tried are: {self.GEOMETRY_NAMES}." ) logging.error(message) raise ValueError(message) From de71ab3f5047a935a880fa5adee20f29eb6438cc Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 16:03:59 +1200 Subject: [PATCH 09/10] Fix typo --- src/geoapis/raster.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index 477e9f4..a340aaf 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -149,12 +149,13 @@ def run(self, layer: int) -> pathlib.Path: url=f"{self.base_url}/exports/", headers=headers, json=api_query ) json_query = response.json() - if not json_query["is_valid"]: - logging.warning( - "Invalid initial query. Check layer exists and is within bounds. " - f"json_query['invalid_reasons']: {json_query['invalid_reasons']}. " - f"json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" - ) + if "is_valid" in json_query.keys() and not json_query["is_valid"]: + message = f"Invalid initial query. Check layer {layer} exists and is within bounds." + if "invalid_reasons" in json_query.keys(): + message = message + f" json_query['invalid_reasons']: {json_query['invalid_reasons']}." + if "items" in json_query.keys(): + message = message + f" json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + logging.warning(message) return [] query_id = json_query["id"] From a7b1374b208bf8ca7c05174bb043d9bb3850b7fc Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 3 Sep 2024 04:04:29 +0000 Subject: [PATCH 10/10] fixup: Format Python code with Black --- src/geoapis/raster.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index a340aaf..037cb58 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -152,9 +152,15 @@ def run(self, layer: int) -> pathlib.Path: if "is_valid" in json_query.keys() and not json_query["is_valid"]: message = f"Invalid initial query. Check layer {layer} exists and is within bounds." if "invalid_reasons" in json_query.keys(): - message = message + f" json_query['invalid_reasons']: {json_query['invalid_reasons']}." + message = ( + message + + f" json_query['invalid_reasons']: {json_query['invalid_reasons']}." + ) if "items" in json_query.keys(): - message = message + f" json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + message = ( + message + + f" json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + ) logging.warning(message) return [] query_id = json_query["id"]