From e68b3b539dcb592566d4e26840b9944fb4916fb6 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 2 Jun 2024 16:14:46 +0200 Subject: [PATCH] Ruff --- fin_depo/__init__.py | 3 +-- fin_depo/data.py | 11 +++++++---- fin_depo/defi_kraken.py | 18 ++++++++++-------- fin_depo/defi_kucoin.py | 32 ++++++++++++++++++-------------- setup.py | 3 +++ test/test_data.py | 4 ---- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/fin_depo/__init__.py b/fin_depo/__init__.py index 11ea7cb..e11e5a0 100644 --- a/fin_depo/__init__.py +++ b/fin_depo/__init__.py @@ -1,4 +1,3 @@ __all__ = ['defi_kraken', 'defi_kucoin'] -from . import defi_kraken -from . import defi_kucoin +from . import defi_kraken, defi_kucoin diff --git a/fin_depo/data.py b/fin_depo/data.py index b15126f..002412b 100644 --- a/fin_depo/data.py +++ b/fin_depo/data.py @@ -1,10 +1,11 @@ +import dataclasses +import datetime +from collections.abc import Mapping +from decimal import Decimal import enforce_typing -import dataclasses -from decimal import Decimal -from collections.abc import Mapping from fin_defs import Asset -import datetime + @enforce_typing.enforce_types @dataclasses.dataclass @@ -12,11 +13,13 @@ class Depo: name: str updated_time: datetime.datetime + @enforce_typing.enforce_types @dataclasses.dataclass class DepoSingle(Depo): assets: Mapping[Asset, Decimal] + @enforce_typing.enforce_types @dataclasses.dataclass class DepoGroup(Depo): diff --git a/fin_depo/defi_kraken.py b/fin_depo/defi_kraken.py index 8d0b432..b33f684 100644 --- a/fin_depo/defi_kraken.py +++ b/fin_depo/defi_kraken.py @@ -1,14 +1,16 @@ -from .data import Depo, DepoSingle -from decimal import Decimal -import fin_defs import datetime -import krakenex import logging +from decimal import Decimal + +import fin_defs +import krakenex + +from .data import Depo, DepoSingle logger = logging.getLogger(__name__) -class KrakenDepoFetcher: +class KrakenDepoFetcher: def __init__(self, kraken_key: str, kraken_secret: str): self.client = krakenex.API( kraken_key, @@ -29,7 +31,7 @@ class KrakenDepoFetcher: del account, balance_str, asset, balance return DepoSingle( - name = 'Kraken', - assets = assets, - updated_time = now, + name='Kraken', + assets=assets, + updated_time=now, ) diff --git a/fin_depo/defi_kucoin.py b/fin_depo/defi_kucoin.py index a728d06..f6f36cd 100644 --- a/fin_depo/defi_kucoin.py +++ b/fin_depo/defi_kucoin.py @@ -1,20 +1,16 @@ -from .data import DepoSingle, DepoGroup -import dataclasses import datetime -import fin_defs import logging -from collections.abc import Iterator, Mapping from decimal import Decimal +import fin_defs import kucoin.client -from frozendict import frozendict -from personal_data.data import DeduplicateMode, Scraper +from .data import DepoGroup, DepoSingle logger = logging.getLogger(__name__) -class KucoinDepoFetcher: +class KucoinDepoFetcher: def __init__(self, kucoin_key: str, kucoin_secret: str, kucoin_pass: str): self.client = kucoin.client.Client( kucoin_key, @@ -27,11 +23,19 @@ class KucoinDepoFetcher: assets_by_account_type: dict[str, dict[fin_defs.Asset, Decimal]] = {} for account_data in self.client.get_accounts(): asset = fin_defs.WELL_KNOWN_SYMBOLS[account_data['currency']] - balance = Decimal( account_data['balance']) - assets_for_account_type = assets_by_account_type.get(account_data['type'], {}) - assets_for_account_type[asset] = assets_for_account_type.get(asset, Decimal(0)) +balance + balance = Decimal(account_data['balance']) + assets_for_account_type = assets_by_account_type.get( + account_data['type'], {}, + ) + assets_for_account_type[asset] = ( + assets_for_account_type.get(asset, Decimal(0)) + balance + ) del account_data, asset, balance - return DepoGroup("Kucoin", now, [ - DepoSingle("Kucoin " + account_type, now, assets) for account_type, - assets in assets_by_account_type.items() - ]) + return DepoGroup( + 'Kucoin', + now, + [ + DepoSingle('Kucoin ' + account_type, now, assets) + for account_type, assets in assets_by_account_type.items() + ], + ) diff --git a/setup.py b/setup.py index c71143a..1350675 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ PACKAGE_NAME = 'fin_depo' with open('README.md') as f: readme = f.read() + def parse_version_file(text: str) -> str: match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text) if match is None: @@ -22,9 +23,11 @@ def parse_version_file(text: str) -> str: raise Exception(msg) return match.group(2) + with open(PACKAGE_NAME + '/_version.py') as f: version = parse_version_file(f.read()) + def parse_requirements(text: str) -> list[str]: return text.strip().split('\n') diff --git a/test/test_data.py b/test/test_data.py index cee1467..a3e981b 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -1,6 +1,2 @@ -import pytest - -import fin_depo - def test_nothing(): pass