From 36a49c6a94e472167f0e94a65f175b6eb6a2fae0 Mon Sep 17 00:00:00 2001 From: rilesdun Date: Sun, 17 Sep 2023 00:03:12 +0000 Subject: [PATCH] pylint fixes --- .github/workflows/python-app.yml | 39 ------------------------- .gitignore | 3 ++ app.py | 4 +-- cache_config.py | 5 +++- config.py | 9 ++++-- gunicorn_config.py | 10 +++++-- src/accounts/account_history.py | 7 +++-- src/accounts/get_account.py | 6 ++++ src/accounts/sons/active_sons.py | 2 +- src/get_latest_transactions.py | 11 ++++++- src/{latestBlock.py => latest_block.py} | 11 +++++-- src/supply/circulating_supply.py | 11 +++++-- src/supply/common.py | 15 +++++++--- src/supply/max_supply.py | 9 +++++- src/supply/rich_list.py | 3 ++ src/supply/supply_details.py | 6 ++++ src/supply/total_supply.py | 9 +++++- 17 files changed, 96 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/python-app.yml rename src/{latestBlock.py => latest_block.py} (57%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index f3d4fca..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,39 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - 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 diff --git a/.gitignore b/.gitignore index 6e4031f..16b2f85 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ __pycache__/ # C extensions *.so +#vscode +.vscode/ + # npm packages node_modules/ diff --git a/app.py b/app.py index ee781fa..c79faac 100644 --- a/app.py +++ b/app.py @@ -20,7 +20,7 @@ from src.blocks import get_block_info from src.get_latest_transactions import get_latest_transactions -from src.latestBlock import get_latest_block +from src.latest_block import get_latest_block from src.supply.supply_details import get_supply_details from src.supply.max_supply import max_supply @@ -34,7 +34,7 @@ CORS(app, resources={r"/*": {"origins": "*"}}) cache.init_app(app) -logging.basicConfig(level=logging.INFO, +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - ' '%(levelname)s - %(message)s') @app.route('/api/latest_block_num', methods=['GET']) diff --git a/cache_config.py b/cache_config.py index 80ba720..d869a14 100644 --- a/cache_config.py +++ b/cache_config.py @@ -1,3 +1,6 @@ +""" +Cache configuration for the application. +""" from flask_caching import Cache -cache = Cache(config={'CACHE_TYPE': 'simple'}) \ No newline at end of file +cache = Cache(config={'CACHE_TYPE': 'simple'}) diff --git a/config.py b/config.py index 79a1e55..6b69f8f 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,10 @@ -# config.py -from dotenv import load_dotenv +""" +Function for loading .env files +""" + import os +from dotenv import load_dotenv load_dotenv() api_url = os.getenv("API_URL") -print(api_url) # Add this line \ No newline at end of file +print(api_url) diff --git a/gunicorn_config.py b/gunicorn_config.py index 8e0679b..0a91e83 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,5 +1,9 @@ +""" +Gunicorn config file +""" + import multiprocessing -bind = "0.0.0.0:5000" -worker_class = 'eventlet' -workers = multiprocessing.cpu_count() * 2 + 1 \ No newline at end of file +bind = "0.0.0.0:5000" # pylint: disable=invalid-name +worker_class = 'eventlet' # pylint: disable=invalid-name +workers = multiprocessing.cpu_count() * 2 + 1 diff --git a/src/accounts/account_history.py b/src/accounts/account_history.py index 00cfd5c..abd423b 100644 --- a/src/accounts/account_history.py +++ b/src/accounts/account_history.py @@ -8,10 +8,11 @@ peerplays = PeerPlays(api_url) -""" -retrieve account history -""" + def get_account_history(account_name): + """ + retrieve account history + """ account = Account(account_name, blockchain_instance=peerplays) account_history = list(account.history()) diff --git a/src/accounts/get_account.py b/src/accounts/get_account.py index ff5aa0a..5cd8e4e 100644 --- a/src/accounts/get_account.py +++ b/src/accounts/get_account.py @@ -1,3 +1,6 @@ +""" +This module contains the function to get account information. +""" from peerplays.account import Account from peerplays import PeerPlays from config import api_url @@ -5,6 +8,9 @@ peerplays = PeerPlays(api_url) def get_account_info(account_name): + """ + This function returns the account information for the given account name. + """ account = Account(account_name, blockchain_instance=peerplays) account_info = { "id": account["id"], diff --git a/src/accounts/sons/active_sons.py b/src/accounts/sons/active_sons.py index b61bede..8203ece 100644 --- a/src/accounts/sons/active_sons.py +++ b/src/accounts/sons/active_sons.py @@ -27,7 +27,7 @@ def get_active_sons(): account_name = account_info["name"] obj["son_account"] = account_name results.append(obj) - son_count += 1 + son_count += 1 object_id_number += 1 except Exception as error: print(f"Error fetching object {object_id}: {error}", file=sys.stderr) diff --git a/src/get_latest_transactions.py b/src/get_latest_transactions.py index 4518570..77513fe 100644 --- a/src/get_latest_transactions.py +++ b/src/get_latest_transactions.py @@ -1,3 +1,6 @@ +""" +This module is used to get the latest transactions from the Peerplays blockchain. +""" from peerplays import PeerPlays from peerplays.block import Block from config import api_url @@ -5,6 +8,9 @@ peerplays = PeerPlays(api_url) def get_block_with_transactions(block_num): + """ + This function returns the block information for the given block number. + """ block = Block(block_num, blockchain_instance=peerplays) if block["transactions"]: return { @@ -14,6 +20,9 @@ def get_block_with_transactions(block_num): return None def get_latest_transactions(num_transactions=10): + """ + This function returns the latest transactions. + """ latest_block_num = peerplays.info()["head_block_number"] transactions = [] @@ -25,4 +34,4 @@ def get_latest_transactions(num_transactions=10): if len(transactions) >= num_transactions: return transactions[:num_transactions] - return transactions \ No newline at end of file + return transactions diff --git a/src/latestBlock.py b/src/latest_block.py similarity index 57% rename from src/latestBlock.py rename to src/latest_block.py index 509d464..7a6c89c 100644 --- a/src/latestBlock.py +++ b/src/latest_block.py @@ -1,3 +1,6 @@ +""" +This file contains the function to get the latest block from the PeerPlays blockchain. +""" from peerplays.blockchain import Blockchain from peerplays import PeerPlays @@ -6,12 +9,14 @@ peerplays = PeerPlays(api_url) def get_latest_block(): + """ + This function returns the latest block from the PeerPlays blockchain. + """ chain = Blockchain(blockchain_instance=peerplays) - # Get the latest block latest_block = None for block in chain.blocks(): latest_block = block - break + break - return latest_block \ No newline at end of file + return latest_block diff --git a/src/supply/circulating_supply.py b/src/supply/circulating_supply.py index daeaddb..dc672cb 100644 --- a/src/supply/circulating_supply.py +++ b/src/supply/circulating_supply.py @@ -1,11 +1,18 @@ -from .common import get_supplies, peerplays, ASSET_IDS +""" +Circulating supply endpoint +""" from peerplays.asset import Asset from flask import Response +from src.supply.common import get_supplies, peerplays, ASSET_IDS + def circulating_supply(coin_name): + """ + This endpoint returns the circulating supply for the given coin name. + """ asset_id = ASSET_IDS.get(coin_name) if asset_id is None: return Response("Invalid coin name", status=400) A = Asset(asset_id, blockchain_instance=peerplays) supply = get_supplies(A)["circulating"] - return Response(supply, content_type='text/plain') \ No newline at end of file + return Response(supply, content_type='text/plain') diff --git a/src/supply/common.py b/src/supply/common.py index 7eb7f5b..21c9b4e 100644 --- a/src/supply/common.py +++ b/src/supply/common.py @@ -1,6 +1,7 @@ +""" +Common functions for supply endpoints +""" from peerplays.peerplays import PeerPlays -from peerplays.asset import Asset -from peerplays.amount import Amount from config import api_url peerplays = PeerPlays(api_url) @@ -14,10 +15,16 @@ } def sats_to_fixed(amount, P): + """ + Convert an amount in satoshis to a fixed point number + """ V = int(amount) / 10**P - return "{:.{prec}f}".format(V, prec=P) + return f"{V:.{P}f}" def get_supplies(asset): + """ + Get the supply details for an asset + """ P = asset["precision"] max_supply = sats_to_fixed(asset["options"]["max_supply"], P) ddo = asset.blockchain.rpc.get_objects([asset["dynamic_asset_data_id"]])[0] @@ -28,4 +35,4 @@ def get_supplies(asset): "maximum": max_supply, "total": max_supply, "circulating": current_supply - } \ No newline at end of file + } diff --git a/src/supply/max_supply.py b/src/supply/max_supply.py index d3b3d09..a2d501d 100644 --- a/src/supply/max_supply.py +++ b/src/supply/max_supply.py @@ -1,6 +1,10 @@ -from .common import get_supplies, peerplays, ASSET_IDS +""" +This module contains the max_supply function, which returns the maximum supply of a coin. +""" from peerplays.asset import Asset from flask import Response +from src.supply.common import get_supplies, peerplays, ASSET_IDS + ASSET_IDS = { "ppy": "1.3.0", @@ -12,6 +16,9 @@ } def max_supply(coin_name): + """ + This endpoint returns the maximum supply for the given coin name. + """ asset_id = ASSET_IDS.get(coin_name) if asset_id is None: return Response("Invalid coin name", status=400) diff --git a/src/supply/rich_list.py b/src/supply/rich_list.py index 11d5e7c..dfeb626 100644 --- a/src/supply/rich_list.py +++ b/src/supply/rich_list.py @@ -1,3 +1,6 @@ +""" +Rich list for a given coin +""" from peerplays.asset import Asset from flask import jsonify from src.supply.common import sats_to_fixed, peerplays, ASSET_IDS diff --git a/src/supply/supply_details.py b/src/supply/supply_details.py index 8bec4c7..8893d06 100644 --- a/src/supply/supply_details.py +++ b/src/supply/supply_details.py @@ -1,9 +1,15 @@ +""" +This module is used to get the supply details of the asset. +""" from peerplays.asset import Asset from peerplays import PeerPlays from src.supply.common import get_supplies def get_supply_details(asset_id="1.3.0"): + """ + returns the supply details of the asset + """ peerplays = PeerPlays("wss://ca.peerplays.info/api") A = Asset(asset_id, blockchain_instance=peerplays) supplies = get_supplies(A) diff --git a/src/supply/total_supply.py b/src/supply/total_supply.py index aef3c8b..8f1c5d4 100644 --- a/src/supply/total_supply.py +++ b/src/supply/total_supply.py @@ -1,8 +1,15 @@ -from .common import get_supplies, peerplays, ASSET_IDS +""" +This module contains the total supply endpoint. +""" from peerplays.asset import Asset from flask import Response +from src.supply.common import get_supplies, peerplays, ASSET_IDS + def total_supply(coin_name): + """ + This endpoint returns the total supply for the given coin name. + """ asset_id = ASSET_IDS.get(coin_name) if asset_id is None: return Response("Invalid coin name", status=400)