links.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """Module containing the WBURLs class and WBURL dataclass.
  2. Used to store predefined URLs that can be associated with a name. The URLs are
  3. shortened using with the `wandb.me` domain, using dub.co as the shortening service.
  4. If the URLs need to be updates, use the dub.co service to point to the new URL.
  5. """
  6. from __future__ import annotations
  7. from dataclasses import dataclass
  8. @dataclass
  9. class WBURL:
  10. url: str
  11. description: str
  12. class Registry:
  13. """A collection of URLs that can be associated with a name."""
  14. def __init__(self) -> None:
  15. self.urls: dict[str, WBURL] = {
  16. "wandb-launch": WBURL(
  17. "https://wandb.me/launch",
  18. "Link to the W&B launch marketing page",
  19. ),
  20. "wandb-init": WBURL(
  21. "https://wandb.me/wandb-init",
  22. "Link to the wandb.init reference documentation page",
  23. ),
  24. "define-metric": WBURL(
  25. "https://wandb.me/define-metric",
  26. "Link to the W&B developer guide documentation page on wandb.define_metric",
  27. ),
  28. "developer-guide": WBURL(
  29. "https://wandb.me/developer-guide",
  30. "Link to the W&B developer guide top level page",
  31. ),
  32. "wandb-core": WBURL(
  33. "https://wandb.me/wandb-core",
  34. "Link to the documentation for the wandb-core service",
  35. ),
  36. "wandb-server": WBURL(
  37. "https://wandb.me/wandb-server",
  38. "Link to the documentation for the self-hosted W&B server",
  39. ),
  40. "multiprocess": WBURL(
  41. "https://wandb.me/multiprocess",
  42. (
  43. "Link to the W&B developer guide documentation page on how to "
  44. "use wandb in a multiprocess environment"
  45. ),
  46. ),
  47. }
  48. def url(self, name: str) -> str:
  49. """Get the URL associated with the given name."""
  50. wb_url = self.urls.get(name)
  51. if wb_url:
  52. return wb_url.url
  53. raise ValueError(f"URL not found for {name}")
  54. def description(self, name: str) -> str:
  55. """Get the description associated with the given name."""
  56. wb_url = self.urls.get(name)
  57. if wb_url:
  58. return wb_url.description
  59. raise ValueError(f"Description not found for {name}")
  60. # This is an instance of the Links class that can be used to access the URLs
  61. url_registry = Registry()