We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pipenv check looks at installed packages, not Pipfile.lock
## Use Case

I would like to run `pipenv check` as a separate job from the build/test job inside a CI pipeline without rebuilding environment. I discovered that I must actually install all packages to a `pipenv` environment before using `pipenv check`. Ideally, I should be able to scan the dependencies inside `Pipfile.lock` without actually installing the whole environment. 

I believe its misleading that right now `pipenv` is just acting as a "proxy" to `safety`,  and by default checks an environment that may not match `Pipfile.lock`.  By using `pipenv check` the assumption should be that it is checking the environment specified in `Pipfile.lock` and if you need to check an environment that deviates, you use `safety` directly.

I've traced the behavior down to these lines:
https://github.com/pypa/pipenv/blob/8939c863464b23b5503569669d1c3f9ad31a498f/pipenv/core.py#L2900-L2902

Instead of generating the temp `requirements.txt` file from the current environment using `pip list`, can we instead generate the temp `requirements.txt` from `Pipfile.lock`? Something like

```python
# this command should also respect the wishes of the --dev argument, if provided. Unsure on specifics of implementation
target_venv_packages = run_command(
        _cmd + ["-m", "pipenv", "requirements"], is_verbose=project.s.is_verbose()
    )
```

## Workaround

I'm currently using the following workaround in my CI job, but would like to go through `pipenv` directly. 

```bash
pipenv requirements --dev | safety check --stdin
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pipenv/routines/check.py`
Content:
```
1 import io
2 import json as simplejson
3 import os
4 import sys
5 import tempfile
6 from pathlib import Path
7 
8 from pipenv import exceptions, pep508checker
9 from pipenv.utils.processes import run_command
10 from pipenv.utils.project import ensure_project
11 from pipenv.utils.shell import cmd_list_to_shell, project_python
12 from pipenv.vendor import click, plette
13 
14 
15 def do_check(
16     project,
17     python=False,
18     system=False,
19     db=None,
20     ignore=None,
21     output="screen",
22     key=None,
23     quiet=False,
24     exit_code=True,
25     policy_file="",
26     save_json="",
27     audit_and_monitor=True,
28     safety_project=None,
29     pypi_mirror=None,
30     use_installed=False,
31     categories="",
32 ):
33     import json
34 
35     if not system:
36         # Ensure that virtualenv is available.
37         ensure_project(
38             project,
39             python=python,
40             validate=False,
41             warn=False,
42             pypi_mirror=pypi_mirror,
43         )
44     if not quiet and not project.s.is_quiet():
45         click.secho("Checking PEP 508 requirements...", bold=True)
46     pep508checker_path = pep508checker.__file__.rstrip("cdo")
47     safety_path = os.path.join(
48         os.path.dirname(os.path.abspath(__file__)), "patched", "safety"
49     )
50     _cmd = [project_python(project, system=system)]
51     # Run the PEP 508 checker in the virtualenv.
52     cmd = _cmd + [Path(pep508checker_path).as_posix()]
53     c = run_command(cmd, is_verbose=project.s.is_verbose())
54     results = []
55     if c.returncode is not None:
56         try:
57             results = simplejson.loads(c.stdout.strip())
58         except json.JSONDecodeError:
59             click.echo(
60                 "{}\n{}\n{}".format(
61                     click.style(
62                         "Failed parsing pep508 results: ",
63                         fg="white",
64                         bold=True,
65                     ),
66                     c.stdout.strip(),
67                     c.stderr.strip(),
68                 )
69             )
70             sys.exit(1)
71     # Load the pipfile.
72     p = plette.Pipfile.load(open(project.pipfile_location))
73     p = plette.Lockfile.with_meta_from(p)
74     failed = False
75     # Assert each specified requirement.
76     for marker, specifier in p._data["_meta"]["requires"].items():
77         if marker in results:
78             try:
79                 assert results[marker] == specifier
80             except AssertionError:
81                 failed = True
82                 click.echo(
83                     "Specifier {} does not match {} ({})."
84                     "".format(
85                         click.style(marker, fg="green"),
86                         click.style(specifier, fg="cyan"),
87                         click.style(results[marker], fg="yellow"),
88                     ),
89                     err=True,
90                 )
91     if failed:
92         click.secho("Failed!", fg="red", err=True)
93         sys.exit(1)
94     else:
95         if not quiet and not project.s.is_quiet():
96             click.secho("Passed!", fg="green")
97     if not quiet and not project.s.is_quiet():
98         click.secho(
99             "Checking installed packages for vulnerabilities...",
100             bold=True,
101         )
102     if ignore:
103         if not isinstance(ignore, (tuple, list)):
104             ignore = [ignore]
105         ignored = [["--ignore", cve] for cve in ignore]
106         if not quiet and not project.s.is_quiet():
107             click.echo(
108                 "Notice: Ignoring Vulnerabilit{} {}".format(
109                     "ies" if len(ignored) > 1 else "y",
110                     click.style(", ".join(ignore), fg="yellow"),
111                 ),
112                 err=True,
113             )
114     else:
115         ignored = []
116 
117     options = [
118         "--audit-and-monitor" if audit_and_monitor else "--disable-audit-and-monitor",
119         "--exit-code" if exit_code else "--continue-on-error",
120     ]
121 
122     if output == "full-report":
123         options.append("--full-report")
124     elif output == "minimal":
125         options.append("--json")
126     elif output not in ["screen", "default"]:
127         options.append(f"--output={output}")
128 
129     if save_json:
130         options.append(f"--save-json={save_json}")
131 
132     if policy_file:
133         options.append(f"--policy-file={policy_file}")
134 
135     if safety_project:
136         options.append(f"--project={safety_project}")
137 
138     if use_installed:
139         target_venv_packages = run_command(
140             _cmd + ["-m", "pip", "list", "--format=freeze"],
141             is_verbose=project.s.is_verbose(),
142         )
143     elif categories:
144         target_venv_packages = run_command(
145             ["pipenv", "requirements", "--categories", categories],
146             is_verbose=project.s.is_verbose(),
147         )
148     else:
149         target_venv_packages = run_command(
150             ["pipenv", "requirements"], is_verbose=project.s.is_verbose()
151         )
152 
153     temp_requirements = tempfile.NamedTemporaryFile(
154         mode="w+",
155         prefix=f"{project.virtualenv_name}",
156         suffix="_requirements.txt",
157         delete=False,
158     )
159     temp_requirements.write(target_venv_packages.stdout.strip())
160     temp_requirements.close()
161 
162     options.extend(["--file", temp_requirements.name])
163 
164     cmd = _cmd + [safety_path, "check"] + options
165 
166     if db:
167         if not quiet and not project.s.is_quiet():
168             click.echo(f"Using {db} database")
169         cmd.append(f"--db={db}")
170     elif key or project.s.PIPENV_PYUP_API_KEY:
171         cmd = cmd + [f"--key={key or project.s.PIPENV_PYUP_API_KEY}"]
172     else:
173         PIPENV_SAFETY_DB = (
174             "https://d2qjmgddvqvu75.cloudfront.net/aws/safety/pipenv/1.0.0/"
175         )
176         os.environ["SAFETY_ANNOUNCEMENTS_URL"] = f"{PIPENV_SAFETY_DB}announcements.json"
177         cmd.append(f"--db={PIPENV_SAFETY_DB}")
178 
179     if ignored:
180         for cve in ignored:
181             cmd += cve
182 
183     os.environ["SAFETY_CUSTOM_INTEGRATION"] = "True"
184     os.environ["SAFETY_SOURCE"] = "pipenv"
185     os.environ["SAFETY_PURE_YAML"] = "True"
186 
187     from pipenv.patched.safety.cli import cli
188 
189     sys.argv = cmd[1:]
190 
191     if output == "minimal":
192         from contextlib import redirect_stderr, redirect_stdout
193 
194         code = 0
195 
196         with redirect_stdout(io.StringIO()) as out, redirect_stderr(io.StringIO()) as err:
197             try:
198                 cli(prog_name="pipenv")
199             except SystemExit as exit_signal:
200                 code = exit_signal.code
201 
202         report = out.getvalue()
203         error = err.getvalue()
204 
205         try:
206             json_report = simplejson.loads(report)
207         except Exception:
208             raise exceptions.PipenvCmdError(
209                 cmd_list_to_shell(cmd), report, error, exit_code=code
210             )
211         meta = json_report.get("report_meta")
212         vulnerabilities_found = meta.get("vulnerabilities_found")
213 
214         fg = "green"
215         message = "All good!"
216         db_type = "commercial" if meta.get("api_key", False) else "free"
217 
218         if vulnerabilities_found >= 0:
219             fg = "red"
220             message = (
221                 f"Scan was complete using Safety’s {db_type} vulnerability database."
222             )
223 
224         click.echo()
225         click.secho(f"{vulnerabilities_found} vulnerabilities found.", fg=fg)
226         click.echo()
227 
228         vulnerabilities = json_report.get("vulnerabilities", [])
229 
230         for vuln in vulnerabilities:
231             click.echo(
232                 "{}: {} {} open to vulnerability {} ({}). More info: {}".format(
233                     click.style(vuln["vulnerability_id"], bold=True, fg="red"),
234                     click.style(vuln["package_name"], fg="green"),
235                     click.style(vuln["analyzed_version"], fg="yellow", bold=True),
236                     click.style(vuln["vulnerability_id"], bold=True),
237                     click.style(vuln["vulnerable_spec"], fg="yellow", bold=False),
238                     click.style(vuln["more_info_url"], bold=True),
239                 )
240             )
241             click.echo(f"{vuln['advisory']}")
242             click.echo()
243 
244         click.secho(message, fg="white", bold=True)
245         sys.exit(code)
246 
247     cli(prog_name="pipenv")
248 
249     temp_requirements.remove()
250
```
--- 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/pipenv/routines/check.py b/pipenv/routines/check.py
--- a/pipenv/routines/check.py
+++ b/pipenv/routines/check.py
@@ -95,10 +95,16 @@
         if not quiet and not project.s.is_quiet():
             click.secho("Passed!", fg="green")
     if not quiet and not project.s.is_quiet():
-        click.secho(
-            "Checking installed packages for vulnerabilities...",
-            bold=True,
-        )
+        if use_installed:
+            click.secho(
+                "Checking installed packages for vulnerabilities...",
+                bold=True,
+            )
+        else:
+            click.secho(
+                "Checking Pipfile.lock packages for vulnerabilities...",
+                bold=True,
+            )
     if ignore:
         if not isinstance(ignore, (tuple, list)):
             ignore = [ignore]

{"golden_diff": "diff --git a/pipenv/routines/check.py b/pipenv/routines/check.py\n--- a/pipenv/routines/check.py\n+++ b/pipenv/routines/check.py\n@@ -95,10 +95,16 @@\n         if not quiet and not project.s.is_quiet():\n             click.secho(\"Passed!\", fg=\"green\")\n     if not quiet and not project.s.is_quiet():\n-        click.secho(\n-            \"Checking installed packages for vulnerabilities...\",\n-            bold=True,\n-        )\n+        if use_installed:\n+            click.secho(\n+                \"Checking installed packages for vulnerabilities...\",\n+                bold=True,\n+            )\n+        else:\n+            click.secho(\n+                \"Checking Pipfile.lock packages for vulnerabilities...\",\n+                bold=True,\n+            )\n     if ignore:\n         if not isinstance(ignore, (tuple, list)):\n             ignore = [ignore]\n", "issue": "pipenv check looks at installed packages, not Pipfile.lock\n## Use Case\r\n\r\nI would like to run `pipenv check` as a separate job from the build/test job inside a CI pipeline without rebuilding environment. I discovered that I must actually install all packages to a `pipenv` environment before using `pipenv check`. Ideally, I should be able to scan the dependencies inside `Pipfile.lock` without actually installing the whole environment. \r\n\r\nI believe its misleading that right now `pipenv` is just acting as a \"proxy\" to `safety`,  and by default checks an environment that may not match `Pipfile.lock`.  By using `pipenv check` the assumption should be that it is checking the environment specified in `Pipfile.lock` and if you need to check an environment that deviates, you use `safety` directly.\r\n\r\nI've traced the behavior down to these lines:\r\nhttps://github.com/pypa/pipenv/blob/8939c863464b23b5503569669d1c3f9ad31a498f/pipenv/core.py#L2900-L2902\r\n\r\nInstead of generating the temp `requirements.txt` file from the current environment using `pip list`, can we instead generate the temp `requirements.txt` from `Pipfile.lock`? Something like\r\n\r\n```python\r\n# this command should also respect the wishes of the --dev argument, if provided. Unsure on specifics of implementation\r\ntarget_venv_packages = run_command(\r\n        _cmd + [\"-m\", \"pipenv\", \"requirements\"], is_verbose=project.s.is_verbose()\r\n    )\r\n```\r\n\r\n## Workaround\r\n\r\nI'm currently using the following workaround in my CI job, but would like to go through `pipenv` directly. \r\n\r\n```bash\r\npipenv requirements --dev | safety check --stdin\r\n```\n", "before_files": [{"content": "import io\nimport json as simplejson\nimport os\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nfrom pipenv import exceptions, pep508checker\nfrom pipenv.utils.processes import run_command\nfrom pipenv.utils.project import ensure_project\nfrom pipenv.utils.shell import cmd_list_to_shell, project_python\nfrom pipenv.vendor import click, plette\n\n\ndef do_check(\n    project,\n    python=False,\n    system=False,\n    db=None,\n    ignore=None,\n    output=\"screen\",\n    key=None,\n    quiet=False,\n    exit_code=True,\n    policy_file=\"\",\n    save_json=\"\",\n    audit_and_monitor=True,\n    safety_project=None,\n    pypi_mirror=None,\n    use_installed=False,\n    categories=\"\",\n):\n    import json\n\n    if not system:\n        # Ensure that virtualenv is available.\n        ensure_project(\n            project,\n            python=python,\n            validate=False,\n            warn=False,\n            pypi_mirror=pypi_mirror,\n        )\n    if not quiet and not project.s.is_quiet():\n        click.secho(\"Checking PEP 508 requirements...\", bold=True)\n    pep508checker_path = pep508checker.__file__.rstrip(\"cdo\")\n    safety_path = os.path.join(\n        os.path.dirname(os.path.abspath(__file__)), \"patched\", \"safety\"\n    )\n    _cmd = [project_python(project, system=system)]\n    # Run the PEP 508 checker in the virtualenv.\n    cmd = _cmd + [Path(pep508checker_path).as_posix()]\n    c = run_command(cmd, is_verbose=project.s.is_verbose())\n    results = []\n    if c.returncode is not None:\n        try:\n            results = simplejson.loads(c.stdout.strip())\n        except json.JSONDecodeError:\n            click.echo(\n                \"{}\\n{}\\n{}\".format(\n                    click.style(\n                        \"Failed parsing pep508 results: \",\n                        fg=\"white\",\n                        bold=True,\n                    ),\n                    c.stdout.strip(),\n                    c.stderr.strip(),\n                )\n            )\n            sys.exit(1)\n    # Load the pipfile.\n    p = plette.Pipfile.load(open(project.pipfile_location))\n    p = plette.Lockfile.with_meta_from(p)\n    failed = False\n    # Assert each specified requirement.\n    for marker, specifier in p._data[\"_meta\"][\"requires\"].items():\n        if marker in results:\n            try:\n                assert results[marker] == specifier\n            except AssertionError:\n                failed = True\n                click.echo(\n                    \"Specifier {} does not match {} ({}).\"\n                    \"\".format(\n                        click.style(marker, fg=\"green\"),\n                        click.style(specifier, fg=\"cyan\"),\n                        click.style(results[marker], fg=\"yellow\"),\n                    ),\n                    err=True,\n                )\n    if failed:\n        click.secho(\"Failed!\", fg=\"red\", err=True)\n        sys.exit(1)\n    else:\n        if not quiet and not project.s.is_quiet():\n            click.secho(\"Passed!\", fg=\"green\")\n    if not quiet and not project.s.is_quiet():\n        click.secho(\n            \"Checking installed packages for vulnerabilities...\",\n            bold=True,\n        )\n    if ignore:\n        if not isinstance(ignore, (tuple, list)):\n            ignore = [ignore]\n        ignored = [[\"--ignore\", cve] for cve in ignore]\n        if not quiet and not project.s.is_quiet():\n            click.echo(\n                \"Notice: Ignoring Vulnerabilit{} {}\".format(\n                    \"ies\" if len(ignored) > 1 else \"y\",\n                    click.style(\", \".join(ignore), fg=\"yellow\"),\n                ),\n                err=True,\n            )\n    else:\n        ignored = []\n\n    options = [\n        \"--audit-and-monitor\" if audit_and_monitor else \"--disable-audit-and-monitor\",\n        \"--exit-code\" if exit_code else \"--continue-on-error\",\n    ]\n\n    if output == \"full-report\":\n        options.append(\"--full-report\")\n    elif output == \"minimal\":\n        options.append(\"--json\")\n    elif output not in [\"screen\", \"default\"]:\n        options.append(f\"--output={output}\")\n\n    if save_json:\n        options.append(f\"--save-json={save_json}\")\n\n    if policy_file:\n        options.append(f\"--policy-file={policy_file}\")\n\n    if safety_project:\n        options.append(f\"--project={safety_project}\")\n\n    if use_installed:\n        target_venv_packages = run_command(\n            _cmd + [\"-m\", \"pip\", \"list\", \"--format=freeze\"],\n            is_verbose=project.s.is_verbose(),\n        )\n    elif categories:\n        target_venv_packages = run_command(\n            [\"pipenv\", \"requirements\", \"--categories\", categories],\n            is_verbose=project.s.is_verbose(),\n        )\n    else:\n        target_venv_packages = run_command(\n            [\"pipenv\", \"requirements\"], is_verbose=project.s.is_verbose()\n        )\n\n    temp_requirements = tempfile.NamedTemporaryFile(\n        mode=\"w+\",\n        prefix=f\"{project.virtualenv_name}\",\n        suffix=\"_requirements.txt\",\n        delete=False,\n    )\n    temp_requirements.write(target_venv_packages.stdout.strip())\n    temp_requirements.close()\n\n    options.extend([\"--file\", temp_requirements.name])\n\n    cmd = _cmd + [safety_path, \"check\"] + options\n\n    if db:\n        if not quiet and not project.s.is_quiet():\n            click.echo(f\"Using {db} database\")\n        cmd.append(f\"--db={db}\")\n    elif key or project.s.PIPENV_PYUP_API_KEY:\n        cmd = cmd + [f\"--key={key or project.s.PIPENV_PYUP_API_KEY}\"]\n    else:\n        PIPENV_SAFETY_DB = (\n            \"https://d2qjmgddvqvu75.cloudfront.net/aws/safety/pipenv/1.0.0/\"\n        )\n        os.environ[\"SAFETY_ANNOUNCEMENTS_URL\"] = f\"{PIPENV_SAFETY_DB}announcements.json\"\n        cmd.append(f\"--db={PIPENV_SAFETY_DB}\")\n\n    if ignored:\n        for cve in ignored:\n            cmd += cve\n\n    os.environ[\"SAFETY_CUSTOM_INTEGRATION\"] = \"True\"\n    os.environ[\"SAFETY_SOURCE\"] = \"pipenv\"\n    os.environ[\"SAFETY_PURE_YAML\"] = \"True\"\n\n    from pipenv.patched.safety.cli import cli\n\n    sys.argv = cmd[1:]\n\n    if output == \"minimal\":\n        from contextlib import redirect_stderr, redirect_stdout\n\n        code = 0\n\n        with redirect_stdout(io.StringIO()) as out, redirect_stderr(io.StringIO()) as err:\n            try:\n                cli(prog_name=\"pipenv\")\n            except SystemExit as exit_signal:\n                code = exit_signal.code\n\n        report = out.getvalue()\n        error = err.getvalue()\n\n        try:\n            json_report = simplejson.loads(report)\n        except Exception:\n            raise exceptions.PipenvCmdError(\n                cmd_list_to_shell(cmd), report, error, exit_code=code\n            )\n        meta = json_report.get(\"report_meta\")\n        vulnerabilities_found = meta.get(\"vulnerabilities_found\")\n\n        fg = \"green\"\n        message = \"All good!\"\n        db_type = \"commercial\" if meta.get(\"api_key\", False) else \"free\"\n\n        if vulnerabilities_found >= 0:\n            fg = \"red\"\n            message = (\n                f\"Scan was complete using Safety\u2019s {db_type} vulnerability database.\"\n            )\n\n        click.echo()\n        click.secho(f\"{vulnerabilities_found} vulnerabilities found.\", fg=fg)\n        click.echo()\n\n        vulnerabilities = json_report.get(\"vulnerabilities\", [])\n\n        for vuln in vulnerabilities:\n            click.echo(\n                \"{}: {} {} open to vulnerability {} ({}). More info: {}\".format(\n                    click.style(vuln[\"vulnerability_id\"], bold=True, fg=\"red\"),\n                    click.style(vuln[\"package_name\"], fg=\"green\"),\n                    click.style(vuln[\"analyzed_version\"], fg=\"yellow\", bold=True),\n                    click.style(vuln[\"vulnerability_id\"], bold=True),\n                    click.style(vuln[\"vulnerable_spec\"], fg=\"yellow\", bold=False),\n                    click.style(vuln[\"more_info_url\"], bold=True),\n                )\n            )\n            click.echo(f\"{vuln['advisory']}\")\n            click.echo()\n\n        click.secho(message, fg=\"white\", bold=True)\n        sys.exit(code)\n\n    cli(prog_name=\"pipenv\")\n\n    temp_requirements.remove()\n", "path": "pipenv/routines/check.py"}], "after_files": [{"content": "import io\nimport json as simplejson\nimport os\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nfrom pipenv import exceptions, pep508checker\nfrom pipenv.utils.processes import run_command\nfrom pipenv.utils.project import ensure_project\nfrom pipenv.utils.shell import cmd_list_to_shell, project_python\nfrom pipenv.vendor import click, plette\n\n\ndef do_check(\n    project,\n    python=False,\n    system=False,\n    db=None,\n    ignore=None,\n    output=\"screen\",\n    key=None,\n    quiet=False,\n    exit_code=True,\n    policy_file=\"\",\n    save_json=\"\",\n    audit_and_monitor=True,\n    safety_project=None,\n    pypi_mirror=None,\n    use_installed=False,\n    categories=\"\",\n):\n    import json\n\n    if not system:\n        # Ensure that virtualenv is available.\n        ensure_project(\n            project,\n            python=python,\n            validate=False,\n            warn=False,\n            pypi_mirror=pypi_mirror,\n        )\n    if not quiet and not project.s.is_quiet():\n        click.secho(\"Checking PEP 508 requirements...\", bold=True)\n    pep508checker_path = pep508checker.__file__.rstrip(\"cdo\")\n    safety_path = os.path.join(\n        os.path.dirname(os.path.abspath(__file__)), \"patched\", \"safety\"\n    )\n    _cmd = [project_python(project, system=system)]\n    # Run the PEP 508 checker in the virtualenv.\n    cmd = _cmd + [Path(pep508checker_path).as_posix()]\n    c = run_command(cmd, is_verbose=project.s.is_verbose())\n    results = []\n    if c.returncode is not None:\n        try:\n            results = simplejson.loads(c.stdout.strip())\n        except json.JSONDecodeError:\n            click.echo(\n                \"{}\\n{}\\n{}\".format(\n                    click.style(\n                        \"Failed parsing pep508 results: \",\n                        fg=\"white\",\n                        bold=True,\n                    ),\n                    c.stdout.strip(),\n                    c.stderr.strip(),\n                )\n            )\n            sys.exit(1)\n    # Load the pipfile.\n    p = plette.Pipfile.load(open(project.pipfile_location))\n    p = plette.Lockfile.with_meta_from(p)\n    failed = False\n    # Assert each specified requirement.\n    for marker, specifier in p._data[\"_meta\"][\"requires\"].items():\n        if marker in results:\n            try:\n                assert results[marker] == specifier\n            except AssertionError:\n                failed = True\n                click.echo(\n                    \"Specifier {} does not match {} ({}).\"\n                    \"\".format(\n                        click.style(marker, fg=\"green\"),\n                        click.style(specifier, fg=\"cyan\"),\n                        click.style(results[marker], fg=\"yellow\"),\n                    ),\n                    err=True,\n                )\n    if failed:\n        click.secho(\"Failed!\", fg=\"red\", err=True)\n        sys.exit(1)\n    else:\n        if not quiet and not project.s.is_quiet():\n            click.secho(\"Passed!\", fg=\"green\")\n    if not quiet and not project.s.is_quiet():\n        if use_installed:\n            click.secho(\n                \"Checking installed packages for vulnerabilities...\",\n                bold=True,\n            )\n        else:\n            click.secho(\n                \"Checking Pipfile.lock packages for vulnerabilities...\",\n                bold=True,\n            )\n    if ignore:\n        if not isinstance(ignore, (tuple, list)):\n            ignore = [ignore]\n        ignored = [[\"--ignore\", cve] for cve in ignore]\n        if not quiet and not project.s.is_quiet():\n            click.echo(\n                \"Notice: Ignoring Vulnerabilit{} {}\".format(\n                    \"ies\" if len(ignored) > 1 else \"y\",\n                    click.style(\", \".join(ignore), fg=\"yellow\"),\n                ),\n                err=True,\n            )\n    else:\n        ignored = []\n\n    options = [\n        \"--audit-and-monitor\" if audit_and_monitor else \"--disable-audit-and-monitor\",\n        \"--exit-code\" if exit_code else \"--continue-on-error\",\n    ]\n\n    if output == \"full-report\":\n        options.append(\"--full-report\")\n    elif output == \"minimal\":\n        options.append(\"--json\")\n    elif output not in [\"screen\", \"default\"]:\n        options.append(f\"--output={output}\")\n\n    if save_json:\n        options.append(f\"--save-json={save_json}\")\n\n    if policy_file:\n        options.append(f\"--policy-file={policy_file}\")\n\n    if safety_project:\n        options.append(f\"--project={safety_project}\")\n\n    if use_installed:\n        target_venv_packages = run_command(\n            _cmd + [\"-m\", \"pip\", \"list\", \"--format=freeze\"],\n            is_verbose=project.s.is_verbose(),\n        )\n    elif categories:\n        target_venv_packages = run_command(\n            [\"pipenv\", \"requirements\", \"--categories\", categories],\n            is_verbose=project.s.is_verbose(),\n        )\n    else:\n        target_venv_packages = run_command(\n            [\"pipenv\", \"requirements\"], is_verbose=project.s.is_verbose()\n        )\n\n    temp_requirements = tempfile.NamedTemporaryFile(\n        mode=\"w+\",\n        prefix=f\"{project.virtualenv_name}\",\n        suffix=\"_requirements.txt\",\n        delete=False,\n    )\n    temp_requirements.write(target_venv_packages.stdout.strip())\n    temp_requirements.close()\n\n    options.extend([\"--file\", temp_requirements.name])\n\n    cmd = _cmd + [safety_path, \"check\"] + options\n\n    if db:\n        if not quiet and not project.s.is_quiet():\n            click.echo(f\"Using {db} database\")\n        cmd.append(f\"--db={db}\")\n    elif key or project.s.PIPENV_PYUP_API_KEY:\n        cmd = cmd + [f\"--key={key or project.s.PIPENV_PYUP_API_KEY}\"]\n    else:\n        PIPENV_SAFETY_DB = (\n            \"https://d2qjmgddvqvu75.cloudfront.net/aws/safety/pipenv/1.0.0/\"\n        )\n        os.environ[\"SAFETY_ANNOUNCEMENTS_URL\"] = f\"{PIPENV_SAFETY_DB}announcements.json\"\n        cmd.append(f\"--db={PIPENV_SAFETY_DB}\")\n\n    if ignored:\n        for cve in ignored:\n            cmd += cve\n\n    os.environ[\"SAFETY_CUSTOM_INTEGRATION\"] = \"True\"\n    os.environ[\"SAFETY_SOURCE\"] = \"pipenv\"\n    os.environ[\"SAFETY_PURE_YAML\"] = \"True\"\n\n    from pipenv.patched.safety.cli import cli\n\n    sys.argv = cmd[1:]\n\n    if output == \"minimal\":\n        from contextlib import redirect_stderr, redirect_stdout\n\n        code = 0\n\n        with redirect_stdout(io.StringIO()) as out, redirect_stderr(io.StringIO()) as err:\n            try:\n                cli(prog_name=\"pipenv\")\n            except SystemExit as exit_signal:\n                code = exit_signal.code\n\n        report = out.getvalue()\n        error = err.getvalue()\n\n        try:\n            json_report = simplejson.loads(report)\n        except Exception:\n            raise exceptions.PipenvCmdError(\n                cmd_list_to_shell(cmd), report, error, exit_code=code\n            )\n        meta = json_report.get(\"report_meta\")\n        vulnerabilities_found = meta.get(\"vulnerabilities_found\")\n\n        fg = \"green\"\n        message = \"All good!\"\n        db_type = \"commercial\" if meta.get(\"api_key\", False) else \"free\"\n\n        if vulnerabilities_found >= 0:\n            fg = \"red\"\n            message = (\n                f\"Scan was complete using Safety\u2019s {db_type} vulnerability database.\"\n            )\n\n        click.echo()\n        click.secho(f\"{vulnerabilities_found} vulnerabilities found.\", fg=fg)\n        click.echo()\n\n        vulnerabilities = json_report.get(\"vulnerabilities\", [])\n\n        for vuln in vulnerabilities:\n            click.echo(\n                \"{}: {} {} open to vulnerability {} ({}). More info: {}\".format(\n                    click.style(vuln[\"vulnerability_id\"], bold=True, fg=\"red\"),\n                    click.style(vuln[\"package_name\"], fg=\"green\"),\n                    click.style(vuln[\"analyzed_version\"], fg=\"yellow\", bold=True),\n                    click.style(vuln[\"vulnerability_id\"], bold=True),\n                    click.style(vuln[\"vulnerable_spec\"], fg=\"yellow\", bold=False),\n                    click.style(vuln[\"more_info_url\"], bold=True),\n                )\n            )\n            click.echo(f\"{vuln['advisory']}\")\n            click.echo()\n\n        click.secho(message, fg=\"white\", bold=True)\n        sys.exit(code)\n\n    cli(prog_name=\"pipenv\")\n\n    temp_requirements.remove()\n", "path": "pipenv/routines/check.py"}]}