We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pip-compile generates setup.txt by given explicitly setup.py in a source file
There is a possible wrong behavior on a command `pip-compile setup.py`, because it generates `setup.txt` file instead of `requirements.txt`.

##### Environment Versions

1. OS Type: Any (tested on MacOSX)
1. Python version: 3.7.x
1. pip version:  19.1
1. pip-tools version: 3.3.2

##### Steps to replicate

1. Prepare a `setup.py` file:
```
cat << EOF > setup.py
from setuptools import setup
setup(install_requires=[])
EOF
```
2. Run: `pip-compile setup.py`

##### Expected result

```
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file requirements.txt setup.py
#
```

##### Actual result

```
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file setup.txt setup.py
#
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `piptools/scripts/compile.py`
Content:
```
1 # coding: utf-8
2 from __future__ import (absolute_import, division, print_function,
3                         unicode_literals)
4 
5 import os
6 import sys
7 import tempfile
8 
9 from .._compat import (
10     install_req_from_line,
11     parse_requirements,
12 )
13 
14 from .. import click
15 from ..exceptions import PipToolsError
16 from ..logging import log
17 from ..pip import get_pip_command, pip_defaults
18 from ..repositories import LocalRequirementsRepository, PyPIRepository
19 from ..resolver import Resolver
20 from ..utils import (dedup, is_pinned_requirement, key_from_req, UNSAFE_PACKAGES)
21 from ..writer import OutputWriter
22 
23 DEFAULT_REQUIREMENTS_FILE = 'requirements.in'
24 
25 
26 @click.command()
27 @click.version_option()
28 @click.option('-v', '--verbose', count=True, help="Show more output")
29 @click.option('-q', '--quiet', count=True, help="Give less output")
30 @click.option('-n', '--dry-run', is_flag=True, help="Only show what would happen, don't change anything")
31 @click.option('-p', '--pre', is_flag=True, default=None, help="Allow resolving to prereleases (default is not)")
32 @click.option('-r', '--rebuild', is_flag=True, help="Clear any caches upfront, rebuild from scratch")
33 @click.option('-f', '--find-links', multiple=True, help="Look for archives in this directory or on this HTML page", envvar='PIP_FIND_LINKS')  # noqa
34 @click.option('-i', '--index-url', help="Change index URL (defaults to {})".format(pip_defaults.index_url), envvar='PIP_INDEX_URL')  # noqa
35 @click.option('--extra-index-url', multiple=True, help="Add additional index URL to search", envvar='PIP_EXTRA_INDEX_URL')  # noqa
36 @click.option('--cert', help="Path to alternate CA bundle.")
37 @click.option('--client-cert', help="Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.")  # noqa
38 @click.option('--trusted-host', multiple=True, envvar='PIP_TRUSTED_HOST',
39               help="Mark this host as trusted, even though it does not have "
40                    "valid or any HTTPS.")
41 @click.option('--header/--no-header', is_flag=True, default=True,
42               help="Add header to generated file")
43 @click.option('--index/--no-index', is_flag=True, default=True,
44               help="Add index URL to generated file")
45 @click.option('--emit-trusted-host/--no-emit-trusted-host', is_flag=True,
46               default=True, help="Add trusted host option to generated file")
47 @click.option('--annotate/--no-annotate', is_flag=True, default=True,
48               help="Annotate results, indicating where dependencies come from")
49 @click.option('-U', '--upgrade', is_flag=True, default=False,
50               help='Try to upgrade all dependencies to their latest versions')
51 @click.option('-P', '--upgrade-package', 'upgrade_packages', nargs=1, multiple=True,
52               help="Specify particular packages to upgrade.")
53 @click.option('-o', '--output-file', nargs=1, type=str, default=None,
54               help=('Output file name. Required if more than one input file is given. '
55                     'Will be derived from input file otherwise.'))
56 @click.option('--allow-unsafe', is_flag=True, default=False,
57               help="Pin packages considered unsafe: {}".format(', '.join(sorted(UNSAFE_PACKAGES))))
58 @click.option('--generate-hashes', is_flag=True, default=False,
59               help="Generate pip 8 style hashes in the resulting requirements file.")
60 @click.option('--max-rounds', default=10,
61               help="Maximum number of rounds before resolving the requirements aborts.")
62 @click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True))
63 def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
64         cert, client_cert, trusted_host, header, index, emit_trusted_host, annotate,
65         upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes,
66         src_files, max_rounds):
67     """Compiles requirements.txt from requirements.in specs."""
68     log.verbosity = verbose - quiet
69 
70     if len(src_files) == 0:
71         if os.path.exists(DEFAULT_REQUIREMENTS_FILE):
72             src_files = (DEFAULT_REQUIREMENTS_FILE,)
73         elif os.path.exists('setup.py'):
74             src_files = ('setup.py',)
75             if not output_file:
76                 output_file = 'requirements.txt'
77         else:
78             raise click.BadParameter(("If you do not specify an input file, "
79                                       "the default is {} or setup.py").format(DEFAULT_REQUIREMENTS_FILE))
80 
81     if len(src_files) == 1 and src_files[0] == '-':
82         if not output_file:
83             raise click.BadParameter('--output-file is required if input is from stdin')
84 
85     if len(src_files) > 1 and not output_file:
86         raise click.BadParameter('--output-file is required if two or more input files are given.')
87 
88     if output_file:
89         dst_file = output_file
90     else:
91         base_name = src_files[0].rsplit('.', 1)[0]
92         dst_file = base_name + '.txt'
93 
94     if upgrade and upgrade_packages:
95         raise click.BadParameter('Only one of --upgrade or --upgrade-package can be provided as an argument.')
96 
97     ###
98     # Setup
99     ###
100 
101     pip_command = get_pip_command()
102 
103     pip_args = []
104     if find_links:
105         for link in find_links:
106             pip_args.extend(['-f', link])
107     if index_url:
108         pip_args.extend(['-i', index_url])
109     if extra_index_url:
110         for extra_index in extra_index_url:
111             pip_args.extend(['--extra-index-url', extra_index])
112     if cert:
113         pip_args.extend(['--cert', cert])
114     if client_cert:
115         pip_args.extend(['--client-cert', client_cert])
116     if pre:
117         pip_args.extend(['--pre'])
118     if trusted_host:
119         for host in trusted_host:
120             pip_args.extend(['--trusted-host', host])
121 
122     pip_options, _ = pip_command.parse_args(pip_args)
123 
124     session = pip_command._build_session(pip_options)
125     repository = PyPIRepository(pip_options, session)
126 
127     upgrade_install_reqs = {}
128     # Proxy with a LocalRequirementsRepository if --upgrade is not specified
129     # (= default invocation)
130     if not upgrade and os.path.exists(dst_file):
131         ireqs = parse_requirements(dst_file, finder=repository.finder, session=repository.session, options=pip_options)
132         # Exclude packages from --upgrade-package/-P from the existing pins: We want to upgrade.
133         upgrade_reqs_gen = (install_req_from_line(pkg) for pkg in upgrade_packages)
134         upgrade_install_reqs = {key_from_req(install_req.req): install_req for install_req in upgrade_reqs_gen}
135 
136         existing_pins = {key_from_req(ireq.req): ireq
137                          for ireq in ireqs
138                          if is_pinned_requirement(ireq) and key_from_req(ireq.req) not in upgrade_install_reqs}
139         repository = LocalRequirementsRepository(existing_pins, repository)
140 
141     log.debug('Using indexes:')
142     # remove duplicate index urls before processing
143     repository.finder.index_urls = list(dedup(repository.finder.index_urls))
144     for index_url in repository.finder.index_urls:
145         log.debug('  {}'.format(index_url))
146 
147     if repository.finder.find_links:
148         log.debug('')
149         log.debug('Configuration:')
150         for find_link in repository.finder.find_links:
151             log.debug('  -f {}'.format(find_link))
152 
153     ###
154     # Parsing/collecting initial requirements
155     ###
156 
157     constraints = []
158     for src_file in src_files:
159         is_setup_file = os.path.basename(src_file) == 'setup.py'
160         if is_setup_file or src_file == '-':
161             # pip requires filenames and not files. Since we want to support
162             # piping from stdin, we need to briefly save the input from stdin
163             # to a temporary file and have pip read that.  also used for
164             # reading requirements from install_requires in setup.py.
165             tmpfile = tempfile.NamedTemporaryFile(mode='wt', delete=False)
166             if is_setup_file:
167                 from distutils.core import run_setup
168                 dist = run_setup(src_file)
169                 tmpfile.write('\n'.join(dist.install_requires))
170             else:
171                 tmpfile.write(sys.stdin.read())
172             tmpfile.flush()
173             constraints.extend(parse_requirements(
174                 tmpfile.name, finder=repository.finder, session=repository.session, options=pip_options))
175         else:
176             constraints.extend(parse_requirements(
177                 src_file, finder=repository.finder, session=repository.session, options=pip_options))
178 
179     constraints.extend(upgrade_install_reqs.values())
180 
181     # Filter out pip environment markers which do not match (PEP496)
182     constraints = [req for req in constraints
183                    if req.markers is None or req.markers.evaluate()]
184 
185     # Check the given base set of constraints first
186     Resolver.check_constraints(constraints)
187 
188     try:
189         resolver = Resolver(constraints, repository, prereleases=pre,
190                             clear_caches=rebuild, allow_unsafe=allow_unsafe)
191         results = resolver.resolve(max_rounds=max_rounds)
192         if generate_hashes:
193             hashes = resolver.resolve_hashes(results)
194         else:
195             hashes = None
196     except PipToolsError as e:
197         log.error(str(e))
198         sys.exit(2)
199 
200     log.debug('')
201 
202     ##
203     # Output
204     ##
205 
206     # Compute reverse dependency annotations statically, from the
207     # dependency cache that the resolver has populated by now.
208     #
209     # TODO (1a): reverse deps for any editable package are lost
210     #            what SHOULD happen is that they are cached in memory, just
211     #            not persisted to disk!
212     #
213     # TODO (1b): perhaps it's easiest if the dependency cache has an API
214     #            that could take InstallRequirements directly, like:
215     #
216     #                cache.set(ireq, ...)
217     #
218     #            then, when ireq is editable, it would store in
219     #
220     #              editables[egg_name][link_without_fragment] = deps
221     #              editables['pip-tools']['git+...ols.git@future'] = {'click>=3.0', 'six'}
222     #
223     #            otherwise:
224     #
225     #              self[as_name_version_tuple(ireq)] = {'click>=3.0', 'six'}
226     #
227     reverse_dependencies = None
228     if annotate:
229         reverse_dependencies = resolver.reverse_dependencies(results)
230 
231     writer = OutputWriter(src_files, dst_file, dry_run=dry_run,
232                           emit_header=header, emit_index=index,
233                           emit_trusted_host=emit_trusted_host,
234                           annotate=annotate,
235                           generate_hashes=generate_hashes,
236                           default_index_url=repository.DEFAULT_INDEX_URL,
237                           index_urls=repository.finder.index_urls,
238                           trusted_hosts=pip_options.trusted_hosts,
239                           format_control=repository.finder.format_control,
240                           allow_unsafe=allow_unsafe)
241     writer.write(results=results,
242                  unsafe_requirements=resolver.unsafe_constraints,
243                  reverse_dependencies=reverse_dependencies,
244                  primary_packages={key_from_req(ireq.req) for ireq in constraints if not ireq.constraint},
245                  markers={key_from_req(ireq.req): ireq.markers
246                           for ireq in constraints if ireq.markers},
247                  hashes=hashes)
248 
249     if dry_run:
250         log.warning('Dry-run, so nothing updated.')
251
```
--- 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/piptools/scripts/compile.py b/piptools/scripts/compile.py
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -21,6 +21,7 @@
 from ..writer import OutputWriter
 
 DEFAULT_REQUIREMENTS_FILE = 'requirements.in'
+DEFAULT_REQUIREMENTS_OUTPUT_FILE = 'requirements.txt'
 
 
 @click.command()
@@ -72,15 +73,14 @@
             src_files = (DEFAULT_REQUIREMENTS_FILE,)
         elif os.path.exists('setup.py'):
             src_files = ('setup.py',)
-            if not output_file:
-                output_file = 'requirements.txt'
         else:
             raise click.BadParameter(("If you do not specify an input file, "
                                       "the default is {} or setup.py").format(DEFAULT_REQUIREMENTS_FILE))
 
-    if len(src_files) == 1 and src_files[0] == '-':
-        if not output_file:
-            raise click.BadParameter('--output-file is required if input is from stdin')
+    if src_files == ('-',) and not output_file:
+        raise click.BadParameter('--output-file is required if input is from stdin')
+    elif src_files == ('setup.py',):
+        output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE
 
     if len(src_files) > 1 and not output_file:
         raise click.BadParameter('--output-file is required if two or more input files are given.')

{"golden_diff": "diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py\n--- a/piptools/scripts/compile.py\n+++ b/piptools/scripts/compile.py\n@@ -21,6 +21,7 @@\n from ..writer import OutputWriter\n \n DEFAULT_REQUIREMENTS_FILE = 'requirements.in'\n+DEFAULT_REQUIREMENTS_OUTPUT_FILE = 'requirements.txt'\n \n \n @click.command()\n@@ -72,15 +73,14 @@\n             src_files = (DEFAULT_REQUIREMENTS_FILE,)\n         elif os.path.exists('setup.py'):\n             src_files = ('setup.py',)\n-            if not output_file:\n-                output_file = 'requirements.txt'\n         else:\n             raise click.BadParameter((\"If you do not specify an input file, \"\n                                       \"the default is {} or setup.py\").format(DEFAULT_REQUIREMENTS_FILE))\n \n-    if len(src_files) == 1 and src_files[0] == '-':\n-        if not output_file:\n-            raise click.BadParameter('--output-file is required if input is from stdin')\n+    if src_files == ('-',) and not output_file:\n+        raise click.BadParameter('--output-file is required if input is from stdin')\n+    elif src_files == ('setup.py',):\n+        output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE\n \n     if len(src_files) > 1 and not output_file:\n         raise click.BadParameter('--output-file is required if two or more input files are given.')\n", "issue": "pip-compile generates setup.txt by given explicitly setup.py in a source file\nThere is a possible wrong behavior on a command `pip-compile setup.py`, because it generates `setup.txt` file instead of `requirements.txt`.\r\n\r\n##### Environment Versions\r\n\r\n1. OS Type: Any (tested on MacOSX)\r\n1. Python version: 3.7.x\r\n1. pip version:  19.1\r\n1. pip-tools version: 3.3.2\r\n\r\n##### Steps to replicate\r\n\r\n1. Prepare a `setup.py` file:\r\n```\r\ncat << EOF > setup.py\r\nfrom setuptools import setup\r\nsetup(install_requires=[])\r\nEOF\r\n```\r\n2. Run: `pip-compile setup.py`\r\n\r\n##### Expected result\r\n\r\n```\r\n#\r\n# This file is autogenerated by pip-compile\r\n# To update, run:\r\n#\r\n#    pip-compile --output-file requirements.txt setup.py\r\n#\r\n```\r\n\r\n##### Actual result\r\n\r\n```\r\n#\r\n# This file is autogenerated by pip-compile\r\n# To update, run:\r\n#\r\n#    pip-compile --output-file setup.txt setup.py\r\n#\r\n```\r\n\n", "before_files": [{"content": "# coding: utf-8\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\n\nimport os\nimport sys\nimport tempfile\n\nfrom .._compat import (\n    install_req_from_line,\n    parse_requirements,\n)\n\nfrom .. import click\nfrom ..exceptions import PipToolsError\nfrom ..logging import log\nfrom ..pip import get_pip_command, pip_defaults\nfrom ..repositories import LocalRequirementsRepository, PyPIRepository\nfrom ..resolver import Resolver\nfrom ..utils import (dedup, is_pinned_requirement, key_from_req, UNSAFE_PACKAGES)\nfrom ..writer import OutputWriter\n\nDEFAULT_REQUIREMENTS_FILE = 'requirements.in'\n\n\n@click.command()\n@click.version_option()\n@click.option('-v', '--verbose', count=True, help=\"Show more output\")\n@click.option('-q', '--quiet', count=True, help=\"Give less output\")\n@click.option('-n', '--dry-run', is_flag=True, help=\"Only show what would happen, don't change anything\")\n@click.option('-p', '--pre', is_flag=True, default=None, help=\"Allow resolving to prereleases (default is not)\")\n@click.option('-r', '--rebuild', is_flag=True, help=\"Clear any caches upfront, rebuild from scratch\")\n@click.option('-f', '--find-links', multiple=True, help=\"Look for archives in this directory or on this HTML page\", envvar='PIP_FIND_LINKS')  # noqa\n@click.option('-i', '--index-url', help=\"Change index URL (defaults to {})\".format(pip_defaults.index_url), envvar='PIP_INDEX_URL')  # noqa\n@click.option('--extra-index-url', multiple=True, help=\"Add additional index URL to search\", envvar='PIP_EXTRA_INDEX_URL')  # noqa\n@click.option('--cert', help=\"Path to alternate CA bundle.\")\n@click.option('--client-cert', help=\"Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.\")  # noqa\n@click.option('--trusted-host', multiple=True, envvar='PIP_TRUSTED_HOST',\n              help=\"Mark this host as trusted, even though it does not have \"\n                   \"valid or any HTTPS.\")\n@click.option('--header/--no-header', is_flag=True, default=True,\n              help=\"Add header to generated file\")\n@click.option('--index/--no-index', is_flag=True, default=True,\n              help=\"Add index URL to generated file\")\n@click.option('--emit-trusted-host/--no-emit-trusted-host', is_flag=True,\n              default=True, help=\"Add trusted host option to generated file\")\n@click.option('--annotate/--no-annotate', is_flag=True, default=True,\n              help=\"Annotate results, indicating where dependencies come from\")\n@click.option('-U', '--upgrade', is_flag=True, default=False,\n              help='Try to upgrade all dependencies to their latest versions')\n@click.option('-P', '--upgrade-package', 'upgrade_packages', nargs=1, multiple=True,\n              help=\"Specify particular packages to upgrade.\")\n@click.option('-o', '--output-file', nargs=1, type=str, default=None,\n              help=('Output file name. Required if more than one input file is given. '\n                    'Will be derived from input file otherwise.'))\n@click.option('--allow-unsafe', is_flag=True, default=False,\n              help=\"Pin packages considered unsafe: {}\".format(', '.join(sorted(UNSAFE_PACKAGES))))\n@click.option('--generate-hashes', is_flag=True, default=False,\n              help=\"Generate pip 8 style hashes in the resulting requirements file.\")\n@click.option('--max-rounds', default=10,\n              help=\"Maximum number of rounds before resolving the requirements aborts.\")\n@click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True))\ndef cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_index_url,\n        cert, client_cert, trusted_host, header, index, emit_trusted_host, annotate,\n        upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes,\n        src_files, max_rounds):\n    \"\"\"Compiles requirements.txt from requirements.in specs.\"\"\"\n    log.verbosity = verbose - quiet\n\n    if len(src_files) == 0:\n        if os.path.exists(DEFAULT_REQUIREMENTS_FILE):\n            src_files = (DEFAULT_REQUIREMENTS_FILE,)\n        elif os.path.exists('setup.py'):\n            src_files = ('setup.py',)\n            if not output_file:\n                output_file = 'requirements.txt'\n        else:\n            raise click.BadParameter((\"If you do not specify an input file, \"\n                                      \"the default is {} or setup.py\").format(DEFAULT_REQUIREMENTS_FILE))\n\n    if len(src_files) == 1 and src_files[0] == '-':\n        if not output_file:\n            raise click.BadParameter('--output-file is required if input is from stdin')\n\n    if len(src_files) > 1 and not output_file:\n        raise click.BadParameter('--output-file is required if two or more input files are given.')\n\n    if output_file:\n        dst_file = output_file\n    else:\n        base_name = src_files[0].rsplit('.', 1)[0]\n        dst_file = base_name + '.txt'\n\n    if upgrade and upgrade_packages:\n        raise click.BadParameter('Only one of --upgrade or --upgrade-package can be provided as an argument.')\n\n    ###\n    # Setup\n    ###\n\n    pip_command = get_pip_command()\n\n    pip_args = []\n    if find_links:\n        for link in find_links:\n            pip_args.extend(['-f', link])\n    if index_url:\n        pip_args.extend(['-i', index_url])\n    if extra_index_url:\n        for extra_index in extra_index_url:\n            pip_args.extend(['--extra-index-url', extra_index])\n    if cert:\n        pip_args.extend(['--cert', cert])\n    if client_cert:\n        pip_args.extend(['--client-cert', client_cert])\n    if pre:\n        pip_args.extend(['--pre'])\n    if trusted_host:\n        for host in trusted_host:\n            pip_args.extend(['--trusted-host', host])\n\n    pip_options, _ = pip_command.parse_args(pip_args)\n\n    session = pip_command._build_session(pip_options)\n    repository = PyPIRepository(pip_options, session)\n\n    upgrade_install_reqs = {}\n    # Proxy with a LocalRequirementsRepository if --upgrade is not specified\n    # (= default invocation)\n    if not upgrade and os.path.exists(dst_file):\n        ireqs = parse_requirements(dst_file, finder=repository.finder, session=repository.session, options=pip_options)\n        # Exclude packages from --upgrade-package/-P from the existing pins: We want to upgrade.\n        upgrade_reqs_gen = (install_req_from_line(pkg) for pkg in upgrade_packages)\n        upgrade_install_reqs = {key_from_req(install_req.req): install_req for install_req in upgrade_reqs_gen}\n\n        existing_pins = {key_from_req(ireq.req): ireq\n                         for ireq in ireqs\n                         if is_pinned_requirement(ireq) and key_from_req(ireq.req) not in upgrade_install_reqs}\n        repository = LocalRequirementsRepository(existing_pins, repository)\n\n    log.debug('Using indexes:')\n    # remove duplicate index urls before processing\n    repository.finder.index_urls = list(dedup(repository.finder.index_urls))\n    for index_url in repository.finder.index_urls:\n        log.debug('  {}'.format(index_url))\n\n    if repository.finder.find_links:\n        log.debug('')\n        log.debug('Configuration:')\n        for find_link in repository.finder.find_links:\n            log.debug('  -f {}'.format(find_link))\n\n    ###\n    # Parsing/collecting initial requirements\n    ###\n\n    constraints = []\n    for src_file in src_files:\n        is_setup_file = os.path.basename(src_file) == 'setup.py'\n        if is_setup_file or src_file == '-':\n            # pip requires filenames and not files. Since we want to support\n            # piping from stdin, we need to briefly save the input from stdin\n            # to a temporary file and have pip read that.  also used for\n            # reading requirements from install_requires in setup.py.\n            tmpfile = tempfile.NamedTemporaryFile(mode='wt', delete=False)\n            if is_setup_file:\n                from distutils.core import run_setup\n                dist = run_setup(src_file)\n                tmpfile.write('\\n'.join(dist.install_requires))\n            else:\n                tmpfile.write(sys.stdin.read())\n            tmpfile.flush()\n            constraints.extend(parse_requirements(\n                tmpfile.name, finder=repository.finder, session=repository.session, options=pip_options))\n        else:\n            constraints.extend(parse_requirements(\n                src_file, finder=repository.finder, session=repository.session, options=pip_options))\n\n    constraints.extend(upgrade_install_reqs.values())\n\n    # Filter out pip environment markers which do not match (PEP496)\n    constraints = [req for req in constraints\n                   if req.markers is None or req.markers.evaluate()]\n\n    # Check the given base set of constraints first\n    Resolver.check_constraints(constraints)\n\n    try:\n        resolver = Resolver(constraints, repository, prereleases=pre,\n                            clear_caches=rebuild, allow_unsafe=allow_unsafe)\n        results = resolver.resolve(max_rounds=max_rounds)\n        if generate_hashes:\n            hashes = resolver.resolve_hashes(results)\n        else:\n            hashes = None\n    except PipToolsError as e:\n        log.error(str(e))\n        sys.exit(2)\n\n    log.debug('')\n\n    ##\n    # Output\n    ##\n\n    # Compute reverse dependency annotations statically, from the\n    # dependency cache that the resolver has populated by now.\n    #\n    # TODO (1a): reverse deps for any editable package are lost\n    #            what SHOULD happen is that they are cached in memory, just\n    #            not persisted to disk!\n    #\n    # TODO (1b): perhaps it's easiest if the dependency cache has an API\n    #            that could take InstallRequirements directly, like:\n    #\n    #                cache.set(ireq, ...)\n    #\n    #            then, when ireq is editable, it would store in\n    #\n    #              editables[egg_name][link_without_fragment] = deps\n    #              editables['pip-tools']['git+...ols.git@future'] = {'click>=3.0', 'six'}\n    #\n    #            otherwise:\n    #\n    #              self[as_name_version_tuple(ireq)] = {'click>=3.0', 'six'}\n    #\n    reverse_dependencies = None\n    if annotate:\n        reverse_dependencies = resolver.reverse_dependencies(results)\n\n    writer = OutputWriter(src_files, dst_file, dry_run=dry_run,\n                          emit_header=header, emit_index=index,\n                          emit_trusted_host=emit_trusted_host,\n                          annotate=annotate,\n                          generate_hashes=generate_hashes,\n                          default_index_url=repository.DEFAULT_INDEX_URL,\n                          index_urls=repository.finder.index_urls,\n                          trusted_hosts=pip_options.trusted_hosts,\n                          format_control=repository.finder.format_control,\n                          allow_unsafe=allow_unsafe)\n    writer.write(results=results,\n                 unsafe_requirements=resolver.unsafe_constraints,\n                 reverse_dependencies=reverse_dependencies,\n                 primary_packages={key_from_req(ireq.req) for ireq in constraints if not ireq.constraint},\n                 markers={key_from_req(ireq.req): ireq.markers\n                          for ireq in constraints if ireq.markers},\n                 hashes=hashes)\n\n    if dry_run:\n        log.warning('Dry-run, so nothing updated.')\n", "path": "piptools/scripts/compile.py"}], "after_files": [{"content": "# coding: utf-8\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\n\nimport os\nimport sys\nimport tempfile\n\nfrom .._compat import (\n    install_req_from_line,\n    parse_requirements,\n)\n\nfrom .. import click\nfrom ..exceptions import PipToolsError\nfrom ..logging import log\nfrom ..pip import get_pip_command, pip_defaults\nfrom ..repositories import LocalRequirementsRepository, PyPIRepository\nfrom ..resolver import Resolver\nfrom ..utils import (dedup, is_pinned_requirement, key_from_req, UNSAFE_PACKAGES)\nfrom ..writer import OutputWriter\n\nDEFAULT_REQUIREMENTS_FILE = 'requirements.in'\nDEFAULT_REQUIREMENTS_OUTPUT_FILE = 'requirements.txt'\n\n\n@click.command()\n@click.version_option()\n@click.option('-v', '--verbose', count=True, help=\"Show more output\")\n@click.option('-q', '--quiet', count=True, help=\"Give less output\")\n@click.option('-n', '--dry-run', is_flag=True, help=\"Only show what would happen, don't change anything\")\n@click.option('-p', '--pre', is_flag=True, default=None, help=\"Allow resolving to prereleases (default is not)\")\n@click.option('-r', '--rebuild', is_flag=True, help=\"Clear any caches upfront, rebuild from scratch\")\n@click.option('-f', '--find-links', multiple=True, help=\"Look for archives in this directory or on this HTML page\", envvar='PIP_FIND_LINKS')  # noqa\n@click.option('-i', '--index-url', help=\"Change index URL (defaults to {})\".format(pip_defaults.index_url), envvar='PIP_INDEX_URL')  # noqa\n@click.option('--extra-index-url', multiple=True, help=\"Add additional index URL to search\", envvar='PIP_EXTRA_INDEX_URL')  # noqa\n@click.option('--cert', help=\"Path to alternate CA bundle.\")\n@click.option('--client-cert', help=\"Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.\")  # noqa\n@click.option('--trusted-host', multiple=True, envvar='PIP_TRUSTED_HOST',\n              help=\"Mark this host as trusted, even though it does not have \"\n                   \"valid or any HTTPS.\")\n@click.option('--header/--no-header', is_flag=True, default=True,\n              help=\"Add header to generated file\")\n@click.option('--index/--no-index', is_flag=True, default=True,\n              help=\"Add index URL to generated file\")\n@click.option('--emit-trusted-host/--no-emit-trusted-host', is_flag=True,\n              default=True, help=\"Add trusted host option to generated file\")\n@click.option('--annotate/--no-annotate', is_flag=True, default=True,\n              help=\"Annotate results, indicating where dependencies come from\")\n@click.option('-U', '--upgrade', is_flag=True, default=False,\n              help='Try to upgrade all dependencies to their latest versions')\n@click.option('-P', '--upgrade-package', 'upgrade_packages', nargs=1, multiple=True,\n              help=\"Specify particular packages to upgrade.\")\n@click.option('-o', '--output-file', nargs=1, type=str, default=None,\n              help=('Output file name. Required if more than one input file is given. '\n                    'Will be derived from input file otherwise.'))\n@click.option('--allow-unsafe', is_flag=True, default=False,\n              help=\"Pin packages considered unsafe: {}\".format(', '.join(sorted(UNSAFE_PACKAGES))))\n@click.option('--generate-hashes', is_flag=True, default=False,\n              help=\"Generate pip 8 style hashes in the resulting requirements file.\")\n@click.option('--max-rounds', default=10,\n              help=\"Maximum number of rounds before resolving the requirements aborts.\")\n@click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True))\ndef cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_index_url,\n        cert, client_cert, trusted_host, header, index, emit_trusted_host, annotate,\n        upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes,\n        src_files, max_rounds):\n    \"\"\"Compiles requirements.txt from requirements.in specs.\"\"\"\n    log.verbosity = verbose - quiet\n\n    if len(src_files) == 0:\n        if os.path.exists(DEFAULT_REQUIREMENTS_FILE):\n            src_files = (DEFAULT_REQUIREMENTS_FILE,)\n        elif os.path.exists('setup.py'):\n            src_files = ('setup.py',)\n        else:\n            raise click.BadParameter((\"If you do not specify an input file, \"\n                                      \"the default is {} or setup.py\").format(DEFAULT_REQUIREMENTS_FILE))\n\n    if src_files == ('-',) and not output_file:\n        raise click.BadParameter('--output-file is required if input is from stdin')\n    elif src_files == ('setup.py',):\n        output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE\n\n    if len(src_files) > 1 and not output_file:\n        raise click.BadParameter('--output-file is required if two or more input files are given.')\n\n    if output_file:\n        dst_file = output_file\n    else:\n        base_name = src_files[0].rsplit('.', 1)[0]\n        dst_file = base_name + '.txt'\n\n    if upgrade and upgrade_packages:\n        raise click.BadParameter('Only one of --upgrade or --upgrade-package can be provided as an argument.')\n\n    ###\n    # Setup\n    ###\n\n    pip_command = get_pip_command()\n\n    pip_args = []\n    if find_links:\n        for link in find_links:\n            pip_args.extend(['-f', link])\n    if index_url:\n        pip_args.extend(['-i', index_url])\n    if extra_index_url:\n        for extra_index in extra_index_url:\n            pip_args.extend(['--extra-index-url', extra_index])\n    if cert:\n        pip_args.extend(['--cert', cert])\n    if client_cert:\n        pip_args.extend(['--client-cert', client_cert])\n    if pre:\n        pip_args.extend(['--pre'])\n    if trusted_host:\n        for host in trusted_host:\n            pip_args.extend(['--trusted-host', host])\n\n    pip_options, _ = pip_command.parse_args(pip_args)\n\n    session = pip_command._build_session(pip_options)\n    repository = PyPIRepository(pip_options, session)\n\n    upgrade_install_reqs = {}\n    # Proxy with a LocalRequirementsRepository if --upgrade is not specified\n    # (= default invocation)\n    if not upgrade and os.path.exists(dst_file):\n        ireqs = parse_requirements(dst_file, finder=repository.finder, session=repository.session, options=pip_options)\n        # Exclude packages from --upgrade-package/-P from the existing pins: We want to upgrade.\n        upgrade_reqs_gen = (install_req_from_line(pkg) for pkg in upgrade_packages)\n        upgrade_install_reqs = {key_from_req(install_req.req): install_req for install_req in upgrade_reqs_gen}\n\n        existing_pins = {key_from_req(ireq.req): ireq\n                         for ireq in ireqs\n                         if is_pinned_requirement(ireq) and key_from_req(ireq.req) not in upgrade_install_reqs}\n        repository = LocalRequirementsRepository(existing_pins, repository)\n\n    log.debug('Using indexes:')\n    # remove duplicate index urls before processing\n    repository.finder.index_urls = list(dedup(repository.finder.index_urls))\n    for index_url in repository.finder.index_urls:\n        log.debug('  {}'.format(index_url))\n\n    if repository.finder.find_links:\n        log.debug('')\n        log.debug('Configuration:')\n        for find_link in repository.finder.find_links:\n            log.debug('  -f {}'.format(find_link))\n\n    ###\n    # Parsing/collecting initial requirements\n    ###\n\n    constraints = []\n    for src_file in src_files:\n        is_setup_file = os.path.basename(src_file) == 'setup.py'\n        if is_setup_file or src_file == '-':\n            # pip requires filenames and not files. Since we want to support\n            # piping from stdin, we need to briefly save the input from stdin\n            # to a temporary file and have pip read that.  also used for\n            # reading requirements from install_requires in setup.py.\n            tmpfile = tempfile.NamedTemporaryFile(mode='wt', delete=False)\n            if is_setup_file:\n                from distutils.core import run_setup\n                dist = run_setup(src_file)\n                tmpfile.write('\\n'.join(dist.install_requires))\n            else:\n                tmpfile.write(sys.stdin.read())\n            tmpfile.flush()\n            constraints.extend(parse_requirements(\n                tmpfile.name, finder=repository.finder, session=repository.session, options=pip_options))\n        else:\n            constraints.extend(parse_requirements(\n                src_file, finder=repository.finder, session=repository.session, options=pip_options))\n\n    constraints.extend(upgrade_install_reqs.values())\n\n    # Filter out pip environment markers which do not match (PEP496)\n    constraints = [req for req in constraints\n                   if req.markers is None or req.markers.evaluate()]\n\n    # Check the given base set of constraints first\n    Resolver.check_constraints(constraints)\n\n    try:\n        resolver = Resolver(constraints, repository, prereleases=pre,\n                            clear_caches=rebuild, allow_unsafe=allow_unsafe)\n        results = resolver.resolve(max_rounds=max_rounds)\n        if generate_hashes:\n            hashes = resolver.resolve_hashes(results)\n        else:\n            hashes = None\n    except PipToolsError as e:\n        log.error(str(e))\n        sys.exit(2)\n\n    log.debug('')\n\n    ##\n    # Output\n    ##\n\n    # Compute reverse dependency annotations statically, from the\n    # dependency cache that the resolver has populated by now.\n    #\n    # TODO (1a): reverse deps for any editable package are lost\n    #            what SHOULD happen is that they are cached in memory, just\n    #            not persisted to disk!\n    #\n    # TODO (1b): perhaps it's easiest if the dependency cache has an API\n    #            that could take InstallRequirements directly, like:\n    #\n    #                cache.set(ireq, ...)\n    #\n    #            then, when ireq is editable, it would store in\n    #\n    #              editables[egg_name][link_without_fragment] = deps\n    #              editables['pip-tools']['git+...ols.git@future'] = {'click>=3.0', 'six'}\n    #\n    #            otherwise:\n    #\n    #              self[as_name_version_tuple(ireq)] = {'click>=3.0', 'six'}\n    #\n    reverse_dependencies = None\n    if annotate:\n        reverse_dependencies = resolver.reverse_dependencies(results)\n\n    writer = OutputWriter(src_files, dst_file, dry_run=dry_run,\n                          emit_header=header, emit_index=index,\n                          emit_trusted_host=emit_trusted_host,\n                          annotate=annotate,\n                          generate_hashes=generate_hashes,\n                          default_index_url=repository.DEFAULT_INDEX_URL,\n                          index_urls=repository.finder.index_urls,\n                          trusted_hosts=pip_options.trusted_hosts,\n                          format_control=repository.finder.format_control,\n                          allow_unsafe=allow_unsafe)\n    writer.write(results=results,\n                 unsafe_requirements=resolver.unsafe_constraints,\n                 reverse_dependencies=reverse_dependencies,\n                 primary_packages={key_from_req(ireq.req) for ireq in constraints if not ireq.constraint},\n                 markers={key_from_req(ireq.req): ireq.markers\n                          for ireq in constraints if ireq.markers},\n                 hashes=hashes)\n\n    if dry_run:\n        log.warning('Dry-run, so nothing updated.')\n", "path": "piptools/scripts/compile.py"}]}