docstr: Attempt to parse a string as a W&B URL.
docstr_tok: ["Attempt","to","parse","a","string","as","a","W","&","B","URL","."]
code: def parse(uri: str) -> Optional["WandbReference"]:
      """Attempt to parse a string as a W&B URL."""
      # TODO: Error if HTTP and host is not localhost?
      if (
          not uri.startswith("/")
          and not uri.startswith(PREFIX_HTTP)
          and not uri.startswith(PREFIX_HTTPS)
      ):
          return None
  
      ref = WandbReference()
  
      # This takes care of things like query and fragment
      parsed = urlparse(uri)
      if parsed.netloc:
          ref.host = parsed.netloc
  
      if not parsed.path.startswith("/"):
          return ref
  
      ref.path = parsed.path[1:]
      parts = ref.path.split("/")
      if len(parts) > 0:
          if parts[0] not in RESERVED_NON_ENTITIES:
              ref.path = None
              ref.entity = parts[0]
              if len(parts) > 1:
                  if parts[1] not in RESERVED_NON_PROJECTS:
                      ref.project = parts[1]
                      if len(parts) > 3 and parts[2] == "runs":
                          ref.ref_type = ReferenceType.RUN
                          ref.run_id = parts[3]
                      elif (
                          len(parts) > 4
                          and parts[2] == "artifacts"
                          and parts[3] == "job"
                      ):
                          ref.ref_type = ReferenceType.JOB
                          ref.job_name = parts[4]
                          if (
                              len(parts) > 5
                              and parts[5] not in RESERVED_JOB_PATHS
                          ):
                              ref.job_alias = parts[5]
                      # TODO: Right now we are not tracking selection as part of URL state in the Jobs tab.
                      #       If that changes we'll want to update this.
  
      return ref
  
file_path: wandb/wandb/sdk/launch/wandb_reference.py
imports: from dataclasses import dataclass
  from enum import IntEnum
  from typing import Optional
  from urllib.parse import urlparse
label_desc: Use image node_id 10 for calling the WandbReference obj's underlying member method code with example usage: obj.parse(uri) and returns: ref, None, ref