prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  pip 21.0.1 fails when run with warnings converted to errors
  **Environment**
  
  * pip version: 21.0.1
  * Python version: 3.9.1
  * OS: Windows
  
  **Description**
  With the latest version of packaging (vendored in 21.0.1) a DeprecationWarning is issued when parsing a "legacy version". If pip is run with warnings converted to errors, this causes a failure.
  
  **Expected behavior**
  No error
  
  **How to Reproduce**
  `py -wE -m pip --version`
  
  Or to pinpoint it further,
  
  ```
  py -wE
  >>> from pip._vendor import pkg_resources
  ```
  
  This does *not* happen with setuptools 52.0.0, it appears to be related to the version of setuptools (44.0.0) that we vendor.
  
  **Output**
  
  ```
  Traceback (most recent call last):
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\packaging\version.py", line 57, in parse
      return Version(version)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\packaging\version.py", line 298, in __init__
      raise InvalidVersion("Invalid version: '{0}'".format(version))
  pip._vendor.packaging.version.InvalidVersion: Invalid version: 'pip'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3252, in <module>
      def _initialize_master_working_set():
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3235, in _call_aside
      f(*args, **kwargs)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3264, in _initialize_master_working_set
      working_set = WorkingSet._build_master()
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 574, in _build_master
      ws = cls()
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 567, in __init__
      self.add_entry(entry)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 623, in add_entry
      for dist in find_distributions(entry, True):
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2061, in find_on_path
      path_item_entries = _by_version_descending(filtered)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2034, in _by_version_descending
      return sorted(names, key=_by_version, reverse=True)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2032, in _by_version
      return [packaging.version.parse(part) for part in parts]
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2032, in <listcomp>
      return [packaging.version.parse(part) for part in parts]
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\packaging\version.py", line 59, in parse
      return LegacyVersion(version)
    File "C:\Users\Gustav\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\packaging\version.py", line 127, in __init__
      warnings.warn(
  DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
  ```
  
  
  </issue>
  <code>
  [start of src/pip/__main__.py]
  1 import os
  2 import sys
  3 
  4 # Remove '' and current working directory from the first entry
  5 # of sys.path, if present to avoid using current directory
  6 # in pip commands check, freeze, install, list and show,
  7 # when invoked as python -m pip <command>
  8 if sys.path[0] in ("", os.getcwd()):
  9     sys.path.pop(0)
  10 
  11 # If we are running from a wheel, add the wheel to sys.path
  12 # This allows the usage python pip-*.whl/pip install pip-*.whl
  13 if __package__ == "":
  14     # __file__ is pip-*.whl/pip/__main__.py
  15     # first dirname call strips of '/__main__.py', second strips off '/pip'
  16     # Resulting path is the name of the wheel itself
  17     # Add that to sys.path so we can import pip
  18     path = os.path.dirname(os.path.dirname(__file__))
  19     sys.path.insert(0, path)
  20 
  21 from pip._internal.cli.main import main as _main
  22 
  23 if __name__ == "__main__":
  24     sys.exit(_main())
  25
  [end of src/pip/__main__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/pip/__main__.py b/src/pip/__main__.py
  --- a/src/pip/__main__.py
  +++ b/src/pip/__main__.py
  @@ -1,5 +1,6 @@
   import os
   import sys
  +import warnings
   
   # Remove '' and current working directory from the first entry
   # of sys.path, if present to avoid using current directory
  @@ -18,7 +19,13 @@
       path = os.path.dirname(os.path.dirname(__file__))
       sys.path.insert(0, path)
   
  -from pip._internal.cli.main import main as _main
  -
   if __name__ == "__main__":
  +    # Work around the error reported in #9540, pending a proper fix.
  +    # Note: It is essential the warning filter is set *before* importing
  +    #       pip, as the deprecation happens at import time, not runtime.
  +    warnings.filterwarnings(
  +        "ignore", category=DeprecationWarning, module=".*packaging\\.version"
  +    )
  +    from pip._internal.cli.main import main as _main
  +
       sys.exit(_main())
  
verification_info: {"golden_diff": "diff --git a/src/pip/__main__.py b/src/pip/__main__.py\n--- a/src/pip/__main__.py\n+++ b/src/pip/__main__.py\n@@ -1,5 +1,6 @@\n import os\n import sys\n+import warnings\n \n # Remove '' and current working directory from the first entry\n # of sys.path, if present to avoid using current directory\n@@ -18,7 +19,13 @@\n     path = os.path.dirname(os.path.dirname(__file__))\n     sys.path.insert(0, path)\n \n-from pip._internal.cli.main import main as _main\n-\n if __name__ == \"__main__\":\n+    # Work around the error reported in #9540, pending a proper fix.\n+    # Note: It is essential the warning filter is set *before* importing\n+    #       pip, as the deprecation happens at import time, not runtime.\n+    warnings.filterwarnings(\n+        \"ignore\", category=DeprecationWarning, module=\".*packaging\\\\.version\"\n+    )\n+    from pip._internal.cli.main import main as _main\n+\n     sys.exit(_main())\n", "issue": "pip 21.0.1 fails when run with warnings converted to errors\n**Environment**\r\n\r\n* pip version: 21.0.1\r\n* Python version: 3.9.1\r\n* OS: Windows\r\n\r\n**Description**\r\nWith the latest version of packaging (vendored in 21.0.1) a DeprecationWarning is issued when parsing a \"legacy version\". If pip is run with warnings converted to errors, this causes a failure.\r\n\r\n**Expected behavior**\r\nNo error\r\n\r\n**How to Reproduce**\r\n`py -wE -m pip --version`\r\n\r\nOr to pinpoint it further,\r\n\r\n```\r\npy -wE\r\n>>> from pip._vendor import pkg_resources\r\n```\r\n\r\nThis does *not* happen with setuptools 52.0.0, it appears to be related to the version of setuptools (44.0.0) that we vendor.\r\n\r\n**Output**\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\packaging\\version.py\", line 57, in parse\r\n    return Version(version)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\packaging\\version.py\", line 298, in __init__\r\n    raise InvalidVersion(\"Invalid version: '{0}'\".format(version))\r\npip._vendor.packaging.version.InvalidVersion: Invalid version: 'pip'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 3252, in <module>\r\n    def _initialize_master_working_set():\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 3235, in _call_aside\r\n    f(*args, **kwargs)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 3264, in _initialize_master_working_set\r\n    working_set = WorkingSet._build_master()\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 574, in _build_master\r\n    ws = cls()\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 567, in __init__\r\n    self.add_entry(entry)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 623, in add_entry\r\n    for dist in find_distributions(entry, True):\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 2061, in find_on_path\r\n    path_item_entries = _by_version_descending(filtered)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 2034, in _by_version_descending\r\n    return sorted(names, key=_by_version, reverse=True)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 2032, in _by_version\r\n    return [packaging.version.parse(part) for part in parts]\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py\", line 2032, in <listcomp>\r\n    return [packaging.version.parse(part) for part in parts]\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\packaging\\version.py\", line 59, in parse\r\n    return LegacyVersion(version)\r\n  File \"C:\\Users\\Gustav\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pip\\_vendor\\packaging\\version.py\", line 127, in __init__\r\n    warnings.warn(\r\nDeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release\r\n```\r\n\n", "before_files": [{"content": "import os\nimport sys\n\n# Remove '' and current working directory from the first entry\n# of sys.path, if present to avoid using current directory\n# in pip commands check, freeze, install, list and show,\n# when invoked as python -m pip <command>\nif sys.path[0] in (\"\", os.getcwd()):\n    sys.path.pop(0)\n\n# If we are running from a wheel, add the wheel to sys.path\n# This allows the usage python pip-*.whl/pip install pip-*.whl\nif __package__ == \"\":\n    # __file__ is pip-*.whl/pip/__main__.py\n    # first dirname call strips of '/__main__.py', second strips off '/pip'\n    # Resulting path is the name of the wheel itself\n    # Add that to sys.path so we can import pip\n    path = os.path.dirname(os.path.dirname(__file__))\n    sys.path.insert(0, path)\n\nfrom pip._internal.cli.main import main as _main\n\nif __name__ == \"__main__\":\n    sys.exit(_main())\n", "path": "src/pip/__main__.py"}]}