Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoflake and isort to CI #12

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ jobs:
- uses: ./.github/actions/python_prepare
- name: Check with black
run: poetry run black --check .

autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with autoflake
run: |
poetry run autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
git diff --exit-code --quiet || exit 1
Comment on lines +54 to +62
Copy link

@coderabbitai coderabbitai bot Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autoflake job is correctly configured to remove unused imports and variables. However, consider adding a step to install autoflake if it's not included in the .github/actions/python_prepare action, as this could lead to a failure in environments where autoflake is not pre-installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just git diff --exit-code ? 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kongzii, you're right that git diff --exit-code alone would suffice to check for differences, as it exits with 1 if there are differences and 0 otherwise. The --quiet option is used to suppress the output, making the CI logs cleaner by not showing the diff output. The || exit 1 part, while seemingly redundant because git diff --exit-code already exits with 1 on differences, is often included for explicitness in CI scripts. It ensures that the script exits with a failure status if differences are found, which is a common practice to make the failure conditions in CI pipelines more explicit. However, in this specific case, it's indeed redundant and could be omitted for simplicity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the answer coderrabbit 🤣

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!


isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with isort
run: |
poetry run isort --profile black .
git diff --exit-code --quiet || exit 1
7 changes: 4 additions & 3 deletions examples/cloud_deployment/gcp/agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flask.wrappers import Request
import functions_framework
import random

from prediction_market_agent_tooling.markets.data_models import AgentMarket
import functions_framework
from flask.wrappers import Request

from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.markets.markets import MarketType


Expand Down
2 changes: 1 addition & 1 deletion examples/cloud_deployment/gcp/deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.deploy.gcp.deploy import (
deploy_to_gcp,
remove_deployed_gcp_function,
Expand All @@ -8,7 +9,6 @@
)
from prediction_market_agent_tooling.deploy.gcp.utils import gcp_function_is_active
from prediction_market_agent_tooling.markets.markets import MarketType
from prediction_market_agent_tooling.config import APIKeys

if __name__ == "__main__":
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down
1 change: 1 addition & 0 deletions examples/monitor/monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import streamlit as st

from prediction_market_agent_tooling.markets.manifold import get_authenticated_user
Expand Down
248 changes: 144 additions & 104 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion prediction_market_agent_tooling/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import typing as t

from pydantic_settings import BaseSettings, SettingsConfigDict

from prediction_market_agent_tooling.gtypes import ChecksumAddress, PrivateKey
from prediction_market_agent_tooling.tools.utils import check_not_none
from prediction_market_agent_tooling.tools.web3_utils import verify_address
from prediction_market_agent_tooling.gtypes import ChecksumAddress, PrivateKey


class APIKeys(BaseSettings):
Expand Down
15 changes: 8 additions & 7 deletions prediction_market_agent_tooling/deploy/agent.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import time
from decimal import Decimal
from enum import Enum

from pydantic import BaseModel
from decimal import Decimal
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent_tooling.markets.data_models import (
AgentMarket,
BetAmount,
Currency,
)
from prediction_market_agent_tooling.markets.markets import (
MarketType,
get_binary_markets,
place_bet,
)
from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.data_models import (
BetAmount,
Currency,
)


class DeploymentType(str, Enum):
Expand Down
8 changes: 5 additions & 3 deletions prediction_market_agent_tooling/deploy/gcp/deploy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import requests
import shutil
import subprocess
import tempfile
import typing as t

import requests
from cron_validator import CronValidator

from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.tools.utils import export_requirements_from_toml
from prediction_market_agent_tooling.deploy.gcp.utils import (
gcloud_create_topic_cmd,
gcloud_delete_function_cmd,
Expand All @@ -16,7 +18,7 @@
get_gcloud_id_token,
)
from prediction_market_agent_tooling.markets.markets import MarketType
from cron_validator import CronValidator
from prediction_market_agent_tooling.tools.utils import export_requirements_from_toml


def deploy_to_gcp(
Expand Down
1 change: 1 addition & 0 deletions prediction_market_agent_tooling/deploy/gcp/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import sys

from google.cloud.functions_v2.services.function_service.client import (
FunctionServiceClient,
)
Expand Down
11 changes: 6 additions & 5 deletions prediction_market_agent_tooling/gtypes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from decimal import Decimal
from typing import NewType, Union
from web3.types import Wei
from eth_typing.evm import (

from eth_typing.evm import ( # noqa: F401 # Import for the sake of easy importing with others from here.
Address,
HexStr,
HexAddress,
ChecksumAddress,
) # noqa: F401 # Import for the sake of easy importing with others from here.
HexAddress,
HexStr,
)
from web3.types import Wei

Wad = Wei # Wei tends to be referred to as `wad` variable in contracts.
USD = NewType(
Expand Down
9 changes: 5 additions & 4 deletions prediction_market_agent_tooling/markets/data_models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import typing as t
from datetime import datetime
from decimal import Decimal
from enum import Enum
import typing as t

from pydantic import BaseModel
from web3 import Web3

from prediction_market_agent_tooling.gtypes import (
USD,
HexAddress,
ChecksumAddress,
Probability,
HexAddress,
Mana,
OmenOutcomeToken,
xDai,
Probability,
Wei,
xDai,
)


Expand Down
12 changes: 7 additions & 5 deletions prediction_market_agent_tooling/markets/manifold.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import typing as t
from datetime import datetime

import requests
import typing as t
from prediction_market_agent_tooling.gtypes import Mana

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.gtypes import Mana
from prediction_market_agent_tooling.markets.data_models import (
ProfitAmount,
ResolvedBet,
BetAmount,
Currency,
ManifoldBet,
ManifoldContractMetric,
ManifoldMarket,
ManifoldUser,
ManifoldContractMetric,
ProfitAmount,
ResolvedBet,
)

"""
Expand Down
14 changes: 6 additions & 8 deletions prediction_market_agent_tooling/markets/markets.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from decimal import Decimal
import typing as t
from decimal import Decimal
from enum import Enum
from prediction_market_agent_tooling.markets.data_models import (
BetAmount,
Currency,
)
from prediction_market_agent_tooling.markets import manifold, omen

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.gtypes import Mana, xDai
from prediction_market_agent_tooling.markets import manifold, omen
from prediction_market_agent_tooling.markets.data_models import BetAmount, Currency
from prediction_market_agent_tooling.tools.utils import (
should_not_happen,
check_not_none,
should_not_happen,
)
from prediction_market_agent_tooling.config import APIKeys


class MarketType(str, Enum):
Expand Down
38 changes: 20 additions & 18 deletions prediction_market_agent_tooling/markets/omen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@
"""

import os
import requests
from typing import Optional

import requests
from web3 import Web3
from web3.types import TxReceipt, TxParams
from prediction_market_agent_tooling.markets.data_models import OmenMarket
from prediction_market_agent_tooling.tools.web3_utils import (
call_function_on_contract,
call_function_on_contract_tx,
WXDAI_ABI,
xdai_to_wei,
remove_fraction,
add_fraction,
check_tx_receipt,
ONE_NONCE,
Nonce,
)
from prediction_market_agent_tooling.tools.gnosis_rpc import GNOSIS_RPC_URL
from web3.types import TxParams, TxReceipt

from prediction_market_agent_tooling.gtypes import (
ABI,
ChecksumAddress,
HexAddress,
OmenOutcomeToken,
PrivateKey,
xDai,
Wei,
ChecksumAddress,
OmenOutcomeToken,
xDai,
)
from prediction_market_agent_tooling.markets.data_models import OmenMarket
from prediction_market_agent_tooling.tools.gnosis_rpc import GNOSIS_RPC_URL
from prediction_market_agent_tooling.tools.web3_utils import (
ONE_NONCE,
WXDAI_ABI,
Nonce,
add_fraction,
call_function_on_contract,
call_function_on_contract_tx,
check_tx_receipt,
remove_fraction,
xdai_to_wei,
)

OMEN_TRUE_OUTCOME = "Yes"
Expand Down
7 changes: 4 additions & 3 deletions prediction_market_agent_tooling/monitor/monitor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import altair as alt
import typing as t
from datetime import datetime
from pydantic import BaseModel

import altair as alt
import pandas as pd
import streamlit as st
import typing as t
from pydantic import BaseModel

from prediction_market_agent_tooling.markets.data_models import ResolvedBet

Expand Down
2 changes: 1 addition & 1 deletion prediction_market_agent_tooling/tools/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import subprocess
from typing import NoReturn, Type, TypeVar, Optional
from typing import NoReturn, Optional, Type, TypeVar

T = TypeVar("T")

Expand Down
14 changes: 8 additions & 6 deletions prediction_market_agent_tooling/tools/web3_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
from typing import Optional, Any, TypeVar
from web3 import Web3
from decimal import Decimal
from web3.types import Wei, TxReceipt, TxParams, Nonce
from typing import Any, Optional, TypeVar

from web3 import Web3
from web3.types import Nonce, TxParams, TxReceipt, Wei

from prediction_market_agent_tooling.gtypes import (
ABI,
xDai,
PrivateKey,
ChecksumAddress,
xdai_type,
HexAddress,
HexStr,
PrivateKey,
xDai,
xdai_type,
)

ONE_NONCE = Nonce(1)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ web3 = "^6.15.1"
eth-typing = "^4.0.0"
pydantic-settings = "^2.1.0"
numpy = "^1.26.4"
autoflake = "^2.2.1"
isort = "^5.13.2"
streamlit = "^1.31.0"

[tool.poetry.group.dev.dependencies]
Expand Down
11 changes: 4 additions & 7 deletions scripts/bet_omen.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import typer
from prediction_market_agent_tooling.tools.web3_utils import verify_address

from prediction_market_agent_tooling.gtypes import PrivateKey, xdai_type
from prediction_market_agent_tooling.markets.omen import (
omen_buy_outcome_tx,
get_market,
omen_buy_outcome_tx,
omen_sell_outcome_tx,
)
from prediction_market_agent_tooling.gtypes import (
PrivateKey,
xdai_type,
)
from eth_typing import HexStr
from prediction_market_agent_tooling.tools.web3_utils import verify_address

app = typer.Typer()

Expand Down
5 changes: 1 addition & 4 deletions tests/deploy/test_deploy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import random

from prediction_market_agent_tooling.deploy.agent import DeployableAgent, DeploymentType
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.deploy.agent import (
DeployableAgent,
DeploymentType,
)
from prediction_market_agent_tooling.markets.markets import MarketType


Expand Down
5 changes: 3 additions & 2 deletions tests/markets/test_manifold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from tests.utils import RUN_PAID_TESTS
from prediction_market_agent_tooling.markets import manifold

from prediction_market_agent_tooling.gtypes import mana_type
from prediction_market_agent_tooling.markets import manifold
from tests.utils import RUN_PAID_TESTS


@pytest.mark.skipif(not RUN_PAID_TESTS, reason="This test costs money to run.")
Expand Down
6 changes: 4 additions & 2 deletions tests/markets/test_omen.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import time

import pytest
from tests.utils import RUN_PAID_TESTS

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.markets import omen
from prediction_market_agent_tooling.gtypes import xdai_type
from prediction_market_agent_tooling.markets.markets import omen
from tests.utils import RUN_PAID_TESTS


def test_omen_pick_binary_market() -> None:
Expand Down
Loading