Skip to content

Commit

Permalink
fixing pylint issues, updating github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelgreca committed Nov 13, 2024
1 parent d8b82b1 commit 830a51e
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 350 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/deploy_on_release.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- 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
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --rcfile=.pylintrc
14 changes: 7 additions & 7 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest black
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
- name: Python Black
run: |
pip install black==24.10.0
black . --check
- name: Test with pytest
run: |
pytest --cov-report html:./results/cov_html --cov=src tests/
35 changes: 0 additions & 35 deletions .github/workflows/train_evaluate.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ coverage.xml
docs/_build/

# PyBuilder
target/
target/
17 changes: 8 additions & 9 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ analyse-fallback-blocks=no

# Clear in-memory caches upon conclusion of linting. Useful if running pylint
# in a server-like mode.
clear-cache-post-run=no
# clear-cache-post-run=no

# Load and enable all available extensions. Use --list-extensions to see a list
# all available extensions.
Expand Down Expand Up @@ -89,7 +89,7 @@ persistent=yes

# Resolve imports to .pyi stubs if available. May reduce no-member messages and
# increase not-an-iterable messages.
prefer-stubs=no
# prefer-stubs=no

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
Expand All @@ -102,7 +102,7 @@ recursive=no
# source root is an absolute path or a path relative to the current working
# directory used to determine a package namespace for modules located under the
# source root.
source-roots=
# source-roots=

# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
Expand Down Expand Up @@ -363,7 +363,7 @@ single-line-if-stmt=no
allow-any-import-level=

# Allow explicit reexports by alias from a package __init__.
allow-reexport-from-package=no
# allow-reexport-from-package=no

# Allow wildcard imports from modules that define __all__.
allow-wildcard-with-all=no
Expand Down Expand Up @@ -433,9 +433,8 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-implicit-booleaness-not-comparison-to-string,
use-implicit-booleaness-not-comparison-to-zero,
use-symbolic-message-instead
use-symbolic-message-instead,
duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand All @@ -448,7 +447,7 @@ enable=

# List of qualified names (i.e., library.method) which require a timeout
# parameter e.g. 'requests.api.get,requests.api.post'
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
# timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request


[MISCELLANEOUS]
Expand Down Expand Up @@ -476,7 +475,7 @@ never-returning-functions=sys.exit,argparse.parse_error
# Let 'consider-using-join' be raised when the separator to join on would be
# non-empty (resulting in expected fixes of the type: ``"- " + " -
# ".join(items)``)
suggest-join-with-non-empty-separator=yes
# suggest-join-with-non-empty-separator=yes


[REPORTS]
Expand Down
Empty file removed __init__.py
Empty file.
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ services:
# exposing the port that will be used by MLFlow and Jupyter Notebook
ports:
- "8888:8888"

# setting external volumes
volumes:
- ./credentials.yaml:/e2e-project/credentials.yaml
- ./models:/e2e-project/models/
- ./data:/e2e-project/data/

dev-mlflow:
image: e2e-dev:latest
build:
Expand All @@ -39,9 +39,9 @@ services:
# exposing the port that will be used by MLFlow and Jupyter Notebook
ports:
- "5000:5000"

# setting external volumes
volumes:
- ./credentials.yaml:/e2e-project/credentials.yaml
- ./models:/e2e-project/models/
- ./data:/e2e-project/data/
- ./data:/e2e-project/data/
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
boto3==1.35.6
boto3==1.24.28
fastapi==0.115.5
joblib==1.3.2
loguru==0.7.2
mlflow==2.17.2
numpy==2.1.3
pandas==1.5.2
mlflow==2.15.1
numpy==1.21.5
pandas==1.4.4
pydantic==2.9.2
pytest==8.3.3
PyYAML==6.0.2
pytest==7.2.2
pytest-cov==6.0.0
PyYAML==6.0
scikit_learn==1.3.2
xgboost==2.1.2
xgboost==2.1.2
35 changes: 28 additions & 7 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
API's main file.
"""
from typing import Dict

import pandas as pd
import mlflow
from fastapi import FastAPI
Expand All @@ -14,15 +19,21 @@
if aws_credentials.EC2 != "YOUR_EC2_INSTANCE_URL":
mlflow.set_tracking_uri(f"http://{aws_credentials.EC2}:5000")
else:
mlflow.set_tracking_uri(f"http://127.0.0.1:5000")
mlflow.set_tracking_uri("http://127.0.0.1:5000")


@app.get("/version")
def check_versions():
def check_versions() -> Dict:
"""
This endpoint will return the current model and code versions.
Returns:
Dict: the model and code versions.
"""
with open(
f"{general_settings.RESEARCH_ENVIRONMENT_PATH}/VERSION", "r", encoding="utf-8"
) as f:
code_version = f.readline().strip()
) as file:
code_version = file.readline().strip()

return {
"code_version": code_version,
Expand All @@ -31,7 +42,17 @@ def check_versions():


@app.get("/predict")
async def prediction(person: Person):
async def prediction(person: Person) -> Dict:
"""
This endpoint is used to make a prediction (with the trained model)
with the given data.
Args:
person (Person): a person's data.
Returns:
Dict: the predictions.
"""
loaded_model = ModelServe(
model_name=model_settings.MODEL_NAME,
model_flavor=model_settings.MODEL_FLAVOR,
Expand All @@ -40,6 +61,6 @@ async def prediction(person: Person):
loaded_model.load()

data = pd.DataFrame.from_dict([person.model_dump()])
X = data_processing_inference(data)
features = data_processing_inference(data)

return {"predictions": loaded_model.predict(X).tolist()}
return {"predictions": loaded_model.predict(features).tolist()}
3 changes: 3 additions & 0 deletions src/config/aws.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Creates a Pydantic's base model for the AWS' credentials.
"""
from pathlib import Path

from pydantic import BaseModel
Expand Down
3 changes: 3 additions & 0 deletions src/config/kaggle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Creates a Pydantic's base model for the Kaggle's credentials.
"""
from pathlib import Path
from pydantic import BaseModel

Expand Down
3 changes: 3 additions & 0 deletions src/config/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Creates a Pydantic's base model for the model's configuration.
"""
from typing import List

from pathlib import Path
Expand Down
3 changes: 3 additions & 0 deletions src/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Creates a Pydantic's base model for the general configuration settings.
"""
import os
from pathlib import Path

Expand Down
Loading

0 comments on commit 830a51e

Please sign in to comment.