prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Version self check should not warn for post releases
  Post releases are explicitly designed to just fix small errors that won't affect the code itself, things like doc updates. However if we release a post release then the pip version self check will tell everyone to go download it, even though using it isn't really all that important.
  
  Ideally this should just ignore post releases.
  
  
  </issue>
  <code>
  [start of pip/utils/outdated.py]
  1 from __future__ import absolute_import
  2 
  3 import datetime
  4 import json
  5 import logging
  6 import os.path
  7 import sys
  8 
  9 from pip._vendor import lockfile
  10 from pip._vendor import pkg_resources
  11 
  12 from pip.compat import total_seconds
  13 from pip.index import PyPI
  14 from pip.locations import USER_CACHE_DIR, running_under_virtualenv
  15 from pip.utils import ensure_dir
  16 from pip.utils.filesystem import check_path_owner
  17 
  18 
  19 SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"
  20 
  21 
  22 logger = logging.getLogger(__name__)
  23 
  24 
  25 class VirtualenvSelfCheckState(object):
  26     def __init__(self):
  27         self.statefile_path = os.path.join(sys.prefix, "pip-selfcheck.json")
  28 
  29         # Load the existing state
  30         try:
  31             with open(self.statefile_path) as statefile:
  32                 self.state = json.load(statefile)
  33         except (IOError, ValueError):
  34             self.state = {}
  35 
  36     def save(self, pypi_version, current_time):
  37         # Attempt to write out our version check file
  38         with open(self.statefile_path, "w") as statefile:
  39             json.dump(
  40                 {
  41                     "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
  42                     "pypi_version": pypi_version,
  43                 },
  44                 statefile,
  45                 sort_keys=True,
  46                 separators=(",", ":")
  47             )
  48 
  49 
  50 class GlobalSelfCheckState(object):
  51     def __init__(self):
  52         self.statefile_path = os.path.join(USER_CACHE_DIR, "selfcheck.json")
  53 
  54         # Load the existing state
  55         try:
  56             with open(self.statefile_path) as statefile:
  57                 self.state = json.load(statefile)[sys.prefix]
  58         except (IOError, ValueError, KeyError):
  59             self.state = {}
  60 
  61     def save(self, pypi_version, current_time):
  62         # Check to make sure that we own the directory
  63         if not check_path_owner(os.path.dirname(self.statefile_path)):
  64             return
  65 
  66         # Now that we've ensured the directory is owned by this user, we'll go
  67         # ahead and make sure that all our directories are created.
  68         ensure_dir(os.path.dirname(self.statefile_path))
  69 
  70         # Attempt to write out our version check file
  71         with lockfile.LockFile(self.statefile_path):
  72             if os.path.exists(self.statefile_path):
  73                 with open(self.statefile_path) as statefile:
  74                     state = json.load(statefile)
  75             else:
  76                 state = {}
  77 
  78             state[sys.prefix] = {
  79                 "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
  80                 "pypi_version": pypi_version,
  81             }
  82 
  83             with open(self.statefile_path, "w") as statefile:
  84                 json.dump(state, statefile, sort_keys=True,
  85                           separators=(",", ":"))
  86 
  87 
  88 def load_selfcheck_statefile():
  89     if running_under_virtualenv():
  90         return VirtualenvSelfCheckState()
  91     else:
  92         return GlobalSelfCheckState()
  93 
  94 
  95 def pip_version_check(session):
  96     """Check for an update for pip.
  97 
  98     Limit the frequency of checks to once per week. State is stored either in
  99     the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
  100     of the pip script path.
  101     """
  102     import pip  # imported here to prevent circular imports
  103     pypi_version = None
  104 
  105     try:
  106         state = load_selfcheck_statefile()
  107 
  108         current_time = datetime.datetime.utcnow()
  109         # Determine if we need to refresh the state
  110         if "last_check" in state.state and "pypi_version" in state.state:
  111             last_check = datetime.datetime.strptime(
  112                 state.state["last_check"],
  113                 SELFCHECK_DATE_FMT
  114             )
  115             if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
  116                 pypi_version = state.state["pypi_version"]
  117 
  118         # Refresh the version if we need to or just see if we need to warn
  119         if pypi_version is None:
  120             resp = session.get(
  121                 PyPI.pip_json_url,
  122                 headers={"Accept": "application/json"},
  123             )
  124             resp.raise_for_status()
  125             pypi_version = resp.json()["info"]["version"]
  126 
  127             # save that we've performed a check
  128             state.save(pypi_version, current_time)
  129 
  130         pip_version = pkg_resources.parse_version(pip.__version__)
  131 
  132         # Determine if our pypi_version is older
  133         if pip_version < pkg_resources.parse_version(pypi_version):
  134             logger.warning(
  135                 "You are using pip version %s, however version %s is "
  136                 "available.\nYou should consider upgrading via the "
  137                 "'pip install --upgrade pip' command." % (pip.__version__,
  138                                                           pypi_version)
  139             )
  140 
  141     except Exception:
  142         logger.debug(
  143             "There was an error checking the latest version of pip",
  144             exc_info=True,
  145         )
  146
  [end of pip/utils/outdated.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/pip/utils/outdated.py b/pip/utils/outdated.py
  --- a/pip/utils/outdated.py
  +++ b/pip/utils/outdated.py
  @@ -7,7 +7,7 @@
   import sys
   
   from pip._vendor import lockfile
  -from pip._vendor import pkg_resources
  +from pip._vendor.packaging import version as packaging_version
   
   from pip.compat import total_seconds
   from pip.index import PyPI
  @@ -122,15 +122,23 @@
                   headers={"Accept": "application/json"},
               )
               resp.raise_for_status()
  -            pypi_version = resp.json()["info"]["version"]
  +            pypi_version = [
  +                v for v in sorted(
  +                    list(resp.json()["releases"]),
  +                    key=packaging_version.parse,
  +                )
  +                if not packaging_version.parse(v).is_prerelease
  +            ][-1]
   
               # save that we've performed a check
               state.save(pypi_version, current_time)
   
  -        pip_version = pkg_resources.parse_version(pip.__version__)
  +        pip_version = packaging_version.parse(pip.__version__)
  +        remote_version = packaging_version.parse(pypi_version)
   
           # Determine if our pypi_version is older
  -        if pip_version < pkg_resources.parse_version(pypi_version):
  +        if (pip_version < remote_version and
  +                pip_version.base_version != remote_version.base_version):
               logger.warning(
                   "You are using pip version %s, however version %s is "
                   "available.\nYou should consider upgrading via the "
  
verification_info: {"golden_diff": "diff --git a/pip/utils/outdated.py b/pip/utils/outdated.py\n--- a/pip/utils/outdated.py\n+++ b/pip/utils/outdated.py\n@@ -7,7 +7,7 @@\n import sys\n \n from pip._vendor import lockfile\n-from pip._vendor import pkg_resources\n+from pip._vendor.packaging import version as packaging_version\n \n from pip.compat import total_seconds\n from pip.index import PyPI\n@@ -122,15 +122,23 @@\n                 headers={\"Accept\": \"application/json\"},\n             )\n             resp.raise_for_status()\n-            pypi_version = resp.json()[\"info\"][\"version\"]\n+            pypi_version = [\n+                v for v in sorted(\n+                    list(resp.json()[\"releases\"]),\n+                    key=packaging_version.parse,\n+                )\n+                if not packaging_version.parse(v).is_prerelease\n+            ][-1]\n \n             # save that we've performed a check\n             state.save(pypi_version, current_time)\n \n-        pip_version = pkg_resources.parse_version(pip.__version__)\n+        pip_version = packaging_version.parse(pip.__version__)\n+        remote_version = packaging_version.parse(pypi_version)\n \n         # Determine if our pypi_version is older\n-        if pip_version < pkg_resources.parse_version(pypi_version):\n+        if (pip_version < remote_version and\n+                pip_version.base_version != remote_version.base_version):\n             logger.warning(\n                 \"You are using pip version %s, however version %s is \"\n                 \"available.\\nYou should consider upgrading via the \"\n", "issue": "Version self check should not warn for post releases\nPost releases are explicitly designed to just fix small errors that won't affect the code itself, things like doc updates. However if we release a post release then the pip version self check will tell everyone to go download it, even though using it isn't really all that important.\n\nIdeally this should just ignore post releases.\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport datetime\nimport json\nimport logging\nimport os.path\nimport sys\n\nfrom pip._vendor import lockfile\nfrom pip._vendor import pkg_resources\n\nfrom pip.compat import total_seconds\nfrom pip.index import PyPI\nfrom pip.locations import USER_CACHE_DIR, running_under_virtualenv\nfrom pip.utils import ensure_dir\nfrom pip.utils.filesystem import check_path_owner\n\n\nSELFCHECK_DATE_FMT = \"%Y-%m-%dT%H:%M:%SZ\"\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass VirtualenvSelfCheckState(object):\n    def __init__(self):\n        self.statefile_path = os.path.join(sys.prefix, \"pip-selfcheck.json\")\n\n        # Load the existing state\n        try:\n            with open(self.statefile_path) as statefile:\n                self.state = json.load(statefile)\n        except (IOError, ValueError):\n            self.state = {}\n\n    def save(self, pypi_version, current_time):\n        # Attempt to write out our version check file\n        with open(self.statefile_path, \"w\") as statefile:\n            json.dump(\n                {\n                    \"last_check\": current_time.strftime(SELFCHECK_DATE_FMT),\n                    \"pypi_version\": pypi_version,\n                },\n                statefile,\n                sort_keys=True,\n                separators=(\",\", \":\")\n            )\n\n\nclass GlobalSelfCheckState(object):\n    def __init__(self):\n        self.statefile_path = os.path.join(USER_CACHE_DIR, \"selfcheck.json\")\n\n        # Load the existing state\n        try:\n            with open(self.statefile_path) as statefile:\n                self.state = json.load(statefile)[sys.prefix]\n        except (IOError, ValueError, KeyError):\n            self.state = {}\n\n    def save(self, pypi_version, current_time):\n        # Check to make sure that we own the directory\n        if not check_path_owner(os.path.dirname(self.statefile_path)):\n            return\n\n        # Now that we've ensured the directory is owned by this user, we'll go\n        # ahead and make sure that all our directories are created.\n        ensure_dir(os.path.dirname(self.statefile_path))\n\n        # Attempt to write out our version check file\n        with lockfile.LockFile(self.statefile_path):\n            if os.path.exists(self.statefile_path):\n                with open(self.statefile_path) as statefile:\n                    state = json.load(statefile)\n            else:\n                state = {}\n\n            state[sys.prefix] = {\n                \"last_check\": current_time.strftime(SELFCHECK_DATE_FMT),\n                \"pypi_version\": pypi_version,\n            }\n\n            with open(self.statefile_path, \"w\") as statefile:\n                json.dump(state, statefile, sort_keys=True,\n                          separators=(\",\", \":\"))\n\n\ndef load_selfcheck_statefile():\n    if running_under_virtualenv():\n        return VirtualenvSelfCheckState()\n    else:\n        return GlobalSelfCheckState()\n\n\ndef pip_version_check(session):\n    \"\"\"Check for an update for pip.\n\n    Limit the frequency of checks to once per week. State is stored either in\n    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix\n    of the pip script path.\n    \"\"\"\n    import pip  # imported here to prevent circular imports\n    pypi_version = None\n\n    try:\n        state = load_selfcheck_statefile()\n\n        current_time = datetime.datetime.utcnow()\n        # Determine if we need to refresh the state\n        if \"last_check\" in state.state and \"pypi_version\" in state.state:\n            last_check = datetime.datetime.strptime(\n                state.state[\"last_check\"],\n                SELFCHECK_DATE_FMT\n            )\n            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:\n                pypi_version = state.state[\"pypi_version\"]\n\n        # Refresh the version if we need to or just see if we need to warn\n        if pypi_version is None:\n            resp = session.get(\n                PyPI.pip_json_url,\n                headers={\"Accept\": \"application/json\"},\n            )\n            resp.raise_for_status()\n            pypi_version = resp.json()[\"info\"][\"version\"]\n\n            # save that we've performed a check\n            state.save(pypi_version, current_time)\n\n        pip_version = pkg_resources.parse_version(pip.__version__)\n\n        # Determine if our pypi_version is older\n        if pip_version < pkg_resources.parse_version(pypi_version):\n            logger.warning(\n                \"You are using pip version %s, however version %s is \"\n                \"available.\\nYou should consider upgrading via the \"\n                \"'pip install --upgrade pip' command.\" % (pip.__version__,\n                                                          pypi_version)\n            )\n\n    except Exception:\n        logger.debug(\n            \"There was an error checking the latest version of pip\",\n            exc_info=True,\n        )\n", "path": "pip/utils/outdated.py"}]}