Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pip install and add new tests #559

Merged
merged 8 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: xdem-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 xdem"
2 changes: 1 addition & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- tqdm
- scikit-image=0.*
- scikit-gstat>=1.0,<1.1
- geoutils=0.1.7
- geoutils=0.1.8

# Development-specific, to mirror manually in setup.cfg [options.extras_require].
- pip
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- tqdm
- scikit-image=0.*
- scikit-gstat>=1.0,<1.1
- geoutils=0.1.7
- geoutils=0.1.8
- pip

# To run CI against latest GeoUtils
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ scipy>=1.0,<1.13
tqdm
scikit-image==0.*
scikit-gstat>=1.0,<1.1
geoutils==0.1.7
geoutils==0.1.8
pip
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
xdem.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
xdem.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"):
xdem.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"):
xdem.misc.diff_environment_yml(env4, devenv4, input_dict=True, print_dep="pip")
6 changes: 3 additions & 3 deletions xdem/coreg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
)

import affine
import fiona
import geopandas as gpd
import geoutils as gu
import numpy as np
import pandas as pd
import pyogrio
import rasterio as rio
import rasterio.warp # pylint: disable=unused-import
import scipy
Expand Down Expand Up @@ -272,8 +272,8 @@ def _mask_as_array(reference_raster: gu.Raster, mask: str | gu.Vector | gu.Raste
# First try to load it as a Vector
try:
mask = gu.Vector(mask)
# If the format is unsopported, try loading as a Raster
except fiona.errors.DriverError:
# If the format is unsupported, try loading as a Raster
except pyogrio.errors.DataSourceError:
try:
mask = gu.Raster(mask)
# If that fails, raise an error
Expand Down
Loading