Skip to content

Commit

Permalink
Merge pull request #461 from geopy/gha
Browse files Browse the repository at this point in the history
Switch from Travis CI to GitHub Actions
  • Loading branch information
KostyaEsmukov committed Dec 26, 2020
2 parents 5fd7520 + c3504eb commit bf5d33c
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 95 deletions.
118 changes: 118 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: CI

on:
pull_request: {}
push: {}

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install tox tox-gh-actions
- run: tox -e lint

check-docs:
name: RST (README.rst + docs) syntax check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install tox tox-gh-actions
- run: tox -e rst

test_local:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: # &test-matrix
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, 'pypy3']
experimental: [false]
include:
- python-version: '3.10-dev'
experimental: true
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools
python3 -m pip install tox tox-gh-actions
- run: GEOPY_TOX_TARGET=test-local tox

test_full:
if: ${{ github.event_name != 'pull_request' }}
needs: [lint, check-docs, test_local]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: # *test-matrix https://github.community/t/support-for-yaml-anchors/16128
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, 'pypy3']
experimental: [false]
include:
- python-version: '3.10-dev'
experimental: true
max-parallel: 2 # Reduce load on the geocoding services
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools
python3 -m pip install tox tox-gh-actions
- run: tox
env:
# GitHub Actions cannot just pass all secrets as env vars :(
ALGOLIA_PLACES_API_KEY: ${{ secrets.ALGOLIA_PLACES_API_KEY }}
ALGOLIA_PLACES_APP_ID: ${{ secrets.ALGOLIA_PLACES_APP_ID }}
ARCGIS_PASSWORD: ${{ secrets.ARCGIS_PASSWORD }}
ARCGIS_REFERER: ${{ secrets.ARCGIS_REFERER }}
ARCGIS_USERNAME: ${{ secrets.ARCGIS_USERNAME }}
AZURE_SUBSCRIPTION_KEY: ${{ secrets.AZURE_SUBSCRIPTION_KEY }}
BAIDU_KEY: ${{ secrets.BAIDU_KEY }}
BAIDU_KEY_REQUIRES_SK: ${{ secrets.BAIDU_KEY_REQUIRES_SK }}
BAIDU_SEC_KEY: ${{ secrets.BAIDU_SEC_KEY }}
BAIDU_V3_KEY: ${{ secrets.BAIDU_V3_KEY }}
BAIDU_V3_KEY_REQUIRES_SK: ${{ secrets.BAIDU_V3_KEY_REQUIRES_SK }}
BAIDU_V3_SEC_KEY: ${{ secrets.BAIDU_V3_SEC_KEY }}
BING_KEY: ${{ secrets.BING_KEY }}
GEOCODEEARTH_KEY: ${{ secrets.GEOCODEEARTH_KEY }}
GEOLAKE_KEY: ${{ secrets.GEOLAKE_KEY }}
GEONAMES_USERNAME: ${{ secrets.GEONAMES_USERNAME }}
GOOGLE_KEY: ${{ secrets.GOOGLE_KEY }}
HERE_APIKEY: ${{ secrets.HERE_APIKEY }}
HERE_APP_CODE: ${{ secrets.HERE_APP_CODE }}
HERE_APP_ID: ${{ secrets.HERE_APP_ID }}
IGNFRANCE_KEY: ${{ secrets.IGNFRANCE_KEY }}
IGNFRANCE_REFERER: ${{ secrets.IGNFRANCE_REFERER }}
LIVESTREETS_AUTH_ID: ${{ secrets.LIVESTREETS_AUTH_ID }}
LIVESTREETS_AUTH_TOKEN: ${{ secrets.LIVESTREETS_AUTH_TOKEN }}
MAPBOX_KEY: ${{ secrets.MAPBOX_KEY }}
MAPQUEST_KEY: ${{ secrets.MAPQUEST_KEY }}
MAPTILER_KEY: ${{ secrets.MAPTILER_KEY }}
OPENCAGE_KEY: ${{ secrets.OPENCAGE_KEY }}
OPENMAPQUEST_APIKEY: ${{ secrets.OPENMAPQUEST_APIKEY }}
PICKPOINT_KEY: ${{ secrets.PICKPOINT_KEY }}
TOMTOM_KEY: ${{ secrets.TOMTOM_KEY }}
WHAT3WORDS_KEY: ${{ secrets.WHAT3WORDS_KEY }}
YANDEX_KEY: ${{ secrets.YANDEX_KEY }}
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

33 changes: 20 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ If your PR remains unreviewed for a while, feel free to bug the maintainer.

### Running tests

To run the full test suite:
To quickly run the test suite without Internet access:

make test-local

To run the full test suite (makes queries to the geocoding services):

make test

Expand All @@ -58,7 +62,7 @@ For example:

pytest test/geocoders/nominatim.py

Before pushing your code, make sure that linting passes, otherwise Travis
Before pushing your code, make sure that linting passes, otherwise a CI
build would fail:

make lint
Expand All @@ -70,21 +74,24 @@ Some geocoders require credentials (like API keys) for testing. They must
remain secret, so if you need to test a code which requires them, you should
obtain your own valid credentials.

Travis CI builds for PRs from forks don't have access to these
credentials to avoid the possibility of leaking the secrets by running
untrusted code. This is a [Travis CI policy][travis_env]. It means that CI
builds for PRs from forks won't test the code which require credentials.
Such code should be tested locally. But it's acceptable to not test such code
if obtaining the required credentials seems problematic: just leave a note
so the maintainer would be aware that the code hasn't been tested.

[travis_env]: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
Tests in CI from forks and PRs run in `test-local` mode only, i.e. no network
requests are performed. Full test suite with network requests is run only
for pushes to branches by maintainers. This
helps to reduce load on the geocoding services and save some quotas associated
with the credentials used by geopy. It means that PR builds won't actually test
network requests. Code changing a geocoder should be tested locally.
But it's acceptable to not test such code if obtaining the required credentials
seems problematic: just leave a note
so the maintainers would be aware that the code hasn't been tested.

You may wonder: why not commit captured data and run mocked tests?
Because there are copyright constraints on the data returned by services.
Another reason is that this data goes obsolete quite fast, and maintaining
it is cumbersome.

The credentials can be stored in a json format in a file called `.test_keys`
located at the root of the project instead of env variables for convenience.
To ease local testing the credentials can be stored in a json format
in a file called `.test_keys` located at the root of the project
instead of env variables.

Example contents of `.test_keys`:

Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ develop: venv piplocal

.PHONY: lint lint-flake8 lint-isort
lint-flake8:
flake8
flake8 geopy test *.py
lint-isort:
isort --check-only -rc geopy test *.py
isort --check-only geopy test *.py
lint: lint-flake8 lint-isort

.PHONY: format
format:
isort -rc geopy test *.py
isort geopy test *.py

.PHONY: test
test:
# Run tests without Internet first. These are fast and help to avoid
# spending geocoders quota for test runs which would fail anyway.
.PHONY: test-local
test-local:
@# Run tests without Internet. These are fast and help to avoid
@# spending geocoders quota for test runs which would fail anyway.
python -m pytest --skip-tests-requiring-internet

.PHONY: test
test: test-local
# Run tests with Internet:
coverage run -m py.test
coverage report
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ geopy
:target: https://pypi.python.org/pypi/geopy/
:alt: Latest Version

.. image:: https://img.shields.io/travis/geopy/geopy.svg?style=flat-square
:target: https://travis-ci.org/geopy/geopy
.. image:: https://img.shields.io/github/workflow/status/geopy/geopy/CI?style=flat-square
:target: https://github.com/geopy/geopy/actions
:alt: Build Status

.. image:: https://img.shields.io/github/license/geopy/geopy.svg?style=flat-square
Expand Down
10 changes: 0 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
[flake8]
max-complexity = 24
max-line-length = 90
exclude =
.git,
.tox,
.venv,
__pycache__,
build,
dist,
docs,
geopy.egg-info

[isort]
; https://github.com/timothycrosley/isort#multi-line-output-modes
Expand All @@ -19,4 +10,3 @@ include_trailing_comma = True
known_first_party = test
line_length = 88
multi_line_output = 3
not_skip = __init__.py
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
]

EXTRAS_DEV_LINT = [
"flake8>=3.6.0,<3.7.0",
"isort>=4.3.4,<4.4.0",
"flake8>=3.8.0,<3.9.0",
"isort>=5.6.0,<5.7.0",
]

EXTRAS_DEV_TEST = [
Expand Down
4 changes: 2 additions & 2 deletions test/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def test_miscellaneous_high_accuracy_cases(self):
13487015.8381145492]]
d = self.cls(ellipsoid='WGS-84')
km = 1000
for l in testcases:
(lat1, lon1, azi1, lat2, lon2, azi2, s12) = l
for tup in testcases:
(lat1, lon1, azi1, lat2, lon2, azi2, s12) = tup
p1, p2 = Point(lat1, lon1), Point(lat2, lon2)
s12a = d.measure(p1, p2) * km
self.assertAlmostEqual(s12a, s12, delta=1e-8)
Expand Down
25 changes: 23 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
[tox]
envlist=py{35,36,37,38,39,310},pypy3,lint,rst
envlist=
py{35,36,37,38,39,310,py3},
py35-async,
lint,
rst,

[testenv]
extras =
dev-test
aiohttp
requests
timezone
passenv = *
whitelist_externals = make
commands = make test
commands = make {env:GEOPY_TOX_TARGET:test}

[testenv:py35-async]
# Run a single job with asyncio adapter:
# (not the whole matrix, to avoid spending extra quota)
setenv = GEOPY_TEST_ADAPTER=geopy.adapters.AioHTTPAdapter

[gh-actions]
python =
3.5: py35
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310
pypy3: pypy3

[testenv:lint]
basepython = python3
extras =
dev-lint
usedevelop = True
commands = make lint

[testenv:rst]
Expand Down

0 comments on commit bf5d33c

Please sign in to comment.