Skip to content

Commit d5bdc89

Browse files
committed
chore: linters
1 parent 14c9121 commit d5bdc89

18 files changed

+88
-108
lines changed

operate/cli.py

+5-26
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""Operate app CLI module."""
2121

2222
import os
23-
import shutil
23+
import typing as t
2424
from pathlib import Path
2525

2626
from aea_ledger_ethereum.ethereum import EthereumCrypto
@@ -37,6 +37,7 @@
3737
from operate.keys import Keys
3838
from operate.services.manage import Services
3939

40+
4041
DEFAULT_HARDHAT_KEY = (
4142
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
4243
).encode()
@@ -45,7 +46,7 @@
4546
class App(Resource):
4647
"""App resource."""
4748

48-
def __init__(self, home: Path) -> None:
49+
def __init__(self, home: t.Optional[Path] = None) -> None:
4950
"""Initialize object."""
5051
super().__init__()
5152
self._path = (home or (Path.home() / OPERATE)).resolve()
@@ -76,7 +77,7 @@ def make(self) -> None:
7677
)
7778

7879
@property
79-
def json(self) -> None:
80+
def json(self) -> dict:
8081
"""Json representation of the app."""
8182
return {
8283
"name": "Operate HTTP server",
@@ -98,7 +99,7 @@ def _daemon(
9899
host: Annotated[str, params.String(help="HTTP server host string")] = "localhost",
99100
port: Annotated[int, params.Integer(help="HTTP server port")] = 8000,
100101
home: Annotated[
101-
Path, params.Directory(long_flag="--home", help="Home directory")
102+
t.Optional[Path], params.Directory(long_flag="--home", help="Home directory")
102103
] = None,
103104
) -> None:
104105
"""Launch operate daemon."""
@@ -125,28 +126,6 @@ def _daemon(
125126
)
126127

127128

128-
@_operate.command(name="prune")
129-
def _prune(
130-
home: Annotated[
131-
Path, params.Directory(long_flag="--home", help="Home directory")
132-
] = None,
133-
) -> None:
134-
"""Delete unused/cached data."""
135-
app = App(home=home)
136-
for service in app.services.json:
137-
if service["active"]:
138-
continue
139-
try:
140-
shutil.rmtree(app.services.path / service["hash"])
141-
print("Removed service " + service["hash"])
142-
except PermissionError:
143-
print(
144-
"Error removing "
145-
+ service["hash"]
146-
+ " please try with admin previledges"
147-
)
148-
149-
150129
def main() -> None:
151130
"""CLI entry point."""
152131
run(cli=_operate)

operate/data/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121

2222
from pathlib import Path
2323

24+
2425
DATA_DIR = Path(__file__).parent

operate/data/contracts/uniswap_v2_erc20/contract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from aea.contracts.base import Contract
2727
from aea_ledger_ethereum import EthereumApi
2828

29+
2930
PUBLIC_ID = PublicId.from_str("valory/uniswap_v2_erc20:0.1.0")
3031

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

199200
if transfer_logs_data:
200-
201201
transfer_logs = cast(
202202
List,
203203
transfer_logs_data["logs"],

operate/http/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
from operate.http.exceptions import NotAllowed, ResourceException
3131

32+
33+
# pylint: disable=no-self-use
34+
3235
GenericResource = t.TypeVar("GenericResource")
3336
PostPayload = t.TypeVar("PostPayload")
3437
PostResponse = t.TypeVar("PostResponse")
@@ -52,7 +55,7 @@ class Resource(
5255
):
5356
"""Web<->Local resource object."""
5457

55-
_handlers: t.Dict[str, t.Callable[[t.Dict], t.Dict]]
58+
_handlers: t.Dict[str, t.Callable]
5659

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

121124
try:
122-
handler = self._handlers.get(request.method)
125+
handler = self._handlers[request.method]
123126
try:
124127
data = await request.json()
125128
except json.decoder.JSONDecodeError:
@@ -134,8 +137,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> t.Any:
134137
content={"error": e.args[0]},
135138
status_code=e.code,
136139
)
137-
except Exception as e:
138-
raise
140+
except Exception as e: # pylint: disable=broad-except
139141
response = JSONResponse(
140142
content={"error": str(e)},
141143
status_code=500,

operate/keys.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"""Keys manager."""
2121
import json
2222
import os
23-
import typing as t
2423
from pathlib import Path
2524

2625
from aea_ledger_ethereum.ethereum import EthereumCrypto

operate/ledger/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from operate.ledger.solana import Solana
2727
from operate.types import ChainType, LedgerType
2828

29+
2930
ETHEREUM_RPC = "https://ethereum.publicnode.com"
3031
GNOSIS_RPC = "https://rpc.gnosischain.com"
3132
GOERLI_RPC = "https://ethereum-goerli.publicnode.com"
@@ -60,16 +61,20 @@
6061

6162

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

6567

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

6972

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

7377

74-
def get_currency_denom(chain: ChainType):
78+
def get_currency_denom(chain: ChainType) -> str:
79+
"""Get currency denom by chain type."""
7580
return CURRENCY_DENOMS.get(chain, "Wei")

operate/ledger/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from abc import ABC, abstractmethod
2424

2525

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

2929
api: t.Any

operate/ledger/ethereum.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Ethereum(LedgerHelper):
3333
api: EthereumApi
3434

3535
def __init__(self, rpc: str) -> None:
36+
"""Initialize object."""
3637
super().__init__(rpc)
3738
self.api = EthereumApi(address=self.rpc)
3839

operate/ledger/profiles.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from operate.types import ChainType, ContractAddresses
2323

24+
2425
CONTRACTS = {
2526
ChainType.GNOSIS: ContractAddresses(
2627
{

operate/ledger/solana.py

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
class Solana(LedgerHelper):
2929
"""Solana ledger helper."""
3030

31-
def __init__(self, rpc: str) -> None:
32-
super().__init__(rpc)
33-
3431
def create_key(self) -> t.Dict:
3532
"""Create key."""
3633
return {

operate/services/manage.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747
from operate.types import (
4848
ChainData,
4949
ConfigurationTemplate,
50-
ServicesType,
5150
ServiceTemplate,
5251
ServiceType,
52+
ServicesType,
5353
)
5454

55+
5556
OPERATE = ".operate"
5657
CONFIG = "config.json"
5758
SERVICES = "services"
@@ -83,10 +84,6 @@ def build_dirs(build_dir: Path) -> None:
8384
continue
8485

8586

86-
class GetServices(ServicesType):
87-
"""Get payload."""
88-
89-
9087
class PostServices(ServiceTemplate):
9188
"""Create payload."""
9289

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

113110
class Services(
114111
Resource[
115-
GetServices,
112+
ServicesType,
116113
PostServices,
117114
ServiceType,
118115
PutServices,
@@ -142,7 +139,7 @@ async def access(
142139
await resource(scope=scope, receive=receive, send=send)
143140

144141
@property
145-
def json(self) -> GetServices:
142+
def json(self) -> ServicesType:
146143
"""Returns the list of available services."""
147144
data = []
148145
for path in self.path.iterdir():
@@ -279,7 +276,7 @@ def _create(
279276

280277
return service
281278

282-
def create(self, data: PostServices) -> PostServices:
279+
def create(self, data: PostServices) -> ServiceType:
283280
"""Create a service."""
284281
service = self._create(
285282
phash=data["hash"],
@@ -326,7 +323,7 @@ def update(self, data: PutServices) -> ServiceType:
326323

327324
# Swap owners on the old safe
328325
owner, *_ = old.chain_data["instances"]
329-
owner_key = self.keys.get(owner).get("private_key")
326+
owner_key = str(self.keys.get(owner).get("private_key"))
330327
ocm.swap(
331328
service_id=old.chain_data["token"],
332329
multisig=old.chain_data["multisig"],

operate/services/protocol.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
from operate.data.contracts.service_staking_token.contract import (
4949
ServiceStakingTokenContract,
5050
)
51-
from operate.ledger.profiles import CONTRACTS
51+
from operate.types import ContractAddresses
52+
5253

5354
ZERO_ETH = 0
5455

@@ -80,7 +81,7 @@ class MultiSendOperation(Enum):
8081
DELEGATE_CALL = 1
8182

8283

83-
def hash_payload_to_hex(
84+
def hash_payload_to_hex( # pylint: disable=too-many-arguments,too-many-locals
8485
safe_tx_hash: str,
8586
ether_value: int,
8687
safe_tx_gas: int,
@@ -245,7 +246,9 @@ def stake(
245246
# since it has the same interface as ERC721 we might want to create
246247
# a ERC721 contract package
247248

248-
def _build_approval_tx(*args, **kargs) -> t.Dict:
249+
def _build_approval_tx( # pylint: disable=unused-argument
250+
*args: t.Any, **kargs: t.Any
251+
) -> t.Dict:
249252
return registry_contracts.erc20.get_approve_tx(
250253
ledger_api=self.ledger_api,
251254
contract_address=service_registry,
@@ -254,15 +257,17 @@ def _build_approval_tx(*args, **kargs) -> t.Dict:
254257
amount=service_id,
255258
)
256259

257-
setattr(tx_settler, "build", _build_approval_tx)
260+
setattr(tx_settler, "build", _build_approval_tx) # noqa: B010
258261
tx_settler.transact(
259262
method=lambda: {},
260263
contract="",
261264
kwargs={},
262265
dry_run=False,
263266
)
264267

265-
def _build_staking_tx(*args, **kargs) -> t.Dict:
268+
def _build_staking_tx( # pylint: disable=unused-argument
269+
*args: t.Any, **kargs: t.Any
270+
) -> t.Dict:
266271
return self.ledger_api.build_transaction(
267272
contract_instance=self.staking_ctr.get_instance(
268273
ledger_api=self.ledger_api,
@@ -276,7 +281,7 @@ def _build_staking_tx(*args, **kargs) -> t.Dict:
276281
raise_on_try=True,
277282
)
278283

279-
setattr(tx_settler, "build", _build_staking_tx)
284+
setattr(tx_settler, "build", _build_staking_tx) # noqa: B010
280285
tx_settler.transact(
281286
method=lambda: {},
282287
contract="",
@@ -328,7 +333,9 @@ def unstake(self, service_id: int, staking_contract: str) -> None:
328333
sleep=self.sleep,
329334
)
330335

331-
def _build_unstaking_tx(*args, **kargs) -> t.Dict:
336+
def _build_unstaking_tx( # pylint: disable=unused-argument
337+
*args: t.Any, **kargs: t.Any
338+
) -> t.Dict:
332339
return self.ledger_api.build_transaction(
333340
contract_instance=self.staking_ctr.get_instance(
334341
ledger_api=self.ledger_api,
@@ -342,7 +349,7 @@ def _build_unstaking_tx(*args, **kargs) -> t.Dict:
342349
raise_on_try=True,
343350
)
344351

345-
setattr(tx_settler, "build", _build_unstaking_tx)
352+
setattr(tx_settler, "build", _build_unstaking_tx) # noqa: B010
346353
tx_settler.transact(
347354
method=lambda: {},
348355
contract="",
@@ -354,7 +361,7 @@ def _build_unstaking_tx(*args, **kargs) -> t.Dict:
354361
class OnChainManager:
355362
"""On chain service management."""
356363

357-
def __init__(self, rpc: str, key: Path, contracts: t.Dict) -> None:
364+
def __init__(self, rpc: str, key: Path, contracts: ContractAddresses) -> None:
358365
"""On chain manager."""
359366
self.rpc = rpc
360367
self.key = key
@@ -427,7 +434,7 @@ def info(self, token_id: int) -> t.Dict:
427434
instances=instances,
428435
)
429436

430-
def mint(
437+
def mint( # pylint: disable=too-many-arguments,too-many-locals
431438
self,
432439
package_path: Path,
433440
agent_id: int,
@@ -437,8 +444,8 @@ def mint(
437444
nft: Optional[Union[Path, IPFSHash]],
438445
update_token: t.Optional[int] = None,
439446
token: t.Optional[str] = None,
440-
):
441-
"Mint service."
447+
) -> t.Dict:
448+
"""Mint service."""
442449
# TODO: Support for update
443450
self._patch()
444451
manager = MintManager(
@@ -538,7 +545,7 @@ def deploy(
538545
reuse_multisig=reuse_multisig,
539546
)
540547

541-
def swap(
548+
def swap( # pylint: disable=too-many-arguments,too-many-locals
542549
self,
543550
service_id: int,
544551
multisig: str,
@@ -554,7 +561,7 @@ def swap(
554561
)
555562
with tempfile.TemporaryDirectory() as temp_dir:
556563
key_file = Path(temp_dir, "key.txt")
557-
key_file.write_text(owner_key)
564+
key_file.write_text(owner_key, encoding="utf-8")
558565
owner_crypto = EthereumCrypto(private_key_path=str(key_file))
559566
owner_cryptos: list[EthereumCrypto] = [owner_crypto]
560567
owners = [

0 commit comments

Comments
 (0)