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

Bump [email protected] and get rid of the service delete workaround #25

Merged
merged 6 commits into from
Feb 28, 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
1 change: 0 additions & 1 deletion frontend/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type Service = {
readme?: string;
ledger: LedgerConfig;
chain_data: ChainData;
active: boolean;
};

export type ServiceTemplate = {
Expand Down
9 changes: 5 additions & 4 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@

from aea_ledger_ethereum.ethereum import EthereumCrypto
from clea import group, params, run
from operate.constants import KEY, KEYS, OPERATE, SERVICES
from operate.http import Resource
from operate.keys import Keys
from operate.services.manage import Services
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware
from starlette.routing import Route
from typing_extensions import Annotated
from uvicorn.main import run as uvicorn

from operate.constants import KEY, KEYS, OPERATE, SERVICES
from operate.http import Resource
from operate.keys import Keys
from operate.services.manage import Services

DEFAULT_HARDHAT_KEY = (
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
).encode()
Expand Down
1 change: 0 additions & 1 deletion operate/data/contracts/uniswap_v2_erc20/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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
3 changes: 2 additions & 1 deletion operate/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import typing as t
from abc import ABC

from operate.http.exceptions import NotAllowed, ResourceException
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.types import Receive, Scope, Send

from operate.http.exceptions import NotAllowed, ResourceException

GenericResource = t.TypeVar("GenericResource")
PostPayload = t.TypeVar("PostPayload")
PostResponse = t.TypeVar("PostResponse")
Expand Down
1 change: 1 addition & 0 deletions operate/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pathlib import Path

from aea_ledger_ethereum.ethereum import EthereumCrypto

from operate.types import KeyType


Expand Down
1 change: 1 addition & 0 deletions operate/ledger/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import typing as t

from aea_ledger_ethereum import EthereumApi, EthereumCrypto

from operate.ledger.base import LedgerHelper
from operate.types import LedgerType

Expand Down
109 changes: 0 additions & 109 deletions operate/services/_subgraph.py

This file was deleted.

5 changes: 3 additions & 2 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
TM_STATE_DIR,
VENVS_DIR,
)
from starlette.types import Receive, Scope, Send
from typing_extensions import TypedDict

from operate.http import Resource
from operate.http.exceptions import BadRequest
from operate.keys import Keys
Expand All @@ -48,8 +51,6 @@
ServiceTemplate,
ServiceType,
)
from starlette.types import Receive, Scope, Send
from typing_extensions import TypedDict

OPERATE = ".operate"
CONFIG = "config.json"
Expand Down
4 changes: 1 addition & 3 deletions operate/services/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@
from autonomy.cli.helpers.chain import OnChainHelper
from autonomy.cli.helpers.chain import ServiceHelper as ServiceManager
from hexbytes import HexBytes

from operate.data import DATA_DIR
from operate.data.contracts.service_staking_token.contract import (
ServiceStakingTokenContract,
)
from operate.ledger.profiles import CONTRACTS

from ._subgraph import SubgraphClient

ZERO_ETH = 0


Expand Down Expand Up @@ -447,7 +446,6 @@ def mint(
key=self.key,
update_token=update_token,
)
manager.subgraph = SubgraphClient()

# Prepare for minting
(
Expand Down
26 changes: 4 additions & 22 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
VENVS_DIR,
)
from autonomy.deploy.generators.docker_compose.base import DockerComposeGenerator
from starlette.types import Receive, Scope, Send
from typing_extensions import TypedDict

from operate.constants import (
CONFIG,
DEPLOYMENT,
Expand All @@ -63,8 +66,6 @@
ServiceType,
Status,
)
from starlette.types import Receive, Scope, Send
from typing_extensions import TypedDict


def build_dirs(build_dir: Path) -> None:
Expand Down Expand Up @@ -373,7 +374,6 @@ def __init__(
keys: KeysType,
ledger: t.Optional[LedgerConfig] = None,
chain_data: t.Optional[ChainData] = None,
active: bool = False,
name: t.Optional[str] = None,
) -> None:
"""Initialize object."""
Expand All @@ -382,7 +382,6 @@ def __init__(
self.keys = keys
self.hash = phash
self.ledger = ledger
self.active = active
self.service_path = service_path
self.chain_data = chain_data or {}
self.path = self.service_path.parent
Expand Down Expand Up @@ -427,7 +426,6 @@ def json(self) -> ServiceType:
"readme": (
readme.read_text(encoding="utf-8") if readme.exists() else None
),
"active": self.active,
}
)

Expand All @@ -449,7 +447,6 @@ def load(cls, path: Path) -> "Service":
chain_data=config.get("chain_data"),
service_path=Path(config["service_path"]),
name=config["name"],
active=config["active"],
)

@classmethod
Expand Down Expand Up @@ -480,31 +477,16 @@ def new(
ledger=ledger,
service_path=Path(downloaded),
name=name,
active=True,
)
service.store()
return service

def __update(self, data: ServiceType) -> ServiceType:
"""Update service."""
# TODO: Finish implementation
self.hash = data["hash"]
self.keys = data["keys"]
self.variables = data.get("variables", self.variables)
self.ledger = data.get("ledger", self.ledger)
self.name = data.get("name", self.name)
self.chain_data = data.get("chain_data", self.chain_data)
self.store()
return self.json

def delete(self, data: DeleteServicePayload) -> DeleteServiceResponse:
"""Delete service."""
try:
shutil.rmtree(self.path)
except (PermissionError, OSError):
# If we get permission error we set the service in-active
# user can then run operate prune with admin priviledges
# to clean up the cache/unused data
self.active = False
self.store()
Comment on lines -502 to -509
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@truemiller the endpoint will delete the service completely

shutil.rmtree(self.path)
return DeleteServiceResponse({})
1 change: 0 additions & 1 deletion operate/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class ServiceType(TypedDict):
readme: NotRequired[str]
ledger: NotRequired[LedgerConfig]
chain_data: NotRequired[ChainData]
active: bool


ServicesType = t.List[ServiceType]
Expand Down
Loading
Loading