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

Linters #33

Merged
merged 5 commits into from
Mar 8, 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
50 changes: 50 additions & 0 deletions .github/workflows/common_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: main_workflow
on:
push:
branches:
- develop
- main
pull_request:
jobs:
linter_checks:
continue-on-error: False
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10.9"]
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-go@v3
with:
go-version: "1.17.7"
- name: Install dependencies
run: |
sudo apt-get update --fix-missing
sudo apt-get autoremove
sudo apt-get autoclean
pip install tomte[tox]==0.2.15
pip install --user --upgrade setuptools
sudo npm install -g markdown-spellcheck
- name: Security checks
run: |
tox -p -e bandit -e safety
- name: Code style check
run: |
tox -p -e black-check -e isort-check
- name: Flake7
run: |
tox -e flake8
- name: Pylint
run: tox -e pylint
- name: Static type check
run: tox -e mypy
# - name: Check spelling
# run: tox -e spell-check
# - name: License compatibility check
# run: tox -e liccheck
# tox -p -e vulture -e darglint
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ frontend/build
.DS_STORE

# python
backend/__pycache__/
backend/scripts/__pycache__/
.tox/
.operate/
data/
__pycache__/
backend/tmp/
data/
backend/temp/
backend/tmp/

tmp/
temp/
Expand Down
60 changes: 60 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[MASTER]
ignore-patterns=contract.py
ignore=operate/data/contracts/

[MESSAGES CONTROL]
disable=C0103,R0801,C0301,C0201,C0204,C0209,W1203,C0302,R1735,R1729,W0511,E0611,R0903

# See here for more options: https://www.codeac.io/documentation/pylint-configuration.html
R1735: use-dict-literal
R1729: use-a-generator
C0103: invalid-name
C0201: consider-iterating-dictionary
W1203: logging-fstring-interpolation
C0204: bad-mcs-classmethod-argument
C0209: consider-using-f-string
C0301: http://pylint-messages.wikidot.com/messages:c0301 > Line too long
C0302: http://pylint-messages.wikidot.com/messages:c0302 > Too many lines in module
R0801: similar lines
E0611: no-name-in-module
R0903: Too few public methods

[IMPORTS]
ignored-modules=os,io

[DESIGN]
# min-public-methods=1
max-public-methods=58
# max-returns=10
# max-bool-expr=7
max-args=6
# max-locals=31
# max-statements=80
max-parents=10
max-branches=36
max-attributes=8

[REFACTORING]
# max-nested-blocks=6

[SPELLING]
# uncomment to enable
# spelling-dict=en_US

# List of comma separated words that should not be checked.
spelling-ignore-words=nocover,pragma,params,noqa,kwargs,str,async,json,boolean,config,pytest,args,url,tx,jsonschema,traceback,api,nosec

[SIMILARITIES]

# Minimum lines number of a similarity.
min-similarity-lines=10

# Ignore comments when computing similarities.
ignore-comments=yes

# Ignore docstrings when computing similarities.
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=no

31 changes: 5 additions & 26 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""Operate app CLI module."""

import os
import shutil
import typing as t
from pathlib import Path

from aea_ledger_ethereum.ethereum import EthereumCrypto
Expand All @@ -37,6 +37,7 @@
from operate.keys import Keys
from operate.services.manage import Services


DEFAULT_HARDHAT_KEY = (
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
).encode()
Expand All @@ -45,7 +46,7 @@
class App(Resource):
"""App resource."""

def __init__(self, home: Path) -> None:
def __init__(self, home: t.Optional[Path] = None) -> None:
"""Initialize object."""
super().__init__()
self._path = (home or (Path.home() / OPERATE)).resolve()
Expand Down Expand Up @@ -76,7 +77,7 @@ def make(self) -> None:
)

@property
def json(self) -> None:
def json(self) -> dict:
"""Json representation of the app."""
return {
"name": "Operate HTTP server",
Expand All @@ -98,7 +99,7 @@ def _daemon(
host: Annotated[str, params.String(help="HTTP server host string")] = "localhost",
port: Annotated[int, params.Integer(help="HTTP server port")] = 8000,
home: Annotated[
Path, params.Directory(long_flag="--home", help="Home directory")
t.Optional[Path], params.Directory(long_flag="--home", help="Home directory")
] = None,
) -> None:
"""Launch operate daemon."""
Expand All @@ -125,28 +126,6 @@ def _daemon(
)


@_operate.command(name="prune")
def _prune(
home: Annotated[
Path, params.Directory(long_flag="--home", help="Home directory")
] = None,
) -> None:
"""Delete unused/cached data."""
app = App(home=home)
for service in app.services.json:
if service["active"]:
continue
try:
shutil.rmtree(app.services.path / service["hash"])
print("Removed service " + service["hash"])
except PermissionError:
print(
"Error removing "
+ service["hash"]
+ " please try with admin previledges"
)


def main() -> None:
"""CLI entry point."""
run(cli=_operate)
Expand Down
1 change: 1 addition & 0 deletions operate/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

from pathlib import Path


DATA_DIR = Path(__file__).parent
2 changes: 1 addition & 1 deletion operate/data/contracts/uniswap_v2_erc20/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from aea.contracts.base import Contract
from aea_ledger_ethereum import EthereumApi


PUBLIC_ID = PublicId.from_str("valory/uniswap_v2_erc20:0.1.0")

_logger = logging.getLogger(
Expand Down Expand Up @@ -197,7 +198,6 @@ def get_transaction_transfer_logs( # type: ignore # pylint: disable=too-many-a
transfer_logs: List = []

if transfer_logs_data:

transfer_logs = cast(
List,
transfer_logs_data["logs"],
Expand Down
10 changes: 6 additions & 4 deletions operate/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

from operate.http.exceptions import NotAllowed, ResourceException


# pylint: disable=no-self-use

GenericResource = t.TypeVar("GenericResource")
PostPayload = t.TypeVar("PostPayload")
PostResponse = t.TypeVar("PostResponse")
Expand All @@ -52,7 +55,7 @@ class Resource(
):
"""Web<->Local resource object."""

_handlers: t.Dict[str, t.Callable[[t.Dict], t.Dict]]
_handlers: t.Dict[str, t.Callable]

def __init__(self) -> None:
"""Initialize object."""
Expand Down Expand Up @@ -119,7 +122,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> t.Any:
return

try:
handler = self._handlers.get(request.method)
handler = self._handlers[request.method]
try:
data = await request.json()
except json.decoder.JSONDecodeError:
Expand All @@ -134,8 +137,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> t.Any:
content={"error": e.args[0]},
status_code=e.code,
)
except Exception as e:
raise
except Exception as e: # pylint: disable=broad-except
response = JSONResponse(
content={"error": str(e)},
status_code=500,
Expand Down
1 change: 0 additions & 1 deletion operate/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""Keys manager."""
import json
import os
import typing as t
from pathlib import Path

from aea_ledger_ethereum.ethereum import EthereumCrypto
Expand Down
9 changes: 7 additions & 2 deletions operate/ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from operate.ledger.solana import Solana
from operate.types import ChainType, LedgerType


ETHEREUM_RPC = "https://ethereum.publicnode.com"
GNOSIS_RPC = "https://rpc.gnosischain.com"
GOERLI_RPC = "https://ethereum-goerli.publicnode.com"
Expand Down Expand Up @@ -60,16 +61,20 @@


def get_default_rpc(chain: ChainType) -> str:
"""Get default RPC chain type."""
return DEFAULT_RPCS.get(chain, ETHEREUM_RPC)


def get_ledger_helper_by_chain(rpc: str, chain: ChainType) -> LedgerHelper:
"""Get ledger helper by chain type."""
return CHAIN_HELPERS.get(chain, Ethereum)(rpc=rpc)


def get_ledger_helper_by_ledger(rpc: str, ledger: LedgerHelper) -> LedgerHelper:
return LEDGER_HELPERS.get(ledger, Ethereum)(rpc=rpc)
"""Get ledger helper by ledger type."""
return LEDGER_HELPERS.get(ledger, Ethereum)(rpc=rpc) # type: ignore


def get_currency_denom(chain: ChainType):
def get_currency_denom(chain: ChainType) -> str:
"""Get currency denom by chain type."""
return CURRENCY_DENOMS.get(chain, "Wei")
2 changes: 1 addition & 1 deletion operate/ledger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from abc import ABC, abstractmethod


class LedgerHelper(ABC):
class LedgerHelper(ABC): # pylint: disable=too-few-public-methods
"""Base ledger helper."""

api: t.Any
Expand Down
1 change: 1 addition & 0 deletions operate/ledger/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Ethereum(LedgerHelper):
api: EthereumApi

def __init__(self, rpc: str) -> None:
"""Initialize object."""
super().__init__(rpc)
self.api = EthereumApi(address=self.rpc)

Expand Down
1 change: 1 addition & 0 deletions operate/ledger/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from operate.types import ChainType, ContractAddresses


CONTRACTS = {
ChainType.GNOSIS: ContractAddresses(
{
Expand Down
3 changes: 0 additions & 3 deletions operate/ledger/solana.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
class Solana(LedgerHelper):
"""Solana ledger helper."""

def __init__(self, rpc: str) -> None:
super().__init__(rpc)

def create_key(self) -> t.Dict:
"""Create key."""
return {
Expand Down
15 changes: 6 additions & 9 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
from operate.types import (
ChainData,
ConfigurationTemplate,
ServicesType,
ServiceTemplate,
ServiceType,
ServicesType,
)


OPERATE = ".operate"
CONFIG = "config.json"
SERVICES = "services"
Expand Down Expand Up @@ -83,10 +84,6 @@ def build_dirs(build_dir: Path) -> None:
continue


class GetServices(ServicesType):
"""Get payload."""


class PostServices(ServiceTemplate):
"""Create payload."""

Expand All @@ -112,7 +109,7 @@ class DeleteServicesResponse(TypedDict):

class Services(
Resource[
GetServices,
ServicesType,
PostServices,
ServiceType,
PutServices,
Expand Down Expand Up @@ -142,7 +139,7 @@ async def access(
await resource(scope=scope, receive=receive, send=send)

@property
def json(self) -> GetServices:
def json(self) -> ServicesType:
"""Returns the list of available services."""
data = []
for path in self.path.iterdir():
Expand Down Expand Up @@ -279,7 +276,7 @@ def _create(

return service

def create(self, data: PostServices) -> PostServices:
def create(self, data: PostServices) -> ServiceType:
"""Create a service."""
service = self._create(
phash=data["hash"],
Expand Down Expand Up @@ -326,7 +323,7 @@ def update(self, data: PutServices) -> ServiceType:

# Swap owners on the old safe
owner, *_ = old.chain_data["instances"]
owner_key = self.keys.get(owner).get("private_key")
owner_key = str(self.keys.get(owner).get("private_key"))
ocm.swap(
service_id=old.chain_data["token"],
multisig=old.chain_data["multisig"],
Expand Down
Loading
Loading