-
Notifications
You must be signed in to change notification settings - Fork 19
118 lines (99 loc) · 4.54 KB
/
python-app.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: build
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.8", "3.9", "3.10"]
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
# We initiate the environment empty, and check if a key for this environment doesn't already exist in the cache
- name: Initiate empty environment
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
auto-update-conda: true
use-mamba: true
channel-priority: strict
activate-environment: geoutils-dev
- name: Get month for resetting cache
id: get-date
run: echo "cache_date=$(/bin/date -u '+%Y%m')" >> $GITHUB_ENV
shell: bash
- name: Cache conda env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ matrix.os }}-${{ matrix.python-version }}-${{ env.cache_date }}-${{ hashFiles('dev-environment.yml') }}-${{ env.CACHE_NUMBER }}
env:
CACHE_NUMBER: 102 # Increase this value to reset cache if environment.yml has not changed
id: cache
# The trick below is necessary because the generic environment file does not specify a Python version, and only
# "conda env update" can be used to update with an environment file, which upgrades the Python version
# (we add "graphviz" from dev-environment to solve all dependencies at once, at graphviz relies on image
# processing packages very much like geo-packages; not a problem for docs, dev installs where all is done at once)
- name: Install base environment with a fixed Python version
if: steps.cache.outputs.cache-hit != 'true'
run: |
mamba install pyyaml python=${{ matrix.python-version }}
pkgs_conda_base=`python .github/get_yml_env_nopy.py "environment.yml" --p "conda"`
pkgs_pip_base=`python .github/get_yml_env_nopy.py "environment.yml" --p "pip"`
mamba install python=${{ matrix.python-version }} $pkgs_conda_base graphviz
if [[ "$pkgs_pip_base" != "None" ]]; then
pip install $pkgs_pip_base
fi
- name: Install project
run: pip install -e . --no-dependencies
- name: Check import works with base environment
run: python -c "import geoutils"
# This time, the trick below is necessary because: 1/ "conda update" does not support a file -f as argument
# and also 2/ "conda env update" does not support --freeze-installed or --no-update-deps
- name: Update environment with development packages if cache does not exist
if: steps.cache.outputs.cache-hit != 'true'
run: |
pkgs_conda_dev=`python -c "import geoutils; geoutils.misc.diff_environment_yml('environment.yml', 'dev-environment.yml', 'conda')"`
pkgs_pip_dev=`python -c "import geoutils; geoutils.misc.diff_environment_yml('environment.yml', 'dev-environment.yml', 'pip')"`
mamba install $pkgs_conda_dev --freeze-installed
if [[ "$pkgs_pip_dev" != "None" ]]; then
pip install --user $pkgs_pip_dev
fi
# Stop the build if there are Python syntax errors or undefined names
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Setup pip dependencies
run: pip install pytest-cov coveralls coveragepy-lcov
- name: Test with pytest
run: pytest -ra --cov=geoutils/
- name: Converting coverage to LCOV format
run: coveragepy-lcov --data_file_path .coverage --output_file_path coverage.info
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.test_number }}
path-to-lcov: coverage.info
parallel: true
finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Upload to Coveralls finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true