We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Replace overly specific function definition with more general alternative
In `outdated.py`, there is a function definition for `was_installed_by_pip` which can be simplified (or gotten rid of), by using `get_installer` defined in another file.

https://github.com/pypa/pip/blob/ba539093754bc96dcdb7f4a48911deffcbcc8725/src/pip/_internal/utils/outdated.py#L79

https://github.com/pypa/pip/blob/ba539093754bc96dcdb7f4a48911deffcbcc8725/src/pip/_internal/utils/packaging.py#L86


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/pip/_internal/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, pkg_resources
10 from pip._vendor.packaging import version as packaging_version
11 
12 from pip._internal.index import PackageFinder
13 from pip._internal.utils.compat import WINDOWS
14 from pip._internal.utils.filesystem import check_path_owner
15 from pip._internal.utils.misc import ensure_dir, get_installed_version
16 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
17 
18 if MYPY_CHECK_RUNNING:
19     import optparse
20     from typing import Any, Dict
21     from pip._internal.download import PipSession
22 
23 
24 SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"
25 
26 
27 logger = logging.getLogger(__name__)
28 
29 
30 class SelfCheckState(object):
31     def __init__(self, cache_dir):
32         # type: (str) -> None
33         self.state = {}  # type: Dict[str, Any]
34         self.statefile_path = None
35 
36         # Try to load the existing state
37         if cache_dir:
38             self.statefile_path = os.path.join(cache_dir, "selfcheck.json")
39             try:
40                 with open(self.statefile_path) as statefile:
41                     self.state = json.load(statefile)[sys.prefix]
42             except (IOError, ValueError, KeyError):
43                 # Explicitly suppressing exceptions, since we don't want to
44                 # error out if the cache file is invalid.
45                 pass
46 
47     def save(self, pypi_version, current_time):
48         # type: (str, datetime.datetime) -> None
49         # If we do not have a path to cache in, don't bother saving.
50         if not self.statefile_path:
51             return
52 
53         # Check to make sure that we own the directory
54         if not check_path_owner(os.path.dirname(self.statefile_path)):
55             return
56 
57         # Now that we've ensured the directory is owned by this user, we'll go
58         # ahead and make sure that all our directories are created.
59         ensure_dir(os.path.dirname(self.statefile_path))
60 
61         # Attempt to write out our version check file
62         with lockfile.LockFile(self.statefile_path):
63             if os.path.exists(self.statefile_path):
64                 with open(self.statefile_path) as statefile:
65                     state = json.load(statefile)
66             else:
67                 state = {}
68 
69             state[sys.prefix] = {
70                 "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
71                 "pypi_version": pypi_version,
72             }
73 
74             with open(self.statefile_path, "w") as statefile:
75                 json.dump(state, statefile, sort_keys=True,
76                           separators=(",", ":"))
77 
78 
79 def was_installed_by_pip(pkg):
80     # type: (str) -> bool
81     """Checks whether pkg was installed by pip
82 
83     This is used not to display the upgrade message when pip is in fact
84     installed by system package manager, such as dnf on Fedora.
85     """
86     try:
87         dist = pkg_resources.get_distribution(pkg)
88         return (dist.has_metadata('INSTALLER') and
89                 'pip' in dist.get_metadata_lines('INSTALLER'))
90     except pkg_resources.DistributionNotFound:
91         return False
92 
93 
94 def pip_version_check(session, options):
95     # type: (PipSession, optparse.Values) -> None
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     installed_version = get_installed_version("pip")
103     if not installed_version:
104         return
105 
106     pip_version = packaging_version.parse(installed_version)
107     pypi_version = None
108 
109     try:
110         state = SelfCheckState(cache_dir=options.cache_dir)
111 
112         current_time = datetime.datetime.utcnow()
113         # Determine if we need to refresh the state
114         if "last_check" in state.state and "pypi_version" in state.state:
115             last_check = datetime.datetime.strptime(
116                 state.state["last_check"],
117                 SELFCHECK_DATE_FMT
118             )
119             if (current_time - last_check).total_seconds() < 7 * 24 * 60 * 60:
120                 pypi_version = state.state["pypi_version"]
121 
122         # Refresh the version if we need to or just see if we need to warn
123         if pypi_version is None:
124             # Lets use PackageFinder to see what the latest pip version is
125             finder = PackageFinder.create(
126                 find_links=options.find_links,
127                 index_urls=[options.index_url] + options.extra_index_urls,
128                 allow_all_prereleases=False,  # Explicitly set to False
129                 trusted_hosts=options.trusted_hosts,
130                 session=session,
131             )
132             candidate = finder.find_candidates("pip").get_best()
133             if candidate is None:
134                 return
135             pypi_version = str(candidate.version)
136 
137             # save that we've performed a check
138             state.save(pypi_version, current_time)
139 
140         remote_version = packaging_version.parse(pypi_version)
141 
142         local_version_is_older = (
143             pip_version < remote_version and
144             pip_version.base_version != remote_version.base_version and
145             was_installed_by_pip('pip')
146         )
147 
148         # Determine if our pypi_version is older
149         if not local_version_is_older:
150             return
151 
152         # Advise "python -m pip" on Windows to avoid issues
153         # with overwriting pip.exe.
154         if WINDOWS:
155             pip_cmd = "python -m pip"
156         else:
157             pip_cmd = "pip"
158         logger.warning(
159             "You are using pip version %s, however version %s is "
160             "available.\nYou should consider upgrading via the "
161             "'%s install --upgrade pip' command.",
162             pip_version, pypi_version, pip_cmd
163         )
164     except Exception:
165         logger.debug(
166             "There was an error checking the latest version of pip",
167             exc_info=True,
168         )
169
```
--- 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/src/pip/_internal/utils/outdated.py b/src/pip/_internal/utils/outdated.py
--- a/src/pip/_internal/utils/outdated.py
+++ b/src/pip/_internal/utils/outdated.py
@@ -13,6 +13,7 @@
 from pip._internal.utils.compat import WINDOWS
 from pip._internal.utils.filesystem import check_path_owner
 from pip._internal.utils.misc import ensure_dir, get_installed_version
+from pip._internal.utils.packaging import get_installer
 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
 
 if MYPY_CHECK_RUNNING:
@@ -85,8 +86,7 @@
     """
     try:
         dist = pkg_resources.get_distribution(pkg)
-        return (dist.has_metadata('INSTALLER') and
-                'pip' in dist.get_metadata_lines('INSTALLER'))
+        return "pip" == get_installer(dist)
     except pkg_resources.DistributionNotFound:
         return False

{"golden_diff": "diff --git a/src/pip/_internal/utils/outdated.py b/src/pip/_internal/utils/outdated.py\n--- a/src/pip/_internal/utils/outdated.py\n+++ b/src/pip/_internal/utils/outdated.py\n@@ -13,6 +13,7 @@\n from pip._internal.utils.compat import WINDOWS\n from pip._internal.utils.filesystem import check_path_owner\n from pip._internal.utils.misc import ensure_dir, get_installed_version\n+from pip._internal.utils.packaging import get_installer\n from pip._internal.utils.typing import MYPY_CHECK_RUNNING\n \n if MYPY_CHECK_RUNNING:\n@@ -85,8 +86,7 @@\n     \"\"\"\n     try:\n         dist = pkg_resources.get_distribution(pkg)\n-        return (dist.has_metadata('INSTALLER') and\n-                'pip' in dist.get_metadata_lines('INSTALLER'))\n+        return \"pip\" == get_installer(dist)\n     except pkg_resources.DistributionNotFound:\n         return False\n", "issue": "Replace overly specific function definition with more general alternative\nIn `outdated.py`, there is a function definition for `was_installed_by_pip` which can be simplified (or gotten rid of), by using `get_installer` defined in another file.\r\n\r\nhttps://github.com/pypa/pip/blob/ba539093754bc96dcdb7f4a48911deffcbcc8725/src/pip/_internal/utils/outdated.py#L79\r\n\r\nhttps://github.com/pypa/pip/blob/ba539093754bc96dcdb7f4a48911deffcbcc8725/src/pip/_internal/utils/packaging.py#L86\r\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, pkg_resources\nfrom pip._vendor.packaging import version as packaging_version\n\nfrom pip._internal.index import PackageFinder\nfrom pip._internal.utils.compat import WINDOWS\nfrom pip._internal.utils.filesystem import check_path_owner\nfrom pip._internal.utils.misc import ensure_dir, get_installed_version\nfrom pip._internal.utils.typing import MYPY_CHECK_RUNNING\n\nif MYPY_CHECK_RUNNING:\n    import optparse\n    from typing import Any, Dict\n    from pip._internal.download import PipSession\n\n\nSELFCHECK_DATE_FMT = \"%Y-%m-%dT%H:%M:%SZ\"\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass SelfCheckState(object):\n    def __init__(self, cache_dir):\n        # type: (str) -> None\n        self.state = {}  # type: Dict[str, Any]\n        self.statefile_path = None\n\n        # Try to load the existing state\n        if cache_dir:\n            self.statefile_path = os.path.join(cache_dir, \"selfcheck.json\")\n            try:\n                with open(self.statefile_path) as statefile:\n                    self.state = json.load(statefile)[sys.prefix]\n            except (IOError, ValueError, KeyError):\n                # Explicitly suppressing exceptions, since we don't want to\n                # error out if the cache file is invalid.\n                pass\n\n    def save(self, pypi_version, current_time):\n        # type: (str, datetime.datetime) -> None\n        # If we do not have a path to cache in, don't bother saving.\n        if not self.statefile_path:\n            return\n\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 was_installed_by_pip(pkg):\n    # type: (str) -> bool\n    \"\"\"Checks whether pkg was installed by pip\n\n    This is used not to display the upgrade message when pip is in fact\n    installed by system package manager, such as dnf on Fedora.\n    \"\"\"\n    try:\n        dist = pkg_resources.get_distribution(pkg)\n        return (dist.has_metadata('INSTALLER') and\n                'pip' in dist.get_metadata_lines('INSTALLER'))\n    except pkg_resources.DistributionNotFound:\n        return False\n\n\ndef pip_version_check(session, options):\n    # type: (PipSession, optparse.Values) -> None\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    installed_version = get_installed_version(\"pip\")\n    if not installed_version:\n        return\n\n    pip_version = packaging_version.parse(installed_version)\n    pypi_version = None\n\n    try:\n        state = SelfCheckState(cache_dir=options.cache_dir)\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 (current_time - last_check).total_seconds() < 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            # Lets use PackageFinder to see what the latest pip version is\n            finder = PackageFinder.create(\n                find_links=options.find_links,\n                index_urls=[options.index_url] + options.extra_index_urls,\n                allow_all_prereleases=False,  # Explicitly set to False\n                trusted_hosts=options.trusted_hosts,\n                session=session,\n            )\n            candidate = finder.find_candidates(\"pip\").get_best()\n            if candidate is None:\n                return\n            pypi_version = str(candidate.version)\n\n            # save that we've performed a check\n            state.save(pypi_version, current_time)\n\n        remote_version = packaging_version.parse(pypi_version)\n\n        local_version_is_older = (\n            pip_version < remote_version and\n            pip_version.base_version != remote_version.base_version and\n            was_installed_by_pip('pip')\n        )\n\n        # Determine if our pypi_version is older\n        if not local_version_is_older:\n            return\n\n        # Advise \"python -m pip\" on Windows to avoid issues\n        # with overwriting pip.exe.\n        if WINDOWS:\n            pip_cmd = \"python -m pip\"\n        else:\n            pip_cmd = \"pip\"\n        logger.warning(\n            \"You are using pip version %s, however version %s is \"\n            \"available.\\nYou should consider upgrading via the \"\n            \"'%s install --upgrade pip' command.\",\n            pip_version, pypi_version, pip_cmd\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": "src/pip/_internal/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, pkg_resources\nfrom pip._vendor.packaging import version as packaging_version\n\nfrom pip._internal.index import PackageFinder\nfrom pip._internal.utils.compat import WINDOWS\nfrom pip._internal.utils.filesystem import check_path_owner\nfrom pip._internal.utils.misc import ensure_dir, get_installed_version\nfrom pip._internal.utils.packaging import get_installer\nfrom pip._internal.utils.typing import MYPY_CHECK_RUNNING\n\nif MYPY_CHECK_RUNNING:\n    import optparse\n    from typing import Any, Dict\n    from pip._internal.download import PipSession\n\n\nSELFCHECK_DATE_FMT = \"%Y-%m-%dT%H:%M:%SZ\"\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass SelfCheckState(object):\n    def __init__(self, cache_dir):\n        # type: (str) -> None\n        self.state = {}  # type: Dict[str, Any]\n        self.statefile_path = None\n\n        # Try to load the existing state\n        if cache_dir:\n            self.statefile_path = os.path.join(cache_dir, \"selfcheck.json\")\n            try:\n                with open(self.statefile_path) as statefile:\n                    self.state = json.load(statefile)[sys.prefix]\n            except (IOError, ValueError, KeyError):\n                # Explicitly suppressing exceptions, since we don't want to\n                # error out if the cache file is invalid.\n                pass\n\n    def save(self, pypi_version, current_time):\n        # type: (str, datetime.datetime) -> None\n        # If we do not have a path to cache in, don't bother saving.\n        if not self.statefile_path:\n            return\n\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 was_installed_by_pip(pkg):\n    # type: (str) -> bool\n    \"\"\"Checks whether pkg was installed by pip\n\n    This is used not to display the upgrade message when pip is in fact\n    installed by system package manager, such as dnf on Fedora.\n    \"\"\"\n    try:\n        dist = pkg_resources.get_distribution(pkg)\n        return \"pip\" == get_installer(dist)\n    except pkg_resources.DistributionNotFound:\n        return False\n\n\ndef pip_version_check(session, options):\n    # type: (PipSession, optparse.Values) -> None\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    installed_version = get_installed_version(\"pip\")\n    if not installed_version:\n        return\n\n    pip_version = packaging_version.parse(installed_version)\n    pypi_version = None\n\n    try:\n        state = SelfCheckState(cache_dir=options.cache_dir)\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 (current_time - last_check).total_seconds() < 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            # Lets use PackageFinder to see what the latest pip version is\n            finder = PackageFinder.create(\n                find_links=options.find_links,\n                index_urls=[options.index_url] + options.extra_index_urls,\n                allow_all_prereleases=False,  # Explicitly set to False\n                trusted_hosts=options.trusted_hosts,\n                session=session,\n            )\n            candidate = finder.find_candidates(\"pip\").get_best()\n            if candidate is None:\n                return\n            pypi_version = str(candidate.version)\n\n            # save that we've performed a check\n            state.save(pypi_version, current_time)\n\n        remote_version = packaging_version.parse(pypi_version)\n\n        local_version_is_older = (\n            pip_version < remote_version and\n            pip_version.base_version != remote_version.base_version and\n            was_installed_by_pip('pip')\n        )\n\n        # Determine if our pypi_version is older\n        if not local_version_is_older:\n            return\n\n        # Advise \"python -m pip\" on Windows to avoid issues\n        # with overwriting pip.exe.\n        if WINDOWS:\n            pip_cmd = \"python -m pip\"\n        else:\n            pip_cmd = \"pip\"\n        logger.warning(\n            \"You are using pip version %s, however version %s is \"\n            \"available.\\nYou should consider upgrading via the \"\n            \"'%s install --upgrade pip' command.\",\n            pip_version, pypi_version, pip_cmd\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": "src/pip/_internal/utils/outdated.py"}]}