laminlabs / lamindb-setup

Setup & configure LaminDB.
Apache License 2.0
4 stars 2 forks source link

Prettify output #466

Open Zethson opened 1 year ago

Zethson commented 1 year ago

lamin info

gives

Current user: zethson
- handle: zethson
- email: lukas.heumos@posteo.net
- id: I5DPZdiE
Current instance: zethson/lukas-bionty-test
- owner: zethson
- name: lukas-bionty-test
- storage root: s3://lukas-bionty-test/
- storage region: eu-central-1
- db: sqlite:////home/zeth/.cache/lamindb/lukas-bionty-test/lukas-bionty-test.lndb
- schema: {'bionty'}

without any colors. Think we can do better.

>>> import lamindb as ln
>>> ln.view()
****************
* module: core *
****************
Storage
                            root type        region          created_at updated_at
id                                                                                
Zg0KqiDx  s3://lukas-bionty-test   s3  eu-central-1 2023-03-30 14:36:29       None
User
                            email   handle  name          created_at updated_at
id                                                                             
I5DPZdiE  lukas.heumos@posteo.net  zethson  None 2023-03-30 14:36:28       None
******************
* module: bionty *
******************

isn't really pretty. We could prettify this with a Rich table

Zethson commented 1 year ago

Could be done with rich like this:

from rich.console import Console

console = Console()

user_info = {
    "Handle": "zethson",
    "Email": "lukas.heumos@posteo.net",
    "ID": "I5DPZdiE"
}

instance_info = {
    "Owner": "zethson",
    "Name": "lukas-bionty-test",
    "Storage Root": "s3://lukas-bionty-test/",
    "Storage Region": "eu-central-1",
    "Database": "sqlite:////home/zeth/.cache/lamindb/lukas-bionty-test/lukas-bionty-test.lndb",
    "Schema": "{'bionty'}"
}

console.rule("User Information", style="blue")
for key, value in user_info.items():
    console.print(f"- [cyan]{key}[/cyan]: {value}")

console.rule("Current Instance", style="blue")
for key, value in instance_info.items():
    console.print(f"- [cyan]{key}[/cyan]: {value}")
Zethson commented 1 year ago

The function

from ._settings import settings

def info():
    """Log information about current instance & user."""
    # Accessing cached settings is faster than accessing the hub
    print(settings.user)
    if settings._instance_exists:
        print(settings.instance)
    else:
        print("No instance loaded: lamin load <instance>")

already returns the "current user" bla so it's annoying to format it