Skip to content

Commit

Permalink
chore: delete double-y implemented __getitem__ from NetworkManager (
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed May 8, 2024
1 parent 42cf4bc commit fd38225
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,26 @@ def ecosystems(self) -> Dict[str, EcosystemAPI]:
"""
All the registered ecosystems in ``ape``, such as ``ethereum``.
"""
ecosystem_objs = self._plugin_ecosystems
plugin_ecosystems = self._plugin_ecosystems

# Load config.
custom_networks: List = self.config_manager.get_config("networks").get("custom", [])
for custom_network in custom_networks:
ecosystem_name = custom_network.ecosystem
if ecosystem_name in ecosystem_objs:
if ecosystem_name in plugin_ecosystems:
# Already included in previous network.
continue

base_ecosystem_name = (
custom_network.get("base_ecosystem_plugin") or self.default_ecosystem_name
)
existing_cls = ecosystem_objs[base_ecosystem_name]
existing_cls = plugin_ecosystems[base_ecosystem_name]
ecosystem_cls = existing_cls.model_copy(
update={"name": ecosystem_name}, cache_clear=("_networks_from_plugins",)
)
ecosystem_objs[ecosystem_name] = ecosystem_cls
plugin_ecosystems[ecosystem_name] = ecosystem_cls

return ecosystem_objs
return plugin_ecosystems

@cached_property
def _plugin_ecosystems(self) -> Dict[str, EcosystemAPI]:
Expand Down Expand Up @@ -273,25 +273,6 @@ def __iter__(self) -> Iterator[str]:
"""
yield from self.ecosystems

def __getitem__(self, ecosystem_name: str) -> EcosystemAPI:
"""
Get an ecosystem by name.
Raises:
:class:`~ape.exceptions.NetworkError`: When the given ecosystem name is
unknown.
Args:
ecosystem_name (str): The name of the ecosystem to get.
Returns:
:class:`~ape.api.networks.EcosystemAPI`
"""
if ecosystem_name not in self.ecosystems:
raise IndexError(f"Unknown ecosystem '{ecosystem_name}'.")

return self.ecosystems[ecosystem_name]

def __ape_extra_attributes__(self) -> Iterator[ExtraModelAttributes]:
yield ExtraModelAttributes(
name="ecosystems",
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,9 @@ def test_fork_past_genesis(networks, mock_sepolia, mock_fork_provider, eth_teste
with pytest.raises(NetworkError, match="Unable to fork past genesis block."):
with networks.fork(block_number=block_id):
pass


def test_getitem(networks):
ethereum = networks["ethereum"]
assert ethereum.name == "ethereum"
assert isinstance(ethereum, EcosystemAPI)

0 comments on commit fd38225

Please sign in to comment.