Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metagraph output #1116

Merged
merged 23 commits into from
Mar 9, 2023
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
4 changes: 2 additions & 2 deletions bittensor/_cli/commands/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run (cli):
ep = metagraph.endpoint_objs[uid]
row = [
str(ep.uid),
'{:.5f}'.format( metagraph.stake[uid]),
'{:.5f}'.format( metagraph.total_stake[uid]),
'{:.5f}'.format( metagraph.ranks[uid]),
'{:.5f}'.format( metagraph.trust[uid]),
'{:.5f}'.format( metagraph.consensus[uid]),
Expand All @@ -66,7 +66,7 @@ def run (cli):
ep.hotkey[:10],
ep.coldkey[:10]
]
total_stake += metagraph.stake[uid]
total_stake += metagraph.total_stake[uid]
total_rank += metagraph.ranks[uid]
# total_validator_trust += metagraph.validator_trust[uid]
total_trust += metagraph.trust[uid]
Expand Down
2 changes: 1 addition & 1 deletion bittensor/_subtensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def transfer_extrinsic(
block_hash = response.block_hash
bittensor.__console__.print("[green]Block Hash: {}[/green]".format( block_hash ))

explorer_url = bittensor.utils.get_explorer_url_for_network( subtensor.network, block_hash )
explorer_url = bittensor.utils.get_explorer_url_for_network( subtensor.network, block_hash, bittensor.__network_explorer_map__ )
if explorer_url is not None:
bittensor.__console__.print("[green]Explorer Link: {}[/green]".format( explorer_url ))

Expand Down
44 changes: 43 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from typing import Union, Optional
from bittensor import Balance, NeuronInfo, AxonInfo, PrometheusInfo, Keypair, __ss58_format__
from scalecodec import ss58_encode
from rich.console import Console
from rich.text import Text

from Crypto.Hash import keccak

Expand Down Expand Up @@ -122,4 +124,44 @@ def get_mock_neuron_by_uid( uid: int, **kwargs ) -> NeuronInfo:
hotkey = get_mock_hotkey(uid),
coldkey = get_mock_coldkey(uid),
**kwargs
)
)

class MockStatus:
def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
pass

class MockConsole:
"""
Mocks the console object for status and print.
Captures the last print output as a string.
"""
captured_print = None

def status(self, *args, **kwargs):
return MockStatus()

def print(self, *args, **kwargs):
console = Console(width = 1000, no_color=True, markup=False) # set width to 1000 to avoid truncation
console.begin_capture()
console.print(*args, **kwargs)
self.captured_print = console.end_capture()

def clear(self, *args, **kwargs):
pass

@staticmethod
def remove_rich_syntax(text: str) -> str:
"""
Removes rich syntax from the given text.
Removes markup and ansi syntax.
"""
output_no_syntax = Text.from_ansi(
Text.from_markup(
text
).plain
).plain

return output_no_syntax
Loading