Skip to content

Commit

Permalink
Create python-package.yml (#1)
Browse files Browse the repository at this point in the history
* Create python-package.yml

* fix cicd: install tomtom_api as dep

* fix: force timestamp types when reading database from file

---------

Co-authored-by: Guillaume Latour <guillaume.latour@macq.eu>
  • Loading branch information
Tazoeur and Guillaume Latour authored May 24, 2023
1 parent 4d446e5 commit 993e9cf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install -r requirements-all.txt
pip install .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
3 changes: 1 addition & 2 deletions src/tomtom_api/priority_queue/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def priority_queue_update_job(

item: QueueItem = db.get_filtered_items(uid=uid)[0]
item.update(name, priority, cancel, payload)
db.update([item])
db.write()
db.update([item], force_write=True)


def pretty_print_queue(queue: List[QueueItem]) -> str:
Expand Down
12 changes: 12 additions & 0 deletions src/tomtom_api/priority_queue/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ def __init__(self):
self.df = None
self.read()

def _force_col_types(self) -> None:
for time_col in ['created_timestamp',
'updated_timestamp',
'submitted_timestamp',
'completed_timestamp',
'cancelled_timestamp',
'error_timestamp']:
self.df[time_col] = pd.to_datetime(self.df[time_col])

def read(self) -> None:
"""Read the file and store the content in the dataframe attribute.
"""
if not self.file.exists():
self.df = pd.DataFrame(columns=self.columns)
else:
self.df = pd.read_parquet(self.file)
self._force_col_types()

def write(self) -> None:
"""Write the content of the dataframe into the file.
Expand Down Expand Up @@ -74,6 +84,7 @@ def add(self, item: QueueItem) -> None:
data = {k: item.__dict__[k] for k in self.columns}
data['report_type'] = item.payload.__class__.__name__
self.df = pd.concat([self.df, pd.DataFrame([data])])
self._force_col_types()

def get_next(self, n: int = 1) -> List[QueueItem]:
"""Get the list of the next element(s)
Expand Down Expand Up @@ -225,3 +236,4 @@ def empty(self) -> None:
"""Empty the database
"""
self.df = pd.DataFrame(columns=self.columns)
self._force_col_types()

0 comments on commit 993e9cf

Please sign in to comment.