Skip to content
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
6 changes: 6 additions & 0 deletions adev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ autonomy_dependencies:
- open-aea-ledger-cosmos
- open-aea-cli-ipfs
extras: null
- name: visualisation-station
version: 0.1.4
location: remote
url: https://api.github.com/repos/StationsStation/visualisation_station
plugins: null
extras: null
poetry_dependencies:
- name: open-autonomy
version: 0.19.4
Expand Down
4 changes: 2 additions & 2 deletions auto_dev/commands/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Command to run tests for packages."""

import rich_click as click
from rich.progress import track

from auto_dev.base import build_cli
from auto_dev.test import COVERAGE_COMMAND, test_path
Expand Down Expand Up @@ -116,7 +115,8 @@ def test(ctx, path, watch, coverage_report) -> None:
msg = f"Unable to get packages are you in the right directory? {error}"
raise click.ClickException(msg) from error
results = {}
for package in track(range(len(packages)), description="Testing..."):
for package in range(len(packages)):
click.echo(f"Testing {packages[package]} {package + 1}/{len(packages)}")
result = test_path(str(packages[package]), verbose=verbose, watch=watch)
results[packages[package]] = result
click.echo(f"{'👌' if result else '❗'} - {packages[package]}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
python-version:
# - "3.9"
- "3.10"
- "3.11"
poetry-version: ["1.8.3"]
os: [ubuntu-20.04,]
runs-on: ${{ matrix.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

strategy:
matrix:
python-versions: ["3.10"]
python-versions: ["3.11"]

permissions:
contents: write
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#! /usr/bin/env bash

# This script is used to run the pre-commit checks for the repository.
# It is called by the pre-commit hook in the repository.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#! /usr/bin/env bash
set -e

# Run lock command and store potential changes
Expand Down
47 changes: 0 additions & 47 deletions auto_dev/data/repo/templates/autonomy/scripts/run_mas.sh

This file was deleted.

2 changes: 1 addition & 1 deletion auto_dev/data/templates/compose/tendermint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
cpus: 0.5
container_name: tm_0
hostname: tm_0
image: "valory/open-autonomy-tendermint:0.15.2"
image: "valory/open-autonomy-tendermint:0.19.4"
restart: always
network_mode: ${NETWORK_MODE}
environment:
Expand Down
2 changes: 1 addition & 1 deletion auto_dev/packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"dev": {},
"third_party": {
"agent/eightballer/base/0.1.0": "bafybeibgotyzg5n7ldgqrunowietfyqvfbmtyhm7ezpjelqiiuamnhml44",
"agent/eightballer/frontend_agent/0.1.0": "bafybeigvt6z3pcub3klzetwpmjxgzpf2hg6uq3vcoe6g7n4cdqz3jr3fqu"
"agent/eightballer/frontend_agent/0.1.0": "bafybeieq3t5vfj57hlr4tmezubut4remtpjawwtdk7aepbwpb4gun5px6e"
}
}
6 changes: 5 additions & 1 deletion auto_dev/services/package_manager/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def add_to_packages(
logger.warning(f"Package already exists in dev packages: {key} skipping.")
continue
try:
data["dev"][key] = package_id.package_hash
key_hash = DEFAULT_IPFS_HASH if not package_id.public_id._package_hash else package_id.package_hash # noqa
data["dev"][key] = key_hash
except ValueError as e:
logger.exception(f"Error adding package: {e}")
msg = f"Error adding package {key} to registry. {package_id}"
Expand Down Expand Up @@ -359,5 +360,8 @@ def publish_agent(
if not Path(DEFAULT_AEA_CONFIG_FILE).exists():
msg = "Not in an agent directory. Please run this command from an agent directory."
raise OperationError(msg)
# we check if there are keys and remove them
if self.agent_runner:
self.agent_runner.remove_keys()
# Publish from agent directory (we're already there)
self._publish_internal(force, new_public_id=new_public_id)
72 changes: 65 additions & 7 deletions auto_dev/services/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import requests
from docker.errors import NotFound
from aea.skills.base import PublicId
from aea.configurations.base import PackageType
from aea_ledger_ethereum import EthereumCrypto
from aea.helpers.env_vars import is_env_variable
from aea.configurations.base import PackageId, PackageType
from aea.configurations.constants import DEFAULT_AEA_CONFIG_FILE

from auto_dev.utils import change_dir, map_os_to_env_vars, load_autonolas_yaml
Expand Down Expand Up @@ -45,6 +47,7 @@ class DevAgentRunner(AgentRunner):
ipfs_hash: str | None = None
use_tendermint: bool = True
install_deps: bool = True
ethereum_address: str | None = None

def __post_init__(
self,
Expand Down Expand Up @@ -134,7 +137,7 @@ def check_tendermint(self, retries: int = 0) -> None:
time.sleep(0.2)
self.check_tendermint(retries + 1)
if res.status == "running":
self.attempt_hard_reset()
self._attempt_hard_reset()
except (subprocess.CalledProcessError, RuntimeError, NotFound) as e:
self.logger.info(f"Tendermint container not found or error: {e}")
if retries > 3:
Expand All @@ -151,7 +154,7 @@ def check_tendermint(self, retries: int = 0) -> None:
self.logger.info("Tendermint is running and healthy ✅")
return None

def attempt_hard_reset(self, attempts: int = 0) -> None:
def _attempt_hard_reset(self, attempts: int = 0) -> None:
"""Attempt to hard reset Tendermint."""
if attempts >= TENDERMINT_RESET_RETRIES:
self.logger.error(f"Failed to reset Tendermint after {TENDERMINT_RESET_RETRIES} attempts.")
Expand All @@ -168,7 +171,7 @@ def attempt_hard_reset(self, attempts: int = 0) -> None:

self.logger.info(f"Tendermint not ready (attempt {attempts + 1}/{TENDERMINT_RESET_RETRIES}), waiting...")
time.sleep(1)
self.attempt_hard_reset(attempts + 1)
self._attempt_hard_reset(attempts + 1)

def fetch_agent(self) -> None:
"""Fetch the agent from registry if needed."""
Expand Down Expand Up @@ -202,13 +205,51 @@ def setup(self) -> None:
self.logger.info("Setting up agent keys...")
self.manage_keys()

self.logger.info("Detecting Necessary Overrides. ")
self.extract_magic_overrides()

self.logger.info("Installing dependencies...")
self.install_dependencies() if self.install_deps else None

self.logger.info("Setting up certificates...")
self.issue_certificates()
self.logger.info("Agent setup complete. 🎉")

def extract_magic_overrides(self):
"""Extract the magic overrides necessary for concensus."""

magic_overrides = {
".models.params.args.setup.all_participants": lambda: f'["{self.ethereum_address}"]',
}

_config, *overrides = load_autonolas_yaml(PackageType.AGENT, self.agent_dir)

dotted_paths = {}
# we go through each override and check if it is an imputed value

def recurse_dictionary(dictionary, path=""):
for key, value in dictionary.items():
if isinstance(value, dict):
recurse_dictionary(value, path=f"{path}.{key}")
elif is_env_variable(value):
dotted_paths[path + f".{key}"] = value

for override in overrides:
_type = override["type"]
public_id = PublicId.from_str(override["public_id"])
package_id = PackageId(package_type=PackageType(_type), public_id=public_id)
path = f"{package_id.package_type.value}.{public_id.name}"
recurse_dictionary(override, path=path)

overrides = {}
for key in dotted_paths:
for magic_var, getter in magic_overrides.items():
if magic_var in key:
_key = key.upper().replace(".", "_")
overrides[_key] = getter()

self._env_vars = overrides

def manage_keys(
self,
generate_keys: bool = True,
Expand All @@ -222,12 +263,29 @@ def manage_keys(
for ledger in required_ledgers:
self.logger.info(f"Processing ledger: {ledger}")
# We check if a key already exists for the ledger
key_file = Path("..") / f"{ledger}_private_key.txt"
new_key_file = Path(f"{ledger}_private_key.txt")
if new_key_file.exists():
self.logger.info(f"Key file {new_key_file} already exists. Skipping key generation.")
continue
key_file = Path("..") / new_key_file
if key_file.exists():
self.setup_ledger_key(ledger, generate_keys=False, existing_key_file=key_file)
else:
self.setup_ledger_key(ledger, generate_keys)

self.ethereum_address = EthereumCrypto().load_private_key_from_path("ethereum_private_key.txt").address

def remove_keys(self) -> None:
"""Remove keys from the agent."""
self.logger.info("Removing keys...")
config = load_autonolas_yaml(PackageType.AGENT)[0]
required_ledgers = config["private_key_paths"]
for ledger in required_ledgers:
cmd = f"aea -s remove-key {ledger}"
self.execute_command(cmd)

self.logger.info("Keys removed. 🔑")

def setup_ledger_key(self, ledger: str, generate_keys, existing_key_file: Path | None = None) -> None:
"""Setup the agent with the ledger key."""
key_file = Path(f"{ledger}_private_key.txt")
Expand Down Expand Up @@ -255,7 +313,7 @@ def install_dependencies(self) -> None:
def issue_certificates(self) -> None:
"""Issue certificates for agent if needed."""
if not Path("../certs").exists():
self.execute_command("aea -s issue-certificates")
self.execute_command("aea -s issue-certificates", verbose=True)
else:
self.execute_command("cp -r ../certs ./")

Expand Down Expand Up @@ -300,7 +358,7 @@ def execute_agent(
"""
self.logger.info("Starting agent execution...")
try:
result = self.execute_command("aea -s run --env ../.env", verbose=True)
result = self.execute_command("aea -s run --env ../.env", verbose=True, env_vars=self._env_vars)
if result:
self.logger.info("Agent execution completed successfully. 😎")
else:
Expand Down
12 changes: 5 additions & 7 deletions auto_dev/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from multiprocessing import cpu_count

from auto_dev.workflow_manager import Task
import pytest


COVERAGE_COMMAND = f"""coverage report \
Expand Down Expand Up @@ -59,9 +59,7 @@ def test_path(
if multiple:
extra_args.extend(("-n", str(cpu_count())))

args = ["pytest", path, *extra_args]
env = os.environ.copy()
env.update({"PYTHONPATH": "."})
task = Task(command=" ".join(args), env_vars=env, stream=verbose, verbose=verbose)
task.work()
return not task.is_failed
args = [path, *extra_args]
os.environ["PYTHONPATH"] = "."
result = pytest.main(args)
return result == 0
36 changes: 1 addition & 35 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pycryptodome = "==3.20.0"
rich-click = "^1.8.2"
tbump = "^6.11.0"
requests = ">=2.28.1,<3"
pytest-xdist = "^3.6.1"
ruff = "^0.5.7"
pydoclint = {extras = ["all"], version = "^0.6.0"}
pydantic = "^2.8.2"
Expand Down
Loading