Skip to content

Commit a2ac201

Browse files
committed
Changed _determine_network to its own method to use it without instantiating a SubtensorInterface obj
1 parent 77d7a41 commit a2ac201

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

bittensor_cli/cli.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,32 +1061,35 @@ def initialize_chain(
10611061
"Verify this is intended.",
10621062
)
10631063
if not self.subtensor:
1064-
if network:
1065-
network_ = None
1066-
for item in network:
1067-
if item.startswith("ws"):
1068-
network_ = item
1069-
break
1070-
else:
1071-
network_ = item
1072-
1073-
not_selected_networks = [net for net in network if net != network_]
1074-
if not_selected_networks:
1075-
console.print(
1076-
f"Networks not selected: "
1077-
f"[{COLORS.G.ARG}]{', '.join(not_selected_networks)}[/{COLORS.G.ARG}]"
1078-
)
1064+
self.subtensor = SubtensorInterface(self._determine_network(network))
1065+
return self.subtensor
10791066

1080-
self.subtensor = SubtensorInterface(network_)
1081-
elif self.config["network"]:
1082-
self.subtensor = SubtensorInterface(self.config["network"])
1083-
console.print(
1084-
f"Using the specified network [{COLORS.G.LINKS}]{self.config['network']}"
1085-
f"[/{COLORS.G.LINKS}] from config"
1086-
)
1067+
def _determine_network(self, network: Optional[list[str]] = None):
1068+
if network:
1069+
network_ = None
1070+
for item in network:
1071+
if item.startswith("ws"):
1072+
network_ = item
1073+
break
10871074
else:
1088-
self.subtensor = SubtensorInterface(defaults.subtensor.network)
1089-
return self.subtensor
1075+
network_ = item
1076+
1077+
not_selected_networks = [net for net in network if net != network_]
1078+
if not_selected_networks:
1079+
console.print(
1080+
f"Networks not selected: "
1081+
f"[{COLORS.G.ARG}]{', '.join(not_selected_networks)}[/{COLORS.G.ARG}]"
1082+
)
1083+
1084+
return network_
1085+
elif self.config["network"]:
1086+
console.print(
1087+
f"Using the specified network [{COLORS.G.LINKS}]{self.config['network']}"
1088+
f"[/{COLORS.G.LINKS}] from config"
1089+
)
1090+
return self.config["network"]
1091+
else:
1092+
return defaults.subtensor.network
10901093

10911094
def _run_command(self, cmd: Coroutine, exit_early: bool = True):
10921095
"""

0 commit comments

Comments
 (0)