Skip to content

Commit

Permalink
GO-22: Setup Basic CI on GitHub (#496)
Browse files Browse the repository at this point in the history
* Setup Basic CI on GitHub

* Update mermaid CI in README

* Update python versions

* Clean up CI execution
  • Loading branch information
mgeiger committed Dec 21, 2022
1 parent 0dde564 commit 8cd84c5
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 34 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: CI

on:
push:
Expand All @@ -10,8 +10,7 @@ on:
branches: [ $default-branch ]

jobs:
build:

ci-execution:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -29,12 +28,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install flake8 pytest mypy
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
- name: Type Checking
run: |
mypy $(git ls-files "*.py")
# - name: Type Checking
# run: |
# mypy --install-types
# mypy $(git ls-files "*.py")

- name: Lint with flake8
run: |
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/deployment.yml
@@ -0,0 +1,14 @@
# This Workflow will ensure that we have pushed to the main branch
# Then ensure we can properly package the product
# Then deploy with a version to pypy
name: Deploy Python Package
on:
pull_request:
branches:
- "main"
jobs:
deploy-package:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Setting System Up"
4 changes: 2 additions & 2 deletions .github/workflows/pylint.yml
Expand Up @@ -3,11 +3,11 @@ name: Pylint
on: [push]

jobs:
build:
pylint-execution:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/static-analysis.yml
@@ -0,0 +1,26 @@
# This Action will perform all static analysis on the code under question
# Static Analysis will consist of:
# flake8 - Style Enforcement
# mypy - Type Checking
# black - Formatting Check
# radon - Cycloclometric Complexity
name: Static Analysis

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Environment setup
run: echo "Running Setup"
- name: Flake8
run: echo "Executing Flake8 Checks"
if: github.head_ref == 'main'
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,18 @@
name: Tests Execution
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
jobs:
python-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Test
run: echo "running tests"
- name: Deploy
run: echo "Deploying"
if: github.head_ref == 'main'
25 changes: 25 additions & 0 deletions README.rst
Expand Up @@ -65,6 +65,31 @@ Import

Not properly implemented.


CI Setup
~~~~~~~~

.. mermaid::
:alt: The image alternate text for HTML output
:align: center
:caption: Caption Text underneath the generated image

sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?
loop Healthcheck
John->John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail...
John-->Alice: Great!
John->Bob: How about you?



Bob-->John: Jolly good!


Credits
-------

Expand Down
37 changes: 19 additions & 18 deletions gotime/providers.py
@@ -1,6 +1,7 @@
import time

import requests
from typing import Optional


class Location:
Expand Down Expand Up @@ -63,7 +64,7 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json

Expand Down Expand Up @@ -103,7 +104,7 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json
resource = data['resourceSets'][0]['resources'][0]
Expand Down Expand Up @@ -151,7 +152,7 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json
legs = data['routes'][0]['legs']
Expand Down Expand Up @@ -197,22 +198,22 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None) -> None:
if data is None:
data = self._last_json
summary = data['response']['route'][0]['summary']
summary = data['response']['route'][0]['summary'] # type: ignore
distance = summary['distance'] / 1000.0
duration = summary['trafficTime']
self._last_result = Result(
provider=self.name,
distance=distance,
duration=duration
)
) # type: ignore

def get_result(self, start: Location, end: Location) -> Result:
self._request_data(start, end)
self._parse_data()
return self._last_result
return self._last_result # type: ignore

def __str__(self):
return f"<{self.__class__.__bases__[0].__name__}> {self.name}: {self.primary[:6]}, {self.secondary[:6]}"
Expand All @@ -237,22 +238,22 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json
route = data['routes'][0]
route = data['routes'][0] # type: ignore
distance = route['distance'] / 1000.0
duration = route['duration']

self._last_result = Result(
provider=self.name,
distance=distance,
duration=duration)
duration=duration) # type: ignore

def get_result(self, start: Location, end: Location) -> Result:
self._request_data(start, end)
self._parse_data()
return self._last_result
return self._last_result # type: ignore

def __str__(self):
return f"<{self.__class__.__bases__[0].__name__}> {self.name}: {self.key[:6]}"
Expand All @@ -278,22 +279,22 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json
route = data['route']
route = data['route'] # type: ignore
distance = route['distance']
duration = route['realTime']
fuel_used = route['fuelUsed']
steps = len(route['legs'][0]['maneuvers'])
self._last_result = Result(provider=self.name, distance=distance,
duration=duration, steps=steps,
fuel_used=fuel_used)
fuel_used=fuel_used) # type: ignore

def get_result(self, start: Location, end: Location) -> Result:
self._request_data(start, end)
self._parse_data()
return self._last_result
return self._last_result # type: ignore

def __str__(self):
return f"<{self.__class__.__bases__[0].__name__}> {self.name}: key={self.key[:6]}"
Expand All @@ -314,16 +315,16 @@ def _request_data(self, start: Location, end: Location):
r = requests.get(url)
self._last_json = r.json()

def _parse_data(self, data: dict = None):
def _parse_data(self, data: Optional[dict] = None):
if data is None:
data = self._last_json
summary = data['routes'][0]['summary']
summary = data['routes'][0]['summary'] # type: ignore
# TODO: What is the storage data units?
duration = summary['travelTimeInSeconds']
distance = summary['lengthInMeters'] / 1000.0
self._last_result = Result(provider=self.name,
distance=distance,
duration=duration)
duration=duration) # type: ignore

def get_result(self, start: Location, end: Location):
self._request_data(start, end)
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -26,9 +26,8 @@
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
description="How long does it take to get from Point A to Point B",
entry_points={
Expand Down
2 changes: 0 additions & 2 deletions tests/test_command_line.py
Expand Up @@ -41,5 +41,3 @@ def test_command_line_help(runner):
assert help_result.exit_code == 0
assert '--help' in help_result.output
assert 'Show this message and exit.' in help_result.output


1 change: 0 additions & 1 deletion tests/test_gotime.py
Expand Up @@ -51,4 +51,3 @@ def test_google_maps_failure():
print(times)
print(Keys.GOOGLE)
assert times[Keys.GOOGLE], "{} not found in {}".format(Keys.GOOGLE, times)

9 changes: 9 additions & 0 deletions tests/test_providers.py
@@ -0,0 +1,9 @@
import pytest

from gotime.providers import Provider


def test_provider():
provider = Provider()
with pytest.raises(NotImplementedError):
provider.get_result(None, None)

0 comments on commit 8cd84c5

Please sign in to comment.