Skip to content

Commit

Permalink
Fix pip install and add more exhaustive CI checks (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet authored Aug 2, 2024
1 parent d1ec847 commit 7484327
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/pip-checks.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions geoutils/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
16 changes: 8 additions & 8 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")

0 comments on commit 7484327

Please sign in to comment.