Skip to content

Commit

Permalink
Merge pull request #725 from valory-xyz/fix/windows-addr-res
Browse files Browse the repository at this point in the history
Fix IPFS node address parsing on Git console
  • Loading branch information
angrybayblade authored Mar 12, 2024
2 parents 9c2abaf + b04592d commit 162e4a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
19 changes: 17 additions & 2 deletions aea/cli/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2022 Valory AG
# Copyright 2021-2024 Valory AG
# Copyright 2018-2019 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +20,7 @@

"""Implementation of the 'aea init' subcommand."""

import platform
from pathlib import Path
from typing import Dict, Optional

Expand Down Expand Up @@ -138,11 +139,25 @@ def _registry_init_remote(
_registry_init_http(username=author, no_subscribe=no_subscribe)


def _clean_ipfs_node_url(ipfs_node: Optional[str]) -> str:
"""Clean IPFS node URL."""
if ipfs_node is None:
return DEFAULT_IPFS_URL
if platform.system() != "Windows":
return ipfs_node
if not ipfs_node.startswith("C:/"):
return ipfs_node
*_, ipfs_node = ipfs_node.split("/dns/")
return f"/dns/{ipfs_node}"


def _registry_init_ipfs(ipfs_node: Optional[str]) -> None:
"""Initialize ipfs registry"""

registry_config = _set_registries(REGISTRY_REMOTE, REMOTE_IPFS)
registry_config["settings"][REGISTRY_REMOTE][REMOTE_IPFS]["ipfs_node"] = ipfs_node
registry_config["settings"][REGISTRY_REMOTE][REMOTE_IPFS][
"ipfs_node"
] = _clean_ipfs_node_url(ipfs_node=ipfs_node)
update_cli_config({REGISTRY_CONFIG_KEY: registry_config})


Expand Down
12 changes: 11 additions & 1 deletion tests/test_cli/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2022 Valory AG
# Copyright 2021-2024 Valory AG
# Copyright 2018-2019 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -28,6 +28,7 @@
import yaml

from aea.cli import cli
from aea.cli.init import _clean_ipfs_node_url

from tests.conftest import CLI_LOG_OPTION, CliRunner, random_string

Expand Down Expand Up @@ -135,3 +136,12 @@ def teardown(self):
self.cli_config_patch.stop()
os.chdir(self.cwd)
shutil.rmtree(self.t)


def test_node_addr_cleanup() -> None:
"""Test node address clean up method."""

original_addr = "/dns/to/some/node"
consoled_parsed_addr = f"C:/Git/bin/{original_addr}"
with patch("platform.system", return_value="Windows"):
assert _clean_ipfs_node_url(ipfs_node=consoled_parsed_addr) == original_addr

0 comments on commit 162e4a8

Please sign in to comment.