Skip to content

Commit

Permalink
Update cartopy and drop Python3.8 (#507)
Browse files Browse the repository at this point in the history
## Overview

This PR fixes #494 

Changes:

* Upgraded Cartopy to v0.23.0 (BSD License)
* Added `yamllint` and `isort` to development deps and to linting
* Dropped support for Python3.8

## Additional Information

SciTools/cartopy#2285
  • Loading branch information
Zeitsperre authored May 14, 2024
2 parents de864ae + 0448abd commit 306fd27
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 75 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.x"
- uses: pre-commit/[email protected]

conda:
Expand All @@ -36,7 +36,6 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand All @@ -50,7 +49,6 @@ jobs:
with:
cache-downloads: true
cache-environment: true
activate-environment: raven
environment-file: environment.yml
create-args: >-
python=${{ matrix.python-version }}
Expand All @@ -60,14 +58,14 @@ jobs:
echo "micromamba: $(micromamba --version)"
- name: Install RavenWPS
run: |
python3 -m pip install --no-user --editable ".[dev]"
python -m pip install --no-user --editable ".[dev]"
- name: Check versions
run: |
conda list
pip check
python -m pip check
- name: Test RavenWPS
run: |
python3 -m pytest -m "not very_slow" tests
python -m pytest -m "not very_slow" tests
finish:
name: Finish
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
rev: v3.15.2
hooks:
- id: pyupgrade
args: [ '--py38-plus' ]
args: [ '--py39-plus' ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down Expand Up @@ -47,7 +47,7 @@ repos:
rev: 1.8.5
hooks:
- id: nbqa-pyupgrade
args: [ '--py38-plus' ]
args: [ '--py39-plus' ]
additional_dependencies: [ 'pyupgrade==v3.15.2' ]
- id: nbqa-black
additional_dependencies: [ 'black==24.4.2' ]
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ notebook:
.PHONY: lint
lint:
@echo "Running flake8 code style checks ..."
@bash -c 'flake8 raven tests'
black --check raven tests
isort --check raven tests
flake8 raven tests
yamllint --config-file=.yamllint.yaml raven

# Only works for notebooks that passed ``make test-notebooks`` above. For
# those that failed, manually starting a local Jupyter server and refresh them
Expand Down
32 changes: 0 additions & 32 deletions client_environment.yml

This file was deleted.

3 changes: 2 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ channels:
dependencies:
- python >=3.8,<3.12
- birdy
- black
- black >=24.4.2
- bump2version
- flake8
- ipykernel
- ipywidgets
- isort >=5.13.2
- nbconvert
- nbval
- pip
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- pywps ==4.5.1
- affine
- anyascii
- cartopy
- cartopy >=0.23.0
- click
- fiona >=1.9
- geopandas >=0.12.0
Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ maintainers = [
{name = "Tuan Long Vu", email = "[email protected]"}
]
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.8.0"
requires-python = ">=3.9.0"
keywords = ["wps", "pywps", "birdhouse", "raven", "hydrology", "gis", "analysis"]
license = {file = "LICENSE.txt"}
classifiers = [
Expand All @@ -27,7 +27,6 @@ classifiers = [
"Programming Language :: Python",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -45,15 +44,15 @@ dependencies = [
"netCDF4",
"numpy",
"owslib",
"pandas <2.0; python_version == '3.8'",
"pandas; python_version >= '3.9'",
"pandas >=2.0",
"psutil",
"pywps ==4.5.1",
"requests",
"xarray >=0.18",
"xclim >=0.31.0",
# GIS libraries
"affine",
"cartopy >=0.23.0",
"fiona >=1.9.0",
"geojson",
"geopandas >=0.12.0",
Expand All @@ -74,11 +73,12 @@ dependencies = [
dev = [
# Dev tools and testing
"birdhouse-birdy",
"black >=24.1.1",
"black >=24.4.2",
"black-nb",
"bumpversion",
"flake8 >=7.0.0",
"ipykernel",
"isort >=5.13.2",
"nbconvert",
"nbval",
"nc-time-axis",
Expand Down Expand Up @@ -119,7 +119,6 @@ raven-wps = "raven.cli:cli"

[tool.black]
target-version = [
"py38",
"py39",
"py310",
"py311"
Expand Down Expand Up @@ -169,7 +168,7 @@ exclude = [

[tool.isort]
profile = "black"
py_version = 38
py_version = 39
append_only = true

[tool.pytest.ini_options]
Expand Down
2 changes: 1 addition & 1 deletion raven/utilities/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def geom_prop(geom: Union[Polygon, MultiPolygon, GeometryCollection]) -> dict:

def dem_prop(
dem: Union[str, Path],
geom: Union[Polygon, MultiPolygon, List[Union[Polygon, MultiPolygon]]] = None,
geom: Union[Polygon, MultiPolygon, list[Union[Polygon, MultiPolygon]]] = None,
directory: Union[str, Path] = None,
) -> dict:
"""Return raster properties for each geometry.
Expand Down
7 changes: 4 additions & 3 deletions raven/utilities/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import collections
import logging
import warnings
from collections.abc import Sequence
from pathlib import Path
from typing import Any, List, Sequence, Tuple, Union
from typing import Any, List, Tuple, Union

from . import gis_import_error_message

Expand Down Expand Up @@ -125,8 +126,8 @@ def multipolygon_check(geom: GeometryCollection) -> None:


def feature_contains(
point: Union[Tuple[Union[int, float, str], Union[str, float, int]], Point],
shp: Union[str, Path, List[Union[str, Path]]],
point: Union[tuple[Union[int, float, str], Union[str, float, int]], Point],
shp: Union[str, Path, list[Union[str, Path]]],
) -> Union[dict, bool]:
"""Return the first feature containing a location.
Expand Down
2 changes: 1 addition & 1 deletion raven/utilities/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def geom_transform(
def generic_raster_clip(
raster: Union[str, Path],
output: Union[str, Path],
geometry: Union[Polygon, MultiPolygon, List[Union[Polygon, MultiPolygon]]],
geometry: Union[Polygon, MultiPolygon, list[Union[Polygon, MultiPolygon]]],
touches: bool = False,
fill_with_nodata: bool = True,
padded: bool = True,
Expand Down
15 changes: 8 additions & 7 deletions raven/utilities/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import os
import urllib.request
import warnings
from collections.abc import Iterable, Sequence
from pathlib import Path
from typing import Iterable, Optional, Sequence, Tuple, Union
from typing import Optional, Tuple, Union
from urllib.parse import urljoin

from requests import Request
Expand Down Expand Up @@ -62,15 +63,15 @@

def _get_location_wfs(
bbox: Optional[
Tuple[
tuple[
Union[str, float, int],
Union[str, float, int],
Union[str, float, int],
Union[str, float, int],
]
] = None,
point: Optional[
Tuple[
tuple[
Union[str, float, int],
Union[str, float, int],
]
Expand Down Expand Up @@ -409,11 +410,11 @@ def aggfunc(x):

def select_hybas_domain(
bbox: Optional[
Tuple[
tuple[
Union[int, float], Union[int, float], Union[int, float], Union[int, float]
]
] = None,
point: Optional[Tuple[Union[int, float], Union[int, float]]] = None,
point: Optional[tuple[Union[int, float], Union[int, float]]] = None,
) -> str:
"""Provided a given coordinate or boundary box, return the domain name of the geographic region the coordinate is located within.
Expand Down Expand Up @@ -483,7 +484,7 @@ def filter_hydrobasins_attributes_wfs(


def get_hydrobasins_location_wfs(
coordinates: Tuple[
coordinates: tuple[
Union[str, float, int],
Union[str, float, int],
],
Expand Down Expand Up @@ -649,7 +650,7 @@ def filter_hydro_routing_attributes_wfs(


def get_hydro_routing_location_wfs(
coordinates: Tuple[
coordinates: tuple[
Union[int, float, str],
Union[str, float, int],
],
Expand Down
15 changes: 8 additions & 7 deletions raven/utilities/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import tempfile
import warnings
import zipfile
from collections.abc import Iterable, Sequence
from pathlib import Path
from re import search
from typing import Iterable, List, Optional, Sequence, Tuple, Union
from typing import List, Optional, Tuple, Union

from . import gis_import_error_message

Expand Down Expand Up @@ -79,9 +80,9 @@ def address_append(address: Union[str, Path]) -> str:


def generic_extract_archive(
resources: Union[str, Path, List[Union[bytes, str, Path]]],
resources: Union[str, Path, list[Union[bytes, str, Path]]],
output_dir: Optional[Union[str, Path]] = None,
) -> List[str]:
) -> list[str]:
"""Extract archives (tar/zip) to a working directory.
Parameters
Expand Down Expand Up @@ -143,10 +144,10 @@ def generic_extract_archive(


def archive_sniffer(
archives: Union[str, Path, List[Union[str, Path]]],
archives: Union[str, Path, list[Union[str, Path]]],
working_dir: Optional[Union[str, Path]] = None,
extensions: Optional[Sequence[str]] = None,
) -> List[Union[str, Path]]:
) -> list[Union[str, Path]]:
"""Return a list of locally unarchived files that match the desired extensions.
Parameters
Expand Down Expand Up @@ -177,7 +178,7 @@ def archive_sniffer(

def crs_sniffer(
*args: Union[str, Path, Sequence[Union[str, Path]]]
) -> Union[List[Union[str, int]], str, int]:
) -> Union[list[Union[str, int]], str, int]:
"""Return the list of CRS found in files.
Parameters
Expand Down Expand Up @@ -266,7 +267,7 @@ def raster_datatype_sniffer(file: Union[str, Path]) -> str:

def get_bbox(
vector: Union[str, Path], all_features: bool = True
) -> Tuple[float, float, float, float]:
) -> tuple[float, float, float, float]:
"""Return bounding box of all features or the first feature in file.
Parameters
Expand Down
9 changes: 5 additions & 4 deletions raven/utilities/testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import os
import re
import warnings
from collections.abc import Sequence
from pathlib import Path
from shutil import copy
from typing import List, Optional, Sequence, Union
from typing import List, Optional, Union
from urllib.error import HTTPError, URLError
from urllib.parse import urljoin
from urllib.request import urlretrieve
Expand Down Expand Up @@ -40,7 +41,7 @@ def get_local_testdata(
temp_folder: Union[str, os.PathLike],
branch: str = "master",
_local_cache: Union[str, os.PathLike] = _default_cache_dir,
) -> Union[Path, List[Path]]:
) -> Union[Path, list[Path]]:
"""Copy specific testdata from a default cache to a temporary folder.
Return files matching `pattern` in the default cache dir and move to a local temp folder.
Expand Down Expand Up @@ -175,7 +176,7 @@ def get_file(
github_url: str = "https://github.com/Ouranosinc/raven-testdata",
branch: str = "master",
cache_dir: Path = _default_cache_dir,
) -> Union[Path, List[Path]]:
) -> Union[Path, list[Path]]:
"""
Return a file from an online GitHub-like repository.
If a local copy is found then always use that to avoid network traffic.
Expand Down Expand Up @@ -222,7 +223,7 @@ def query_folder(
pattern: Optional[str] = None,
github_url: str = "https://github.com/Ouranosinc/raven-testdata",
branch: str = "master",
) -> List[str]:
) -> list[str]:
"""
Lists the files available for retrieval from a remote git repository with get_file.
If provided a folder name, will perform a globbing-like filtering operation for parent folders.
Expand Down
Loading

0 comments on commit 306fd27

Please sign in to comment.