From 748432746f3277c47596bda998230edb455c7a30 Mon Sep 17 00:00:00 2001 From: Romain Hugonnet Date: Fri, 2 Aug 2024 15:32:26 -0700 Subject: [PATCH] Fix pip install and add more exhaustive CI checks (#593) --- .github/workflows/pip-checks.yml | 49 ++++++++++++++++++++++++++++++++ geoutils/vector.py | 4 +-- tests/test_misc.py | 16 +++++------ 3 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/pip-checks.yml diff --git a/.github/workflows/pip-checks.yml b/.github/workflows/pip-checks.yml new file mode 100644 index 00000000..b202f954 --- /dev/null +++ b/.github/workflows/pip-checks.yml @@ -0,0 +1,49 @@ +# This workflow checks that pip installation works to import the package (tests are in python-tests.yml) + +name: pip-install + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + name: ${{ matrix.os }}, python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + python-version: ["3.9", "3.10", "3.11"] + + # Run all shells using bash (including Windows) + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v4 + + # We initiate the environment empty + - name: Initiate empty environment + uses: conda-incubator/setup-miniconda@v3 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + auto-update-conda: true + use-mamba: true + channel-priority: strict + activate-environment: geoutils-pip + python-version: + + # Use pip install + - name: Install project + run: | + mamba install pip + pip install -e . + + # Check import works + - name: Check import works with base environment + run: python -c "import geoutils" diff --git a/geoutils/vector.py b/geoutils/vector.py index 815249d5..1e270be4 100644 --- a/geoutils/vector.py +++ b/geoutils/vector.py @@ -20,12 +20,12 @@ overload, ) -import fiona import geopandas as gpd import matplotlib import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pyogrio import rasterio as rio import rasterio.errors import shapely @@ -1137,7 +1137,7 @@ def reproject( except rasterio.errors.RasterioIOError: try: ds_ref = Vector(ref) - except fiona.errors.DriverError: + except pyogrio.errors.DataSourceError: raise ValueError("Could not open raster or vector with rasterio or fiona.") else: raise TypeError("Type of ref must be string path to file, Raster or Vector.") diff --git a/tests/test_misc.py b/tests/test_misc.py index 5773505d..ab0e62bb 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -118,8 +118,8 @@ def useless_func() -> int: def test_diff_environment_yml(self, capsys) -> None: # type: ignore # Test with synthetic environment - env = {"dependencies": ["python==3.9", "numpy", "fiona"]} - devenv = {"dependencies": ["python==3.9", "numpy", "fiona", "opencv"]} + env = {"dependencies": ["python==3.9", "numpy", "pandas"]} + devenv = {"dependencies": ["python==3.9", "numpy", "pandas", "opencv"]} # This should print the difference between the two geoutils.misc.diff_environment_yml(env, devenv, input_dict=True, print_dep="conda") @@ -134,8 +134,8 @@ def test_diff_environment_yml(self, capsys) -> None: # type: ignore captured = capsys.readouterr().out assert captured == "opencv\nNone\n" - env2 = {"dependencies": ["python==3.9", "numpy", "fiona"]} - devenv2 = {"dependencies": ["python==3.9", "numpy", "fiona", "opencv", {"pip": ["geoutils", "-e ./"]}]} + env2 = {"dependencies": ["python==3.9", "numpy", "pandas"]} + devenv2 = {"dependencies": ["python==3.9", "numpy", "pandas", "opencv", {"pip": ["geoutils", "-e ./"]}]} # The diff function should not account for -e ./ that is the local install for developers geoutils.misc.diff_environment_yml(env2, devenv2, input_dict=True, print_dep="both") @@ -155,13 +155,13 @@ def test_diff_environment_yml(self, capsys) -> None: # type: ignore # When the dependencies are not defined in dev-env but in env, it should raise an error # For normal dependencies - env3 = {"dependencies": ["python==3.9", "numpy", "fiona", "lol"]} - devenv3 = {"dependencies": ["python==3.9", "numpy", "fiona", "opencv", {"pip": ["geoutils"]}]} + env3 = {"dependencies": ["python==3.9", "numpy", "pandas", "lol"]} + devenv3 = {"dependencies": ["python==3.9", "numpy", "pandas", "opencv", {"pip": ["geoutils"]}]} with pytest.raises(ValueError, match="The following dependencies are listed in env but not dev-env: lol"): geoutils.misc.diff_environment_yml(env3, devenv3, input_dict=True, print_dep="pip") # For pip dependencies - env4 = {"dependencies": ["python==3.9", "numpy", "fiona", {"pip": ["lol"]}]} - devenv4 = {"dependencies": ["python==3.9", "numpy", "fiona", "opencv", {"pip": ["geoutils"]}]} + env4 = {"dependencies": ["python==3.9", "numpy", "pandas", {"pip": ["lol"]}]} + devenv4 = {"dependencies": ["python==3.9", "numpy", "pandas", "opencv", {"pip": ["geoutils"]}]} with pytest.raises(ValueError, match="The following pip dependencies are listed in env but not dev-env: lol"): geoutils.misc.diff_environment_yml(env4, devenv4, input_dict=True, print_dep="pip")