class_docstr: Parse a requirement.
  
  Parse a given requirement string into its parts, such as name, specifier,
  URL, and extras. Raises InvalidRequirement on a badly-formed requirement
  string.
class_docstr_tok: ["Parse","a","requirement",".","Parse","a","given","requirement","string","into","its","parts",",","such","as","name",",","specifier",",","URL",",","and","extras",".","Raises","InvalidRequirement","on","a","badly-formed","requirement","string","."]
code: def __init__(self, requirement_string: str) -> None:
      try:
          parsed = parse_requirement(requirement_string)
      except ParserSyntaxError as e:
          raise InvalidRequirement(str(e)) from e
  
      self.name: str = parsed.name
      if parsed.url:
          parsed_url = urllib.parse.urlparse(parsed.url)
          if parsed_url.scheme == "file":
              if urllib.parse.urlunparse(parsed_url) != parsed.url:
                  raise InvalidRequirement("Invalid URL given")
          elif not (parsed_url.scheme and parsed_url.netloc) or (
              not parsed_url.scheme and not parsed_url.netloc
          ):
              raise InvalidRequirement(f"Invalid URL: {parsed.url}")
          self.url: Optional[str] = parsed.url
      else:
          self.url = None
      self.extras: Set[str] = set(
          parsed.extras if parsed.extras else []
      )
      self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
      self.marker: Optional[Marker] = None
      if parsed.marker is not None:
          self.marker = Marker.__new__(Marker)
          self.marker._markers = _normalize_extra_values(parsed.marker)
  
file_path: metaflow/metaflow/_vendor/packaging/requirements.py
imports: import urllib.parse
  from typing import Any, List, Optional, Set
  from ._parser import parse_requirement
  from ._tokenizer import ParserSyntaxError
  from .markers import Marker, _normalize_extra_values
  from .specifiers import SpecifierSet
label_desc: Use image node_id 1 to create a new Requirement object  with example: obj = Requirement(requirement_string)