Skip to content

Commit

Permalink
feat: add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi committed Jun 14, 2024
1 parent 3cff6e4 commit 6259117
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 46 deletions.
2 changes: 1 addition & 1 deletion electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TempDir = `${OperateDirectory}/temp`;
const VersionFile = `${OperateDirectory}/version.txt`;
const LogFile = `${OperateDirectory}/logs.txt`;
const OperateInstallationLog = `${os.homedir()}/operate.log`;
const OperateCmd = `${os.homedir()}/.operate/venv/bin/operate`;
const OperateCmd = `${os.homedir()}/dist/${os.platform()}/pearl/pearl`;
const Env = {
...process.env,
PATH: `${process.env.PATH}:/opt/homebrew/bin:/usr/local/bin`,
Expand Down
5 changes: 5 additions & 0 deletions pearl.py → operate/pearl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from aea.mail.base_pb2 import DESCRIPTOR
from multiaddr.codecs.idna import to_bytes as _
from multiaddr.codecs.uint16be import to_bytes as _
from aea_ledger_ethereum.ethereum import *
from aea_ledger_cosmos.cosmos import *
from aea_ledger_ethereum_flashbots.ethereum_flashbots import *
from aea.crypto.registries.base import *

from operate.cli import main

if __name__ == "__main__":
Expand Down
49 changes: 8 additions & 41 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
from copy import copy, deepcopy
from dataclasses import dataclass
from pathlib import Path
from venv import main as venv_cli

import psutil
from aea.__version__ import __version__ as aea_version
from aea.configurations.constants import (
DEFAULT_LEDGER,
LEDGER,
Expand All @@ -44,7 +42,6 @@
from aea.configurations.data_types import PackageType
from aea.helpers.yaml_utils import yaml_dump, yaml_load, yaml_load_all
from aea_cli_ipfs.ipfs_utils import IPFSTool
from autonomy.__version__ import __version__ as autonomy_version
from autonomy.cli.helpers.deployment import run_deployment, stop_deployment
from autonomy.configurations.loader import load_service_config
from autonomy.deploy.base import BaseDeploymentGenerator
Expand Down Expand Up @@ -83,7 +80,6 @@
OnChainUserParams,
)


SAFE_CONTRACT_ADDRESS = "safe_contract_address"
ALL_PARTICIPANTS = "all_participants"
CONSENSUS_THRESHOLD = "consensus_threshold"
Expand Down Expand Up @@ -299,7 +295,7 @@ def generate_config_tendermint(self) -> "HostDeploymentGenerator":
encoding="utf-8",
)
shutil.copy(
tendermint.__file__,
tendermint.__file__.replace('.pyc', '.py'),
self.build_dir / "tendermint.py",
)
return self
Expand All @@ -317,7 +313,6 @@ def generate(
json.dumps(agent, indent=2),
encoding="utf-8",
)
venv_cli(args=[str(self.build_dir / "venv")])
return self

def _populate_keys(self) -> None:
Expand All @@ -344,6 +339,8 @@ def populate_private_keys(self) -> "DockerComposeGenerator":
def _run_cmd(args: t.List[str], cwd: t.Optional[Path] = None) -> None:
"""Run command in a subprocess."""
print(f"Running: {' '.join(args)}")
# print working dir
print(f"Working dir: {os.getcwd()}")
result = subprocess.run( # pylint: disable=subprocess-run-check # nosec
args=args,
cwd=cwd,
Expand Down Expand Up @@ -387,27 +384,8 @@ def _setup_agent(working_dir: Path) -> None:
json.dumps(env, indent=4),
encoding="utf-8",
)
venv = working_dir / "venv"
pbin = str(venv / "bin" / "python")

# Install agent dependencies
_run_cmd(
args=[
pbin,
"-m",
"pip",
"install",
f"open-autonomy[all]=={autonomy_version}",
f"open-aea-ledger-ethereum=={aea_version}",
f"open-aea-ledger-ethereum-flashbots=={aea_version}",
f"open-aea-ledger-cosmos=={aea_version}",
],
)

# Install tendermint dependencies
_run_cmd(args=[pbin, "-m", "pip", "install", "flask", "requests"])

abin = str(venv / "bin" / "aea")
abin = os.getcwd() + '/dist/aea_bin/aea_bin'
# Fetch agent
_run_cmd(
args=[
Expand All @@ -434,12 +412,6 @@ def _setup_agent(working_dir: Path) -> None:
cwd=working_dir,
)

# Install agent dependencies
_run_cmd(
args=[abin, "-v", "debug", "install", "--timeout", "600"],
cwd=working_dir / "agent",
)

# Add keys
shutil.copy(
working_dir / "ethereum_private_key.txt",
Expand All @@ -458,8 +430,9 @@ def _setup_agent(working_dir: Path) -> None:
def _start_agent(working_dir: Path) -> None:
"""Start agent process."""
env = json.loads((working_dir / "agent.json").read_text(encoding="utf-8"))
aea_bin = os.getcwd() + '/dist/aea_bin/aea_bin'
process = subprocess.Popen( # pylint: disable=consider-using-with # nosec
args=[str(working_dir / "venv" / "bin" / "aea"), "run"],
args=[aea_bin, "run"],
cwd=working_dir / "agent",
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
Expand All @@ -477,15 +450,9 @@ def _start_agent(working_dir: Path) -> None:
def _start_tendermint(working_dir: Path) -> None:
"""Start tendermint process."""
env = json.loads((working_dir / "tendermint.json").read_text(encoding="utf-8"))
tendermint_com = os.getcwd() + "/dist/tendermint/tendermint"
process = subprocess.Popen( # pylint: disable=consider-using-with # nosec
args=[
str(working_dir / "venv" / "bin" / "flask"),
"run",
"--host",
"localhost",
"--port",
"8080",
],
args=[tendermint_com],
cwd=working_dir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
Expand Down
6 changes: 6 additions & 0 deletions operate/services/utils/tendermint.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,9 @@ def create_server() -> Any:
"""Function to retrieve just the app to be used by flask entry point."""
flask_app, _ = create_app()
return flask_app


if __name__ == '__main__':
# Start the Flask server programmatically
app = create_server()
app.run(host='localhost', port=8080)
63 changes: 63 additions & 0 deletions pearl_operate.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files
from PyInstaller.utils.hooks import collect_all

datas = []
binaries = []
hiddenimports = ['aea_ledger_ethereum', 'aea_ledger_cosmos', 'aea_ledger_ethereum_flashbots']
datas += collect_data_files('eth_account')
tmp_ret = collect_all('aea')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('autonomy')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('operate')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('aea_ledger_ethereum')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('aea_ledger_cosmos')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('aea_ledger_ethereum_flashbots')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]


a = Analysis(
['operate/pearl.py'],
pathex=[],
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='pearl',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='pearl',
)
Loading

0 comments on commit 6259117

Please sign in to comment.