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

Micromamba for ci #205

Merged
merged 4 commits into from
Aug 26, 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
44 changes: 24 additions & 20 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,47 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
environment-name: [
"py3.10-ecoscope1.8.2",
"py3.11-ecoscope1.8.2",
"py3.12-ecoscope1.8.2",
]
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to attach ecoscope version here? It means every time we upgrade ecoscope we need to change the github action too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synced offline and will resolve it later.


steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
with:
python-version: ${{ matrix.python-version }}
environment-file: ./ci/envs/${{ matrix.environment-name }}.yml
cache-environment: true
cache-downloads: true
init-shell: bash

- uses: actions/cache@v4
id: restore-cache
with:
key: "venv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}"
path: |
.venv/

# If python patch version changes, or pyproject.toml gets updated,
# the cache lookup will miss, and the venv needs to be recreated.
- name: If no cache hit, recreate venv
if: "steps.restore-cache.outputs.cache-hit == false"
- name: Install pip dependencies and our package
shell: bash -leo pipefail {0}
run: |
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e ".[test]"
python -m pip install -U pip
python -m pip install -e ".[test,lithops]" --config-settings editable_mode=compat

- name: Run doctests
shell: bash -leo pipefail {0}
run: |
.venv/bin/python -m pytest -v ecoscope_workflows/ --doctest-modules \
python -m pytest -v ecoscope_workflows/ --doctest-modules \
--ignore=ecoscope_workflows/visualize.py

- name: Export shell name and conda env name to env
run: |
echo 'SHELL="bash -leo pipefail"' >> $GITHUB_ENV
echo "CONDA_ENV_NAME=${{ matrix.environment-name }}" >> $GITHUB_ENV

- name: Test with pytest
env:
EARTHRANGER_SERVER: ${{ secrets.EARTHRANGER_SERVER }}
EARTHRANGER_USERNAME: ${{ secrets.EARTHRANGER_USERNAME }}
EARTHRANGER_PASSWORD: ${{ secrets.EARTHRANGER_PASSWORD }}
shell: bash -leo pipefail {0}
run: |
.venv/bin/python -m pytest -n auto tests -vvv
python -m pytest tests -vvv

# - name: Upload Coverage to Codecov
# uses: codecov/codecov-action@v2
11 changes: 11 additions & 0 deletions ci/envs/py3.10-ecoscope1.8.2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: py3.10-ecoscope1.8.2
channels:
- conda-forge
dependencies:
- python==3.10.12
- geopandas<=0.14.2
- git
- numpy<2
- pip
- pip:
- ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]
11 changes: 11 additions & 0 deletions ci/envs/py3.11-ecoscope1.8.2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: py3.11-ecoscope1.8.2
channels:
- conda-forge
dependencies:
- python=3.11
- geopandas<=0.14.2
- git
- numpy<2
- pip
- pip:
- ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]
11 changes: 11 additions & 0 deletions ci/envs/py3.12-ecoscope1.8.2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: py3.12-ecoscope1.8.2
channels:
- conda-forge
dependencies:
- python=3.12
- geopandas<=0.14.2
- git
- numpy<2
- pip
- pip:
- ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]
47 changes: 36 additions & 11 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,42 @@ def test_end_to_end(end_to_end: EndToEndFixture, tmp_path: Path):
with open(script_outpath, mode="w") as f:
f.write(script)

cmd = [
sys.executable,
"-W",
"ignore", # in testing context warnings are added; exclude them from stdout
script_outpath.as_posix(),
"--config-file",
end_to_end.param_path.as_posix(),
]
exe = (
# workaround for https://github.com/mamba-org/mamba/issues/2577
f"{os.environ['MAMBA_EXE']} run -n {os.environ['CONDA_ENV_NAME']} python"
if "mamba" in sys.executable
else sys.executable
)
cmd = " ".join(
[
os.environ.get("SHELL", "/bin/sh").replace('"', "").replace("'", ""),
"-c",
f"'{exe}",
"-W",
"ignore", # in testing context warnings are added; exclude them from stdout
script_outpath.as_posix(),
"--config-file",
f"{end_to_end.param_path.as_posix()}'",
],
)

env = os.environ.copy()
env["ECOSCOPE_WORKFLOWS_RESULTS"] = tmp.as_posix()
out = subprocess.run(cmd, capture_output=True, text=True, env=env)
assert out.returncode == 0

proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=env,
shell=True,
)
returncode = proc.wait()
if returncode != 0:
assert proc.stderr is not None
raise ValueError(f"{cmd = } failed with:\n {proc.stderr.read()}")
assert returncode == 0
assert proc.stdout is not None
stdout = proc.stdout.read().strip()
for assert_fn in end_to_end.assert_that_stdout:
assert assert_fn(out.stdout.strip())
assert assert_fn(stdout)
Loading