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

refactor: Refactor pyrorisks #83

Merged
merged 41 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a7325f2
refactor: Remove heroku deployment files
jsakv Jul 2, 2024
339b5c3
refactor: Remove DVC CML pipelines
jsakv Jul 2, 2024
4db972a
chore: Remove notebooks from package
jsakv Jul 2, 2024
c39bdec
refactor: Deprecate pyro_risks modules
jsakv Jul 2, 2024
16467db
refactor: Remove pyro_risks CLI
jsakv Jul 2, 2024
f0260de
refactor: Deprecate example scripts
jsakv Jul 2, 2024
75f7a64
refactor: Deprecate pyro_risks tests
jsakv Jul 2, 2024
82b70d2
refactor: Rename package
jsakv Jul 2, 2024
7591d58
refactor: Add setup.py
jsakv Jul 2, 2024
5cb8326
refactor: Patch package version
jsakv Jul 2, 2024
6fb76a7
refactor: Patch package version
jsakv Jul 2, 2024
baeb141
refactor: Deprecate module documentation
jsakv Jul 2, 2024
dd92714
chore: Add Mock predictor
jsakv Jul 2, 2024
2abe79c
fix: Update dockerfile package name
jsakv Jul 2, 2024
58719d1
refactor: Remove setup.py
jsakv Jul 2, 2024
34265a9
refactor: Remove config tooling
jsakv Jul 2, 2024
b6060f9
refactor: Add poetry
jsakv Jul 2, 2024
05f4ad6
refactor: Update dockerfile
jsakv Jul 2, 2024
db8c305
refactor: Add dependencies explicitly
jsakv Jul 3, 2024
706d910
refactor: Update app deployment
jsakv Jul 3, 2024
665c8a4
chore: Remove docs requirements.txt
jsakv Jul 9, 2024
639e154
chore: Remove CI requirements.txt
jsakv Jul 9, 2024
529e6b3
chore: Add rasterio manylinux wheel
jsakv Jul 9, 2024
b5cfad5
chore: Update project dependencies
jsakv Jul 9, 2024
bc1a75b
chore: Add build directory to image
jsakv Jul 9, 2024
4c66986
refactor: Refactor FWI workflow
jsakv Jul 9, 2024
9824a0e
chore: Bump action version
jsakv Jul 9, 2024
ff01731
chore: Update style workflow
jsakv Jul 9, 2024
85f2924
chore: Bump ruff version
jsakv Jul 9, 2024
93bc966
chore: Update style workflow
jsakv Jul 9, 2024
94599ba
chore: Add builds workflow
jsakv Jul 9, 2024
e1c1172
chore: Refactor docs workflow
jsakv Jul 9, 2024
4a17f69
style: Format repository
jsakv Jul 9, 2024
4e8a5fc
fix: Add init files for mypy
jsakv Jul 9, 2024
27ef4de
fix: Update mypy config and version
jsakv Jul 9, 2024
264e332
chore: Ignore mypy method assign
jsakv Jul 9, 2024
84bc6fe
fix: Fix pydantic field key-word argument
jsakv Jul 9, 2024
f6eb65f
fix: Fix type hints
jsakv Jul 9, 2024
fc6621e
fix: Fix pydantic field key-word argument
jsakv Jul 9, 2024
14e2151
fix: Use idiomatic type check
jsakv Jul 9, 2024
996a301
chore: Remove black
jsakv Jul 11, 2024
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
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

3 changes: 0 additions & 3 deletions .dvc/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .dvc/config

This file was deleted.

3 changes: 0 additions & 3 deletions .dvcignore

This file was deleted.

4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: web-server
name: builds

on:
push:
Expand All @@ -7,14 +7,14 @@ on:
branches: [ master ]

jobs:
docker-ready:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build & run docker
- uses: actions/checkout@v4
- name: Build & run docker container
env:
CDS_UID: ${{ secrets.CDS_UID }}
CDS_API_KEY: ${{ secrets.CDS_API_KEY }}
run: PORT=8003 docker-compose up -d --build
- name: Ping app inside the container
- name: Ping containerized app
run: sleep 5 && nc -vz localhost 8003
28 changes: 8 additions & 20 deletions .github/workflows/doc-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
name: doc-deploy
on:
push:
branches: master
branches: [master]

jobs:
docs-publish:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Set up Python 3.7
- name: Set up Python 3.10.5
uses: actions/setup-python@v1
with:
python-version: 3.7
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ hashFiles('requirements.txt') }}-${{ hashFiles('**/*.py') }}
restore-keys: |
${{ runner.os }}-pkg-deps-${{ hashFiles('requirements.txt') }}-
${{ runner.os }}-pkg-deps-
${{ runner.os }}-
python-version: 3.10.5

- name: Install dependencies
run: |
sudo apt install libspatialindex-dev python3-rtree
python -m pip install --upgrade pip
pip install -e .
pip install -r docs/requirements.txt
run: poetry install


- name: Build documentation
run: |
sphinx-build docs/source docs/build -a -v
poetry run sphinx-build docs/source docs/build -a -v

- name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
see-page-build-payload:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v1
- name: Set up Python 3.10.5
uses: actions/setup-python@v4
with:
python-version: 3.7
architecture: x64
python-version: 3.10.5

- name: check status
run: |
import os
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/get_today_effis_fwi.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/main.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/requirements.txt

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Scheduled Scripts

on:
workflow_dispatch:
schedule:
- cron: "0 1 * * *"

jobs:
get-effis-fwi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Get Today Effis Fwi
run: poetry run python pyrorisks/platform_fwi/main.py
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
BUCKET_NAME: risk
REGION_NAME: gra
ENDPOINT_URL: https://s3.gra.io.cloud.ovh.net/

80 changes: 80 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: style

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

jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run Ruff linter
run: |
poetry run ruff --version
poetry run ruff check --diff .

formating:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run Ruff formatter
run: |
poetry run ruff --version
poetry run ruff format --diff .

typing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run mypy
run: |
poetry run mypy --version
poetry run mypy app pyrorisks
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/

# Distribution / packaging
.Python
build/
docs/build/
develop-eggs/
dist/
downloads/
Expand Down
2 changes: 0 additions & 2 deletions Aptfile

This file was deleted.

37 changes: 14 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
FROM python:3.8.1
FROM python:3.10-buster

# set work directory
WORKDIR /usr/src/app
RUN pip install poetry==1.8.1

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

# copy app requirements
COPY ./requirements.txt requirements.txt
COPY ./requirements-app.txt /usr/src/app/requirements-app.txt
COPY ./setup.py setup.py
COPY ./README.md README.md
COPY ./pyro_risks pyro_risks
WORKDIR /app

# install dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y libspatialindex-dev python3-rtree && \
pip install --upgrade pip setuptools wheel && \
pip install -e . && \
pip install -r /usr/src/app/requirements-app.txt && \
mkdir /usr/src/app/app && \
rm -rf /root/.cache/pip && \
rm -rf /var/lib/apt/lists/*
COPY pyrorisks ./pyrorisks
COPY app ./app
COPY build ./build
COPY pyproject.toml poetry.lock README.md ./

# copy project
COPY app/ /usr/src/app/app/
RUN poetry install
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions app/api/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# This program is licensed under the Apache License version 2.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.

from pyro_risks.models.predict import PyroRisk


__all__ = ["predictor"]


predictor = PyroRisk(which="RF")
class Mock:
def predict(self, date):
_ = date
return {"01": {"score": 0.5, "explainability": "weather"}, "02": {"score": 0.5, "explainability": "weather"}}


predictor = Mock()
Empty file added app/api/routes/__init__.py
Empty file.
5 changes: 1 addition & 4 deletions app/api/routes/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@
async def get_pyrorisk(country: str, date: str):
"""Using the country identifier, this will compute the wildfire risk for all known subregions"""
preds = predictor.predict(date)
return [
RegionRisk(geocode=k, score=v["score"], explainability=v["explainability"])
for k, v in preds.items()
]
return [RegionRisk(geocode=k, score=v["score"], explainability=v["explainability"]) for k, v in preds.items()]
Loading
Loading