We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pip freeze reports doubles in requirements files as "not installed"
* Pip version: 9.0.1
* Python version: all
* Operating system: all

### Description:
If a package is listed twice in a single requirements file, or once in two or more requirements files, then 'pip freeze -r requirements.txt' erroneously reports that the package isn't installed.


### What I've run:

```
pip install simplejson

cat <<EOF > requirements.txt
simplejson
simplejson
EOF

pip freeze -r requirements.txt
simplejson==3.10.0
Requirement file [requirements.txt] contains simplejson, but that package is not installed
## The following requirements were added by pip freeze:
```

Similarly, pip freeze now supports multiple '-r' options, and if the same package appears in more than one of the requirements files, then the same message about the package not being installed is displayed.

--- 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/operations/freeze.py`
Content:
```
1 from __future__ import absolute_import
2 
3 import logging
4 import os
5 import re
6 import warnings
7 
8 from pip._vendor import pkg_resources
9 from pip._vendor.packaging.utils import canonicalize_name
10 from pip._vendor.pkg_resources import RequirementParseError
11 
12 from pip._internal.exceptions import InstallationError
13 from pip._internal.req import InstallRequirement
14 from pip._internal.req.req_file import COMMENT_RE
15 from pip._internal.utils.deprecation import RemovedInPip11Warning
16 from pip._internal.utils.misc import (
17     dist_is_editable, get_installed_distributions
18 )
19 
20 logger = logging.getLogger(__name__)
21 
22 
23 def freeze(
24         requirement=None,
25         find_links=None, local_only=None, user_only=None, skip_regex=None,
26         isolated=False,
27         wheel_cache=None,
28         exclude_editable=False,
29         skip=()):
30     find_links = find_links or []
31     skip_match = None
32 
33     if skip_regex:
34         skip_match = re.compile(skip_regex).search
35 
36     dependency_links = []
37 
38     for dist in pkg_resources.working_set:
39         if dist.has_metadata('dependency_links.txt'):
40             dependency_links.extend(
41                 dist.get_metadata_lines('dependency_links.txt')
42             )
43     for link in find_links:
44         if '#egg=' in link:
45             dependency_links.append(link)
46     for link in find_links:
47         yield '-f %s' % link
48     installations = {}
49     for dist in get_installed_distributions(local_only=local_only,
50                                             skip=(),
51                                             user_only=user_only):
52         try:
53             req = FrozenRequirement.from_dist(
54                 dist,
55                 dependency_links
56             )
57         except RequirementParseError:
58             logger.warning(
59                 "Could not parse requirement: %s",
60                 dist.project_name
61             )
62             continue
63         if exclude_editable and req.editable:
64             continue
65         installations[req.name] = req
66 
67     if requirement:
68         # the options that don't get turned into an InstallRequirement
69         # should only be emitted once, even if the same option is in multiple
70         # requirements files, so we need to keep track of what has been emitted
71         # so that we don't emit it again if it's seen again
72         emitted_options = set()
73         for req_file_path in requirement:
74             with open(req_file_path) as req_file:
75                 for line in req_file:
76                     if (not line.strip() or
77                             line.strip().startswith('#') or
78                             (skip_match and skip_match(line)) or
79                             line.startswith((
80                                 '-r', '--requirement',
81                                 '-Z', '--always-unzip',
82                                 '-f', '--find-links',
83                                 '-i', '--index-url',
84                                 '--pre',
85                                 '--trusted-host',
86                                 '--process-dependency-links',
87                                 '--extra-index-url'))):
88                         line = line.rstrip()
89                         if line not in emitted_options:
90                             emitted_options.add(line)
91                             yield line
92                         continue
93 
94                     if line.startswith('-e') or line.startswith('--editable'):
95                         if line.startswith('-e'):
96                             line = line[2:].strip()
97                         else:
98                             line = line[len('--editable'):].strip().lstrip('=')
99                         line_req = InstallRequirement.from_editable(
100                             line,
101                             isolated=isolated,
102                             wheel_cache=wheel_cache,
103                         )
104                     else:
105                         line_req = InstallRequirement.from_line(
106                             COMMENT_RE.sub('', line).strip(),
107                             isolated=isolated,
108                             wheel_cache=wheel_cache,
109                         )
110 
111                     if not line_req.name:
112                         logger.info(
113                             "Skipping line in requirement file [%s] because "
114                             "it's not clear what it would install: %s",
115                             req_file_path, line.strip(),
116                         )
117                         logger.info(
118                             "  (add #egg=PackageName to the URL to avoid"
119                             " this warning)"
120                         )
121                     elif line_req.name not in installations:
122                         logger.warning(
123                             "Requirement file [%s] contains %s, but that "
124                             "package is not installed",
125                             req_file_path, COMMENT_RE.sub('', line).strip(),
126                         )
127                     else:
128                         yield str(installations[line_req.name]).rstrip()
129                         del installations[line_req.name]
130 
131         yield(
132             '## The following requirements were added by '
133             'pip freeze:'
134         )
135     for installation in sorted(
136             installations.values(), key=lambda x: x.name.lower()):
137         if canonicalize_name(installation.name) not in skip:
138             yield str(installation).rstrip()
139 
140 
141 class FrozenRequirement(object):
142     def __init__(self, name, req, editable, comments=()):
143         self.name = name
144         self.req = req
145         self.editable = editable
146         self.comments = comments
147 
148     _rev_re = re.compile(r'-r(\d+)$')
149     _date_re = re.compile(r'-(20\d\d\d\d\d\d)$')
150 
151     @classmethod
152     def from_dist(cls, dist, dependency_links):
153         location = os.path.normcase(os.path.abspath(dist.location))
154         comments = []
155         from pip._internal.vcs import vcs, get_src_requirement
156         if dist_is_editable(dist) and vcs.get_backend_name(location):
157             editable = True
158             try:
159                 req = get_src_requirement(dist, location)
160             except InstallationError as exc:
161                 logger.warning(
162                     "Error when trying to get requirement for VCS system %s, "
163                     "falling back to uneditable format", exc
164                 )
165                 req = None
166             if req is None:
167                 logger.warning(
168                     'Could not determine repository location of %s', location
169                 )
170                 comments.append(
171                     '## !! Could not determine repository location'
172                 )
173                 req = dist.as_requirement()
174                 editable = False
175         else:
176             editable = False
177             req = dist.as_requirement()
178             specs = req.specs
179             assert len(specs) == 1 and specs[0][0] in ["==", "==="], \
180                 'Expected 1 spec with == or ===; specs = %r; dist = %r' % \
181                 (specs, dist)
182             version = specs[0][1]
183             ver_match = cls._rev_re.search(version)
184             date_match = cls._date_re.search(version)
185             if ver_match or date_match:
186                 svn_backend = vcs.get_backend('svn')
187                 if svn_backend:
188                     svn_location = svn_backend().get_location(
189                         dist,
190                         dependency_links,
191                     )
192                 if not svn_location:
193                     logger.warning(
194                         'Warning: cannot find svn location for %s', req)
195                     comments.append(
196                         '## FIXME: could not find svn URL in dependency_links '
197                         'for this package:'
198                     )
199                 else:
200                     warnings.warn(
201                         "SVN editable detection based on dependency links "
202                         "will be dropped in the future.",
203                         RemovedInPip11Warning,
204                     )
205                     comments.append(
206                         '# Installing as editable to satisfy requirement %s:' %
207                         req
208                     )
209                     if ver_match:
210                         rev = ver_match.group(1)
211                     else:
212                         rev = '{%s}' % date_match.group(1)
213                     editable = True
214                     req = '%s@%s#egg=%s' % (
215                         svn_location,
216                         rev,
217                         cls.egg_name(dist)
218                     )
219         return cls(dist.project_name, req, editable, comments)
220 
221     @staticmethod
222     def egg_name(dist):
223         name = dist.egg_name()
224         match = re.search(r'-py\d\.\d$', name)
225         if match:
226             name = name[:match.start()]
227         return name
228 
229     def __str__(self):
230         req = self.req
231         if self.editable:
232             req = '-e %s' % req
233         return '\n'.join(list(self.comments) + [str(req)]) + '\n'
234
```
--- 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/operations/freeze.py b/src/pip/_internal/operations/freeze.py
--- a/src/pip/_internal/operations/freeze.py
+++ b/src/pip/_internal/operations/freeze.py
@@ -1,11 +1,12 @@
 from __future__ import absolute_import
 
+import collections
 import logging
 import os
 import re
 import warnings
 
-from pip._vendor import pkg_resources
+from pip._vendor import pkg_resources, six
 from pip._vendor.packaging.utils import canonicalize_name
 from pip._vendor.pkg_resources import RequirementParseError
 
@@ -70,6 +71,9 @@
         # requirements files, so we need to keep track of what has been emitted
         # so that we don't emit it again if it's seen again
         emitted_options = set()
+        # keep track of which files a requirement is in so that we can
+        # give an accurate warning if a requirement appears multiple times.
+        req_files = collections.defaultdict(list)
         for req_file_path in requirement:
             with open(req_file_path) as req_file:
                 for line in req_file:
@@ -119,14 +123,28 @@
                             " this warning)"
                         )
                     elif line_req.name not in installations:
-                        logger.warning(
-                            "Requirement file [%s] contains %s, but that "
-                            "package is not installed",
-                            req_file_path, COMMENT_RE.sub('', line).strip(),
-                        )
+                        # either it's not installed, or it is installed
+                        # but has been processed already
+                        if not req_files[line_req.name]:
+                            logger.warning(
+                                "Requirement file [%s] contains %s, but that "
+                                "package is not installed",
+                                req_file_path,
+                                COMMENT_RE.sub('', line).strip(),
+                            )
+                        else:
+                            req_files[line_req.name].append(req_file_path)
                     else:
                         yield str(installations[line_req.name]).rstrip()
                         del installations[line_req.name]
+                        req_files[line_req.name].append(req_file_path)
+
+        # Warn about requirements that were included multiple times (in a
+        # single requirements file or in different requirements files).
+        for name, files in six.iteritems(req_files):
+            if len(files) > 1:
+                logger.warning("Requirement %s included multiple times [%s]",
+                               name, ', '.join(sorted(set(files))))
 
         yield(
             '## The following requirements were added by '

{"golden_diff": "diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py\n--- a/src/pip/_internal/operations/freeze.py\n+++ b/src/pip/_internal/operations/freeze.py\n@@ -1,11 +1,12 @@\n from __future__ import absolute_import\n \n+import collections\n import logging\n import os\n import re\n import warnings\n \n-from pip._vendor import pkg_resources\n+from pip._vendor import pkg_resources, six\n from pip._vendor.packaging.utils import canonicalize_name\n from pip._vendor.pkg_resources import RequirementParseError\n \n@@ -70,6 +71,9 @@\n         # requirements files, so we need to keep track of what has been emitted\n         # so that we don't emit it again if it's seen again\n         emitted_options = set()\n+        # keep track of which files a requirement is in so that we can\n+        # give an accurate warning if a requirement appears multiple times.\n+        req_files = collections.defaultdict(list)\n         for req_file_path in requirement:\n             with open(req_file_path) as req_file:\n                 for line in req_file:\n@@ -119,14 +123,28 @@\n                             \" this warning)\"\n                         )\n                     elif line_req.name not in installations:\n-                        logger.warning(\n-                            \"Requirement file [%s] contains %s, but that \"\n-                            \"package is not installed\",\n-                            req_file_path, COMMENT_RE.sub('', line).strip(),\n-                        )\n+                        # either it's not installed, or it is installed\n+                        # but has been processed already\n+                        if not req_files[line_req.name]:\n+                            logger.warning(\n+                                \"Requirement file [%s] contains %s, but that \"\n+                                \"package is not installed\",\n+                                req_file_path,\n+                                COMMENT_RE.sub('', line).strip(),\n+                            )\n+                        else:\n+                            req_files[line_req.name].append(req_file_path)\n                     else:\n                         yield str(installations[line_req.name]).rstrip()\n                         del installations[line_req.name]\n+                        req_files[line_req.name].append(req_file_path)\n+\n+        # Warn about requirements that were included multiple times (in a\n+        # single requirements file or in different requirements files).\n+        for name, files in six.iteritems(req_files):\n+            if len(files) > 1:\n+                logger.warning(\"Requirement %s included multiple times [%s]\",\n+                               name, ', '.join(sorted(set(files))))\n \n         yield(\n             '## The following requirements were added by '\n", "issue": "pip freeze reports doubles in requirements files as \"not installed\"\n* Pip version: 9.0.1\r\n* Python version: all\r\n* Operating system: all\r\n\r\n### Description:\r\nIf a package is listed twice in a single requirements file, or once in two or more requirements files, then 'pip freeze -r requirements.txt' erroneously reports that the package isn't installed.\r\n\r\n\r\n### What I've run:\r\n\r\n```\r\npip install simplejson\r\n\r\ncat <<EOF > requirements.txt\r\nsimplejson\r\nsimplejson\r\nEOF\r\n\r\npip freeze -r requirements.txt\r\nsimplejson==3.10.0\r\nRequirement file [requirements.txt] contains simplejson, but that package is not installed\r\n## The following requirements were added by pip freeze:\r\n```\r\n\r\nSimilarly, pip freeze now supports multiple '-r' options, and if the same package appears in more than one of the requirements files, then the same message about the package not being installed is displayed.\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport logging\nimport os\nimport re\nimport warnings\n\nfrom pip._vendor import pkg_resources\nfrom pip._vendor.packaging.utils import canonicalize_name\nfrom pip._vendor.pkg_resources import RequirementParseError\n\nfrom pip._internal.exceptions import InstallationError\nfrom pip._internal.req import InstallRequirement\nfrom pip._internal.req.req_file import COMMENT_RE\nfrom pip._internal.utils.deprecation import RemovedInPip11Warning\nfrom pip._internal.utils.misc import (\n    dist_is_editable, get_installed_distributions\n)\n\nlogger = logging.getLogger(__name__)\n\n\ndef freeze(\n        requirement=None,\n        find_links=None, local_only=None, user_only=None, skip_regex=None,\n        isolated=False,\n        wheel_cache=None,\n        exclude_editable=False,\n        skip=()):\n    find_links = find_links or []\n    skip_match = None\n\n    if skip_regex:\n        skip_match = re.compile(skip_regex).search\n\n    dependency_links = []\n\n    for dist in pkg_resources.working_set:\n        if dist.has_metadata('dependency_links.txt'):\n            dependency_links.extend(\n                dist.get_metadata_lines('dependency_links.txt')\n            )\n    for link in find_links:\n        if '#egg=' in link:\n            dependency_links.append(link)\n    for link in find_links:\n        yield '-f %s' % link\n    installations = {}\n    for dist in get_installed_distributions(local_only=local_only,\n                                            skip=(),\n                                            user_only=user_only):\n        try:\n            req = FrozenRequirement.from_dist(\n                dist,\n                dependency_links\n            )\n        except RequirementParseError:\n            logger.warning(\n                \"Could not parse requirement: %s\",\n                dist.project_name\n            )\n            continue\n        if exclude_editable and req.editable:\n            continue\n        installations[req.name] = req\n\n    if requirement:\n        # the options that don't get turned into an InstallRequirement\n        # should only be emitted once, even if the same option is in multiple\n        # requirements files, so we need to keep track of what has been emitted\n        # so that we don't emit it again if it's seen again\n        emitted_options = set()\n        for req_file_path in requirement:\n            with open(req_file_path) as req_file:\n                for line in req_file:\n                    if (not line.strip() or\n                            line.strip().startswith('#') or\n                            (skip_match and skip_match(line)) or\n                            line.startswith((\n                                '-r', '--requirement',\n                                '-Z', '--always-unzip',\n                                '-f', '--find-links',\n                                '-i', '--index-url',\n                                '--pre',\n                                '--trusted-host',\n                                '--process-dependency-links',\n                                '--extra-index-url'))):\n                        line = line.rstrip()\n                        if line not in emitted_options:\n                            emitted_options.add(line)\n                            yield line\n                        continue\n\n                    if line.startswith('-e') or line.startswith('--editable'):\n                        if line.startswith('-e'):\n                            line = line[2:].strip()\n                        else:\n                            line = line[len('--editable'):].strip().lstrip('=')\n                        line_req = InstallRequirement.from_editable(\n                            line,\n                            isolated=isolated,\n                            wheel_cache=wheel_cache,\n                        )\n                    else:\n                        line_req = InstallRequirement.from_line(\n                            COMMENT_RE.sub('', line).strip(),\n                            isolated=isolated,\n                            wheel_cache=wheel_cache,\n                        )\n\n                    if not line_req.name:\n                        logger.info(\n                            \"Skipping line in requirement file [%s] because \"\n                            \"it's not clear what it would install: %s\",\n                            req_file_path, line.strip(),\n                        )\n                        logger.info(\n                            \"  (add #egg=PackageName to the URL to avoid\"\n                            \" this warning)\"\n                        )\n                    elif line_req.name not in installations:\n                        logger.warning(\n                            \"Requirement file [%s] contains %s, but that \"\n                            \"package is not installed\",\n                            req_file_path, COMMENT_RE.sub('', line).strip(),\n                        )\n                    else:\n                        yield str(installations[line_req.name]).rstrip()\n                        del installations[line_req.name]\n\n        yield(\n            '## The following requirements were added by '\n            'pip freeze:'\n        )\n    for installation in sorted(\n            installations.values(), key=lambda x: x.name.lower()):\n        if canonicalize_name(installation.name) not in skip:\n            yield str(installation).rstrip()\n\n\nclass FrozenRequirement(object):\n    def __init__(self, name, req, editable, comments=()):\n        self.name = name\n        self.req = req\n        self.editable = editable\n        self.comments = comments\n\n    _rev_re = re.compile(r'-r(\\d+)$')\n    _date_re = re.compile(r'-(20\\d\\d\\d\\d\\d\\d)$')\n\n    @classmethod\n    def from_dist(cls, dist, dependency_links):\n        location = os.path.normcase(os.path.abspath(dist.location))\n        comments = []\n        from pip._internal.vcs import vcs, get_src_requirement\n        if dist_is_editable(dist) and vcs.get_backend_name(location):\n            editable = True\n            try:\n                req = get_src_requirement(dist, location)\n            except InstallationError as exc:\n                logger.warning(\n                    \"Error when trying to get requirement for VCS system %s, \"\n                    \"falling back to uneditable format\", exc\n                )\n                req = None\n            if req is None:\n                logger.warning(\n                    'Could not determine repository location of %s', location\n                )\n                comments.append(\n                    '## !! Could not determine repository location'\n                )\n                req = dist.as_requirement()\n                editable = False\n        else:\n            editable = False\n            req = dist.as_requirement()\n            specs = req.specs\n            assert len(specs) == 1 and specs[0][0] in [\"==\", \"===\"], \\\n                'Expected 1 spec with == or ===; specs = %r; dist = %r' % \\\n                (specs, dist)\n            version = specs[0][1]\n            ver_match = cls._rev_re.search(version)\n            date_match = cls._date_re.search(version)\n            if ver_match or date_match:\n                svn_backend = vcs.get_backend('svn')\n                if svn_backend:\n                    svn_location = svn_backend().get_location(\n                        dist,\n                        dependency_links,\n                    )\n                if not svn_location:\n                    logger.warning(\n                        'Warning: cannot find svn location for %s', req)\n                    comments.append(\n                        '## FIXME: could not find svn URL in dependency_links '\n                        'for this package:'\n                    )\n                else:\n                    warnings.warn(\n                        \"SVN editable detection based on dependency links \"\n                        \"will be dropped in the future.\",\n                        RemovedInPip11Warning,\n                    )\n                    comments.append(\n                        '# Installing as editable to satisfy requirement %s:' %\n                        req\n                    )\n                    if ver_match:\n                        rev = ver_match.group(1)\n                    else:\n                        rev = '{%s}' % date_match.group(1)\n                    editable = True\n                    req = '%s@%s#egg=%s' % (\n                        svn_location,\n                        rev,\n                        cls.egg_name(dist)\n                    )\n        return cls(dist.project_name, req, editable, comments)\n\n    @staticmethod\n    def egg_name(dist):\n        name = dist.egg_name()\n        match = re.search(r'-py\\d\\.\\d$', name)\n        if match:\n            name = name[:match.start()]\n        return name\n\n    def __str__(self):\n        req = self.req\n        if self.editable:\n            req = '-e %s' % req\n        return '\\n'.join(list(self.comments) + [str(req)]) + '\\n'\n", "path": "src/pip/_internal/operations/freeze.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nimport collections\nimport logging\nimport os\nimport re\nimport warnings\n\nfrom pip._vendor import pkg_resources, six\nfrom pip._vendor.packaging.utils import canonicalize_name\nfrom pip._vendor.pkg_resources import RequirementParseError\n\nfrom pip._internal.exceptions import InstallationError\nfrom pip._internal.req import InstallRequirement\nfrom pip._internal.req.req_file import COMMENT_RE\nfrom pip._internal.utils.deprecation import RemovedInPip11Warning\nfrom pip._internal.utils.misc import (\n    dist_is_editable, get_installed_distributions\n)\n\nlogger = logging.getLogger(__name__)\n\n\ndef freeze(\n        requirement=None,\n        find_links=None, local_only=None, user_only=None, skip_regex=None,\n        isolated=False,\n        wheel_cache=None,\n        exclude_editable=False,\n        skip=()):\n    find_links = find_links or []\n    skip_match = None\n\n    if skip_regex:\n        skip_match = re.compile(skip_regex).search\n\n    dependency_links = []\n\n    for dist in pkg_resources.working_set:\n        if dist.has_metadata('dependency_links.txt'):\n            dependency_links.extend(\n                dist.get_metadata_lines('dependency_links.txt')\n            )\n    for link in find_links:\n        if '#egg=' in link:\n            dependency_links.append(link)\n    for link in find_links:\n        yield '-f %s' % link\n    installations = {}\n    for dist in get_installed_distributions(local_only=local_only,\n                                            skip=(),\n                                            user_only=user_only):\n        try:\n            req = FrozenRequirement.from_dist(\n                dist,\n                dependency_links\n            )\n        except RequirementParseError:\n            logger.warning(\n                \"Could not parse requirement: %s\",\n                dist.project_name\n            )\n            continue\n        if exclude_editable and req.editable:\n            continue\n        installations[req.name] = req\n\n    if requirement:\n        # the options that don't get turned into an InstallRequirement\n        # should only be emitted once, even if the same option is in multiple\n        # requirements files, so we need to keep track of what has been emitted\n        # so that we don't emit it again if it's seen again\n        emitted_options = set()\n        # keep track of which files a requirement is in so that we can\n        # give an accurate warning if a requirement appears multiple times.\n        req_files = collections.defaultdict(list)\n        for req_file_path in requirement:\n            with open(req_file_path) as req_file:\n                for line in req_file:\n                    if (not line.strip() or\n                            line.strip().startswith('#') or\n                            (skip_match and skip_match(line)) or\n                            line.startswith((\n                                '-r', '--requirement',\n                                '-Z', '--always-unzip',\n                                '-f', '--find-links',\n                                '-i', '--index-url',\n                                '--pre',\n                                '--trusted-host',\n                                '--process-dependency-links',\n                                '--extra-index-url'))):\n                        line = line.rstrip()\n                        if line not in emitted_options:\n                            emitted_options.add(line)\n                            yield line\n                        continue\n\n                    if line.startswith('-e') or line.startswith('--editable'):\n                        if line.startswith('-e'):\n                            line = line[2:].strip()\n                        else:\n                            line = line[len('--editable'):].strip().lstrip('=')\n                        line_req = InstallRequirement.from_editable(\n                            line,\n                            isolated=isolated,\n                            wheel_cache=wheel_cache,\n                        )\n                    else:\n                        line_req = InstallRequirement.from_line(\n                            COMMENT_RE.sub('', line).strip(),\n                            isolated=isolated,\n                            wheel_cache=wheel_cache,\n                        )\n\n                    if not line_req.name:\n                        logger.info(\n                            \"Skipping line in requirement file [%s] because \"\n                            \"it's not clear what it would install: %s\",\n                            req_file_path, line.strip(),\n                        )\n                        logger.info(\n                            \"  (add #egg=PackageName to the URL to avoid\"\n                            \" this warning)\"\n                        )\n                    elif line_req.name not in installations:\n                        # either it's not installed, or it is installed\n                        # but has been processed already\n                        if not req_files[line_req.name]:\n                            logger.warning(\n                                \"Requirement file [%s] contains %s, but that \"\n                                \"package is not installed\",\n                                req_file_path,\n                                COMMENT_RE.sub('', line).strip(),\n                            )\n                        else:\n                            req_files[line_req.name].append(req_file_path)\n                    else:\n                        yield str(installations[line_req.name]).rstrip()\n                        del installations[line_req.name]\n                        req_files[line_req.name].append(req_file_path)\n\n        # Warn about requirements that were included multiple times (in a\n        # single requirements file or in different requirements files).\n        for name, files in six.iteritems(req_files):\n            if len(files) > 1:\n                logger.warning(\"Requirement %s included multiple times [%s]\",\n                               name, ', '.join(sorted(set(files))))\n\n        yield(\n            '## The following requirements were added by '\n            'pip freeze:'\n        )\n    for installation in sorted(\n            installations.values(), key=lambda x: x.name.lower()):\n        if canonicalize_name(installation.name) not in skip:\n            yield str(installation).rstrip()\n\n\nclass FrozenRequirement(object):\n    def __init__(self, name, req, editable, comments=()):\n        self.name = name\n        self.req = req\n        self.editable = editable\n        self.comments = comments\n\n    _rev_re = re.compile(r'-r(\\d+)$')\n    _date_re = re.compile(r'-(20\\d\\d\\d\\d\\d\\d)$')\n\n    @classmethod\n    def from_dist(cls, dist, dependency_links):\n        location = os.path.normcase(os.path.abspath(dist.location))\n        comments = []\n        from pip._internal.vcs import vcs, get_src_requirement\n        if dist_is_editable(dist) and vcs.get_backend_name(location):\n            editable = True\n            try:\n                req = get_src_requirement(dist, location)\n            except InstallationError as exc:\n                logger.warning(\n                    \"Error when trying to get requirement for VCS system %s, \"\n                    \"falling back to uneditable format\", exc\n                )\n                req = None\n            if req is None:\n                logger.warning(\n                    'Could not determine repository location of %s', location\n                )\n                comments.append(\n                    '## !! Could not determine repository location'\n                )\n                req = dist.as_requirement()\n                editable = False\n        else:\n            editable = False\n            req = dist.as_requirement()\n            specs = req.specs\n            assert len(specs) == 1 and specs[0][0] in [\"==\", \"===\"], \\\n                'Expected 1 spec with == or ===; specs = %r; dist = %r' % \\\n                (specs, dist)\n            version = specs[0][1]\n            ver_match = cls._rev_re.search(version)\n            date_match = cls._date_re.search(version)\n            if ver_match or date_match:\n                svn_backend = vcs.get_backend('svn')\n                if svn_backend:\n                    svn_location = svn_backend().get_location(\n                        dist,\n                        dependency_links,\n                    )\n                if not svn_location:\n                    logger.warning(\n                        'Warning: cannot find svn location for %s', req)\n                    comments.append(\n                        '## FIXME: could not find svn URL in dependency_links '\n                        'for this package:'\n                    )\n                else:\n                    warnings.warn(\n                        \"SVN editable detection based on dependency links \"\n                        \"will be dropped in the future.\",\n                        RemovedInPip11Warning,\n                    )\n                    comments.append(\n                        '# Installing as editable to satisfy requirement %s:' %\n                        req\n                    )\n                    if ver_match:\n                        rev = ver_match.group(1)\n                    else:\n                        rev = '{%s}' % date_match.group(1)\n                    editable = True\n                    req = '%s@%s#egg=%s' % (\n                        svn_location,\n                        rev,\n                        cls.egg_name(dist)\n                    )\n        return cls(dist.project_name, req, editable, comments)\n\n    @staticmethod\n    def egg_name(dist):\n        name = dist.egg_name()\n        match = re.search(r'-py\\d\\.\\d$', name)\n        if match:\n            name = name[:match.start()]\n        return name\n\n    def __str__(self):\n        req = self.req\n        if self.editable:\n            req = '-e %s' % req\n        return '\\n'.join(list(self.comments) + [str(req)]) + '\\n'\n", "path": "src/pip/_internal/operations/freeze.py"}]}