File size: 2,520 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Module containing the WBURLs class and WBURL dataclass.

Used to store predefined URLs that can be associated with a name. The URLs are
shortened using with the `wandb.me` domain, using dub.co as the shortening service.
If the URLs need to be updates, use the dub.co service to point to the new URL.
"""

from __future__ import annotations

from dataclasses import dataclass


@dataclass
class WBURL:
    url: str
    description: str


class Registry:
    """A collection of URLs that can be associated with a name."""

    def __init__(self) -> None:
        self.urls: dict[str, WBURL] = {
            "wandb-launch": WBURL(
                "https://wandb.me/launch",
                "Link to the W&B launch marketing page",
            ),
            "wandb-init": WBURL(
                "https://wandb.me/wandb-init",
                "Link to the wandb.init reference documentation page",
            ),
            "define-metric": WBURL(
                "https://wandb.me/define-metric",
                "Link to the W&B developer guide documentation page on wandb.define_metric",
            ),
            "developer-guide": WBURL(
                "https://wandb.me/developer-guide",
                "Link to the W&B developer guide top level page",
            ),
            "wandb-core": WBURL(
                "https://wandb.me/wandb-core",
                "Link to the documentation for the wandb-core service",
            ),
            "wandb-server": WBURL(
                "https://wandb.me/wandb-server",
                "Link to the documentation for the self-hosted W&B server",
            ),
            "multiprocess": WBURL(
                "https://wandb.me/multiprocess",
                (
                    "Link to the W&B developer guide documentation page on how to "
                    "use wandb in a multiprocess environment"
                ),
            ),
        }

    def url(self, name: str) -> str:
        """Get the URL associated with the given name."""
        wb_url = self.urls.get(name)
        if wb_url:
            return wb_url.url
        raise ValueError(f"URL not found for {name}")

    def description(self, name: str) -> str:
        """Get the description associated with the given name."""
        wb_url = self.urls.get(name)
        if wb_url:
            return wb_url.description
        raise ValueError(f"Description not found for {name}")


# This is an instance of the Links class that can be used to access the URLs
url_registry = Registry()