Skip to content

Commit

Permalink
Merge pull request #269 from sigmadawg/add-pylint
Browse files Browse the repository at this point in the history
re-worked on #Add pylint workflow and fix all issues"
  • Loading branch information
djeck1432 authored Nov 1, 2024
2 parents fd94afd + d12357d commit 93148b5
Show file tree
Hide file tree
Showing 117 changed files with 1,625 additions and 1,394 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Pylint Check

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Debug Information
run: |
echo "Current directory:"
pwd
echo "\nDirectory structure:"
ls -R
echo "\nGit root directory:"
git rev-parse --show-toplevel
echo "\nSearching for Python files:"
find . -name "*.py"
echo "\nGit ls-files output:"
git ls-files
echo "\nSpecific path search:"
git ls-files 'data_handler/*.py'
git ls-files './data_handler/*.py'
git ls-files 'apps/data_handler/*.py'
git ls-files './apps/data_handler/*.py'
- name: Run Pylint
run: |
PYTHON_FILES=$(find ./apps/data_handler -name "*.py")
if [ -n "$PYTHON_FILES" ]; then
echo "Files to lint: $PYTHON_FILES"
python -m pylint $PYTHON_FILES --disable=all --enable=C0114,C0115,C0116,C0301 --max-line-length=150
else
echo "No Python files found in apps/data_handler/"
exit 1
fi
1 change: 1 addition & 0 deletions apps/data_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Module docstring placeholder."""

7 changes: 7 additions & 0 deletions apps/data_handler/celery_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This module initializes the Celery application for the data handler.
It sets up the necessary configurations and integrates with the broader
application to manage asynchronous tasks efficiently.
"""

27 changes: 23 additions & 4 deletions apps/data_handler/celery_app/celery_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""
Celery configuration for scheduling periodic tasks.
"""

# run_loan_states_computation_for_hashtack_v0,;
# run_loan_states_computation_for_hashtack_v1,; run_loan_states_computation_for_nostra_alpha,;
# run_loan_states_computation_for_nostra_mainnet,; run_loan_states_computation_for_zklend,;
# run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
# run_liquidable_debt_computation_for_hashstack_v0,;
# run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,

from data_handler.celery_app.tasks import (
run_liquidable_debt_computation_for_zklend, )
from data_handler.celery_app.order_books_tasks import ekubo_order_book
import os

from celery import Celery
Expand All @@ -10,10 +25,8 @@
REDIS_HOST = os.environ.get("REDIS_HOST", "")
REDIS_PORT = os.environ.get("REDIS_PORT", 6379)


ORDER_BOOK_TIME_INTERVAL = int(os.environ.get("ORDER_BOOK_TIME_INTERVAL", 5))


app = Celery(
main="DataHandler",
broker=f"redis://{REDIS_HOST}:{REDIS_PORT}/0",
Expand Down Expand Up @@ -59,7 +72,13 @@

from data_handler.celery_app.order_books_tasks import ekubo_order_book
from data_handler.celery_app.tasks import (
run_liquidable_debt_computation_for_zklend,
) # run_loan_states_computation_for_hashtack_v0,; run_loan_states_computation_for_hashtack_v1,; run_loan_states_computation_for_nostra_alpha,; run_loan_states_computation_for_nostra_mainnet,; run_loan_states_computation_for_zklend,; run_liquidable_debt_computation_for_nostra_alpha,; run_liquidable_debt_computation_for_nostra_mainnet,; run_liquidable_debt_computation_for_hashstack_v0,; run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,
run_liquidable_debt_computation_for_zklend, )

# run_loan_states_computation_for_hashtack_v0,; run_loan_states_computation_for_hashtack_v1,;
# run_loan_states_computation_for_nostra_alpha,; run_loan_states_computation_for_nostra_mainnet,;
# run_loan_states_computation_for_zklend,; run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
# run_liquidable_debt_computation_for_hashstack_v0,;
# run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,

app.autodiscover_tasks(["celery_app.tasks", "celery_app.order_books_tasks"])
18 changes: 7 additions & 11 deletions apps/data_handler/celery_app/order_books_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Tasks for fetching and storing order book data from Ekubo and Haiko APIs.
"""

import logging

from data_handler.celery_app.celery_conf import app
Expand All @@ -19,27 +22,20 @@ def ekubo_order_book():
"""
pool_states = EkuboAPIConnector().get_pools()
filtered_pool_states = [
pool_state
for pool_state in pool_states
if isinstance(pool_state, dict)
and pool_state["token0"] in TOKEN_MAPPING
and pool_state["token1"] in TOKEN_MAPPING
pool_state for pool_state in pool_states if isinstance(pool_state, dict)
and pool_state["token0"] in TOKEN_MAPPING and pool_state["token1"] in TOKEN_MAPPING
]
for pool_state in filtered_pool_states:
token_a = pool_state["token0"]
token_b = pool_state["token1"]
logging.getLogger().info(
f"Fetching data for token pair: {token_a} and {token_b}"
)
logging.getLogger().info(f"Fetching data for token pair: {token_a} and {token_b}")
try:
order_book = EkuboOrderBook(token_a, token_b)
order_book.fetch_price_and_liquidity()
serialized_data = order_book.serialize()
connector.write_to_db(OrderBookModel(**serialized_data.model_dump()))
except Exception as exc:
logger.info(
f"With token pair: {token_a} and {token_b} something happened: {exc}"
)
logger.info(f"With token pair: {token_a} and {token_b} something happened: {exc}")
continue


Expand Down
12 changes: 9 additions & 3 deletions apps/data_handler/celery_app/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Celery tasks for running loan state and liquidable debt computations,
and fetching Uniswap V2 order book data."""

import logging
from time import monotonic

Expand Down Expand Up @@ -27,7 +30,6 @@

connector = DBConnector()


# @app.task(name="run_loan_states_computation_for_hashtack_v0")
# def run_loan_states_computation_for_hashtack_v0():
# start = monotonic()
Expand All @@ -42,7 +44,6 @@
# monotonic() - start,
# )


# @app.task(name="run_loan_states_computation_for_hashtack_v1")
# def run_loan_states_computation_for_hashtack_v1():
# start = monotonic()
Expand All @@ -57,7 +58,6 @@
# monotonic() - start,
# )


# @app.task(name="run_loan_states_computation_for_zklend")
# def run_loan_states_computation_for_zklend():
# start = monotonic()
Expand All @@ -75,6 +75,7 @@

@app.task(name="run_loan_states_computation_for_nostra_alpha")
def run_loan_states_computation_for_nostra_alpha():
"""fn docstring"""
start = monotonic()
logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -126,34 +127,39 @@ def uniswap_v2_order_book():

@app.task(name="run_liquidable_debt_computation_for_zklend")
def run_liquidable_debt_computation_for_zklend():
"""fn docstring"""
logging.info("Starting zkLend liquidable debt computation")
zklend.run()
logging.info("zkLend liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_nostra_alpha")
def run_liquidable_debt_computation_for_nostra_alpha():
"""fn docstring"""
logging.info("Starting nostra alpha liquidable debt computation")
nostra_alpha.run()
logging.info("Nostra alpha liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_hashstack_v0")
def run_liquidable_debt_computation_for_hashstack_v0():
"""fn docstring"""
logging.info("Starting hashstack v0 liquidable debt computation")
hashstack_v0.run()
logging.info("Hashstack v0 liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_nostra_mainnet")
def run_liquidable_debt_computation_for_nostra_mainnet():
"""fn docstring"""
logging.info("Starting nostra mainnet liquidable debt computation")
nostra_mainnet.run()
logging.info("Nostra mainnet liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_hashstack_v1")
def run_liquidable_debt_computation_for_hashstack_v1():
"""fn docstring"""
logging.info("Starting hashstack v1 liquidable debt computation")
hashstack_v1.run()
logging.info("Hashstack v1 liquidable debt computation finished")
8 changes: 8 additions & 0 deletions apps/data_handler/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
"""
This module initializes the database connection and imports necessary components.
It imports:
- `SQLALCHEMY_DATABASE_URL`: The URL for the SQLAlchemy database connection.
- `Base`: The declarative base class for SQLAlchemy models.
"""

from data_handler.db.database import SQLALCHEMY_DATABASE_URL, Base
Loading

0 comments on commit 93148b5

Please sign in to comment.