We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pip/utils/outdated.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 "

{"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"}], "after_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.packaging import version as packaging_version\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 = [\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 = 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 < 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                \"'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"}]}