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

Initial support for HTML table outputs #17

Merged
merged 8 commits into from
Aug 27, 2024
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
51 changes: 44 additions & 7 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ class Options:
help="The netuid (network unique identifier) of the subnet within the root network, (e.g. 1)",
prompt=True,
)
reuse_last = typer.Option(
False,
help="Reuse the metagraph data you last retrieved. Only use this if you have already retrieved metagraph"
"data",
)
html_output = typer.Option(
False,
"--html",
help="Display the table as HTML in the browser, rather than in the Terminal.",
)


def list_prompt(init_var: list, list_type: type, help_text: str) -> list:
Expand Down Expand Up @@ -1167,9 +1177,9 @@ def wallet_create_wallet(
wallet_path: Optional[str] = Options.wallet_path,
wallet_hotkey: Optional[str] = Options.wallet_hk_req,
n_words: Optional[int] = None,
use_password: Optional[bool] = Options.use_password,
overwrite_hotkey: Optional[bool] = Options.overwrite_hotkey,
overwrite_coldkey: Optional[bool] = Options.overwrite_coldkey,
use_password: bool = Options.use_password,
overwrite_hotkey: bool = Options.overwrite_hotkey,
overwrite_coldkey: bool = Options.overwrite_coldkey,
):
"""
# wallet create
Expand Down Expand Up @@ -2884,7 +2894,13 @@ def sudo_get(
sudo.get_hyperparameters(self.initialize_chain(network, chain), netuid)
)

def subnets_list(self, network: str = Options.network, chain: str = Options.chain):
def subnets_list(
self,
network: str = Options.network,
chain: str = Options.chain,
reuse_last: bool = Options.reuse_last,
html_output: bool = Options.html_output,
):
"""
# subnets list
Executes the `list` command to list all subnets and their detailed information on the Bittensor network.
Expand Down Expand Up @@ -2932,8 +2948,12 @@ def subnets_list(self, network: str = Options.network, chain: str = Options.chai
This command is particularly useful for users seeking an overview of the Bittensor network's structure and the
distribution of its resources and ownership information for each subnet.
"""
if reuse_last:
subtensor = None
else:
subtensor = self.initialize_chain(network, chain)
return self._run_command(
subnets.subnets_list(self.initialize_chain(network, chain))
subnets.subnets_list(subtensor, reuse_last, html_output)
)

def subnets_lock_cost(
Expand Down Expand Up @@ -3205,9 +3225,15 @@ def subnets_register(

def subnets_metagraph(
self,
netuid: int = Options.netuid,
netuid: Optional[int] = typer.Option(
None,
help="The netuid (network unique identifier) of the subnet within the root network, (e.g. 1). This does"
"is ignored when used with `--reuse-last`.",
),
network: str = Options.network,
chain: str = Options.chain,
reuse_last: bool = Options.reuse_last,
html_output: bool = Options.html_output,
):
"""
Executes the `metagraph` command to retrieve and display the entire metagraph for a specified network.
Expand Down Expand Up @@ -3269,8 +3295,19 @@ def subnets_metagraph(
It is useful for network analysis and diagnostics. It is intended to be used as part of the Bittensor CLI and
not as a standalone function within user code.
"""
if reuse_last:
if netuid is not None:
console.print("Cannot specify netuid when using `--reuse-last`")
raise typer.Exit()
subtensor = None
else:
if netuid is None:
netuid = rich.prompt.IntPrompt.ask(
"Enter the netuid (network unique identifier) of the subnet within the root network, (e.g. 1)."
)
subtensor = self.initialize_chain(network, chain)
return self._run_command(
subnets.metagraph_cmd(self.initialize_chain(network, chain), netuid)
subnets.metagraph_cmd(subtensor, netuid, reuse_last, html_output)
)

def weights_reveal(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GitPython>=3.0.0
fuzzywuzzy~=0.18.0
netaddr~=1.3.0
numpy>=2.0.1
Jinja2
pycryptodome # Crypto
PyYAML~=6.0.1
rich~=13.7
Expand Down
4 changes: 1 addition & 3 deletions src/bittensor/async_substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,7 @@ async def result_handler(message: dict, subscription_id) -> tuple[dict, bool]:
):
# Created as a task because we don't actually care about the result
self._forgettable_task = asyncio.create_task(
self.rpc_request(
"author_unwatchExtrinsic", [subscription_id]
)
self.rpc_request("author_unwatchExtrinsic", [subscription_id])
)
return {
"block_hash": message_result["inblock"],
Expand Down
4 changes: 2 additions & 2 deletions src/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ async def unstake_extrinsic(

with console.status(
f":satellite: Unstaking from chain: [white]{subtensor}[/white] ..."
):
):
unstaking_balance = Balance.from_tao(unstaking_balance)
call = await subtensor.substrate.compose_call(
call_module="SubtensorModule",
Expand Down Expand Up @@ -1423,7 +1423,7 @@ async def unstake(
hotkey_ss58=final_hotkeys[0][1],
amount=None if unstake_all else final_amounts[0],
wait_for_inclusion=True,
prompt=False, #TODO: Add no prompt
prompt=False, # TODO: Add no prompt
)
else:
await unstake_multiple_extrinsic(
Expand Down
Loading
Loading