diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml new file mode 100644 index 00000000..0a6f9738 --- /dev/null +++ b/.github/workflows/black.yaml @@ -0,0 +1,45 @@ +name: Black Formatter + +on: + pull_request: + branches: + - master + +jobs: + format: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} # Check out the PR branch + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install Black + run: pip install black + + - name: Run Black + run: black . + + - name: Check for changes + id: changes + run: | + if [[ -n $(git status --porcelain) ]]; then + echo "changes_detected=true" >> $GITHUB_ENV + else + echo "changes_detected=false" >> $GITHUB_ENV + fi + + - name: Commit changes + if: env.changes_detected == 'true' + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "chore: \`black .\`" + git push diff --git a/eth_portfolio/_utils.py b/eth_portfolio/_utils.py index f034c554..ccec74b1 100644 --- a/eth_portfolio/_utils.py +++ b/eth_portfolio/_utils.py @@ -258,8 +258,7 @@ async def _get_and_yield( @property @abstractmethod - def _start_block(self) -> int: - ... + def _start_block(self) -> int: ... _LT = TypeVar("_LT") diff --git a/eth_portfolio/_ydb/token_transfers.py b/eth_portfolio/_ydb/token_transfers.py index 1edf6d92..5f3ac246 100644 --- a/eth_portfolio/_ydb/token_transfers.py +++ b/eth_portfolio/_ydb/token_transfers.py @@ -44,8 +44,7 @@ def __repr__(self) -> str: return f"<{self.__class__.__module__}.{self.__class__.__name__} address={self.address}>" @abc.abstractproperty - def _topics(self) -> List: - ... + def _topics(self) -> List: ... @a_sync.ASyncIterator.wrap async def yield_thru_block(self, block) -> AsyncIterator["asyncio.Task[TokenTransfer]"]: diff --git a/eth_portfolio/portfolio.py b/eth_portfolio/portfolio.py index 2a72e4a7..709e23dc 100644 --- a/eth_portfolio/portfolio.py +++ b/eth_portfolio/portfolio.py @@ -174,7 +174,6 @@ def __init__( load_prices: bool = True, asynchronous: bool = False, ) -> None: - """ Initialize a Portfolio instance. diff --git a/eth_portfolio/protocols/_base.py b/eth_portfolio/protocols/_base.py index 3f22dd37..25e15b30 100644 --- a/eth_portfolio/protocols/_base.py +++ b/eth_portfolio/protocols/_base.py @@ -20,8 +20,7 @@ async def balances(self, address: Address, block: Optional[Block] = None) -> Tok return await self._balances(address, block=block) @abc.abstractmethod - async def _balances(self, address: Address, block: Optional[Block] = None) -> TokenBalances: - ... + async def _balances(self, address: Address, block: Optional[Block] = None) -> TokenBalances: ... class ProtocolWithStakingABC(ProtocolABC, metaclass=abc.ABCMeta): diff --git a/eth_portfolio/protocols/lending/_base.py b/eth_portfolio/protocols/lending/_base.py index 2e4a8fa2..58a7e007 100644 --- a/eth_portfolio/protocols/lending/_base.py +++ b/eth_portfolio/protocols/lending/_base.py @@ -22,8 +22,7 @@ async def debt(self, address: Address, block: Optional[Block] = None) -> TokenBa return await self._debt(address, block) # type: ignore @abc.abstractmethod - async def _debt(self, address: Address, block: Optional[Block] = None) -> TokenBalances: - ... + async def _debt(self, address: Address, block: Optional[Block] = None) -> TokenBalances: ... class LendingProtocolWithLockedCollateral(LendingProtocol, ProtocolABC): diff --git a/tests/_test_completeness.py b/tests/_test_completeness.py index e602afdd..2de3ae89 100644 --- a/tests/_test_completeness.py +++ b/tests/_test_completeness.py @@ -1,6 +1,7 @@ """ This is temporarily disabled, might be removed """ + from typing import Callable import eth_portfolio.protocols.lending diff --git a/tests/protocols/test_external.py b/tests/protocols/test_external.py index 0f349755..c39aa68c 100644 --- a/tests/protocols/test_external.py +++ b/tests/protocols/test_external.py @@ -10,12 +10,10 @@ SOME_OTHER_TOKEN = "0x0000000000000000000000000000000000000003" -class MockProtocolA(AsyncMock): - ... +class MockProtocolA(AsyncMock): ... -class MockProtocolB(AsyncMock): - ... +class MockProtocolB(AsyncMock): ... @patch("a_sync.map") diff --git a/tests/test_typing.py b/tests/test_typing.py index ffd7676a..fa6709b4 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -21,6 +21,7 @@ WALLET_2 = "0x0000000000000000000000000000000000000006" WALLET_3 = "0x0000000000000000000000000000000000000007" + # Test Balance class def test_balance_addition(): b1 = Balance(balance=Decimal("10"), usd_value=Decimal("100"))