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

Switch to GH actions #242

Merged
merged 27 commits into from
Dec 16, 2021
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
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Upload release

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# make sure tags are fetched so we can get a version
- run: |
git fetch --prune --unshallow --tags

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine

- name: Build sdist
run: |
python setup.py sdist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
168 changes: 168 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Tests

on:
pull_request:

push:
branches:
- master

env:
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: root

jobs:
test-pip:
name: Run tests (with pip)

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [ubuntu-latest, macos-latest]
# only test oldest and most recent supported Python versions
python-version: ["3.6", "3.9"]

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v2

# make sure tags are fetched so we can get a version
- run: git fetch --prune --unshallow --tags

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"

- name: Restore pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ matrix.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ matrix.os }}-pip-

- name: Setup Python environment
run: |
python -m pip install --upgrade pip setuptools wheel
pip install cython numpy

- name: Setup MySQL
if: contains(matrix.os, 'ubuntu')
run: |
sudo /etc/init.d/mysql start
mysql -e 'SHOW DATABASES;' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}

- name: Install Terracotta
run: |
pip install -e .[test]
pip freeze

- name: Initialize mypy
run: |
mypy . > /dev/null || true
mypy --install-types --non-interactive

- name: Run tests
run: |
if [ ${{ runner.os }} == "Linux" ]; then
MYSQL_SRV="${{ env.DB_USER }}:${{ env.DB_PASSWORD }}@127.0.0.1:${{ env.DB_PORT }}"
python -m pytest . --color=yes --cov=terracotta --mysql-server=$MYSQL_SRV
else
python -m pytest . --color=yes --cov=terracotta
fi

- name: Run benchmarks
run: |
python -m pytest --color=yes tests/benchmarks.py

- name: Upload coverage
uses: codecov/codecov-action@v1


test-conda:
name: Run tests (with conda)

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [windows-latest]
# Python 3.6 is EOL on conda-forge, so use 3.7 instead
python-version: ["3.7", "3.9"]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2

# make sure tags are fetched so we can get a version
- run: git fetch --prune --unshallow --tags

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"

- name: Restore pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ matrix.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ matrix.os }}-pip-

- name: Restore conda cache
uses: actions/cache@v2
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ matrix.python-version }}-${{ hashFiles('environment.yml') }}

- uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
environment-file: environment.yml
activate-environment: terracotta

- name: Install Terracotta
run: |
pip install -e .[test]
conda list

- name: Initialize mypy
run: |
mypy . > /dev/null || true
mypy --install-types --non-interactive

- name: Run tests
run: |
python -m pytest . --color=yes --cov=terracotta

- name: Run benchmarks
run: |
python -m pytest tests/benchmarks.py --color=yes

- name: Upload coverage
uses: codecov/codecov-action@v1
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Framework :: Flask',
'Operating System :: Microsoft :: Windows :: Windows 10',
'Operating System :: MacOS :: MacOS X',
Expand Down Expand Up @@ -69,7 +70,7 @@
'pillow',
'pyyaml>=3.10', # downstream dependency of apispec
'shapely',
'rasterio>=1.0,<=1.1.8', # TODO: unpin when performance issues with GDAL3 are fixed
'rasterio>=1.0',
'shapely',
'toml',
'tqdm'
Expand Down
2 changes: 1 addition & 1 deletion terracotta/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np


EXTRA_CALLABLES = {
EXTRA_CALLABLES: Dict[str, Tuple[Callable, int]] = {
# 'name': (callable, nargs)

# mask operations
Expand Down
2 changes: 1 addition & 1 deletion terracotta/scripts/optimize_rasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _optimize_single_raster(
'--overwrite', is_flag=True, default=False, help='Force overwrite of existing files'
)
@click.option(
'--resampling-method', type=click.Choice(RESAMPLING_METHODS.keys()),
'--resampling-method', type=click.Choice(list(RESAMPLING_METHODS.keys())),
default='average', help='Resampling method for overviews', show_default=True
)
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def run_test_server(driver_path, port):
create_app().run(port=port)


@pytest.fixture(scope='module')
@pytest.fixture(scope='session')
def test_server(testdb):
"""Spawn a Terracotta server in a separate process"""
port = 5555
Expand Down
2 changes: 0 additions & 2 deletions tests/drivers/test_drivers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pytest

TESTABLE_DRIVERS = ['sqlite', 'mysql']
Expand Down Expand Up @@ -32,7 +31,6 @@ def test_normalize_filepath(provider, tmpdir):
equivalent_paths = (
f'{tmpdir}/foo.tc',
f'{tmpdir}//foo.tc',
os.path.relpath(f'{tmpdir}/foo.tc', '.'),
f'{tmpdir}/bar/../foo.tc',
)

Expand Down
4 changes: 3 additions & 1 deletion tests/drivers/test_raster_drivers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import platform
import time

import rasterio
Expand Down Expand Up @@ -253,6 +254,7 @@ def insertion_worker(key, path, raster_file, provider):
time.sleep(0.01)


@pytest.mark.xfail(platform.system() == "Darwin", reason="Flaky on OSX")
@pytest.mark.parametrize('provider', DRIVERS)
def test_multiprocess_insertion(driver_path, provider, raster_file):
import functools
Expand All @@ -271,7 +273,7 @@ def test_multiprocess_insertion(driver_path, provider, raster_file):
provider=provider)

with concurrent.futures.ProcessPoolExecutor(4) as executor:
for result in executor.map(worker, key_vals):
for _ in executor.map(worker, key_vals):
pass

datasets = db.get_datasets()
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_entrypoint(monkeypatch, capsys):
assert exc.code == 0

captured = capsys.readouterr()
assert 'Usage: terracotta' in captured.out
assert 'Usage:' in captured.out


def test_entrypoint_exception(monkeypatch, capsys):
Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/test_optimize_rasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_reoptimize(tmpdir, unoptimized_raster_file, extra_flag):
args = ['optimize-rasters', infile, '-o', str(outfile)]
result = runner.invoke(cli.cli, args)
assert result.exit_code == 0
ctime = os.stat(outfile).st_ctime
ctime = os.path.getmtime(outfile)

# second time
args = ['optimize-rasters', infile, '-o', str(outfile)]
Expand All @@ -185,10 +185,10 @@ def test_reoptimize(tmpdir, unoptimized_raster_file, extra_flag):

if extra_flag == 'skip-existing':
assert result.exit_code == 0
assert os.stat(outfile).st_ctime == ctime
assert os.path.getmtime(outfile) == ctime
elif extra_flag == 'overwrite':
assert result.exit_code == 0
assert os.stat(outfile).st_ctime != ctime
assert os.path.getmtime(outfile) != ctime
else:
assert result.exit_code == 2

Expand Down
2 changes: 1 addition & 1 deletion tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_timeout():
from terracotta.expressions import evaluate_expression

with pytest.raises(RuntimeError) as raised_exc:
evaluate_expression('+'.join(['v1'] * 10), {'v1': np.ones((256, 256))}, timeout=0)
evaluate_expression('+'.join(['v1'] * 100), {'v1': np.ones((256, 256))}, timeout=0)

assert 'timeout' in str(raised_exc.value)

Expand Down
Loading