Repository: jazzband/pip-tools (python)

Issue:
Option --pre doesn't work in requirements.in
The option `--pre` set in `requirements.in` doesn't work as expected. Neither `--pre package` or `package==0.0.1 --pre`. If `--pre` passed to the CLI it works like a charm. It seems `PyPIRepository` doesn't respect `PackageFinder.allow_all_prereleases` parameter.

##### Environment Versions

1. OS Type MacOS 10.14.3
2. Python version: 3.7.3
3. pip version:  pip 19.1.1 from /Projects/pip-tools/.venv/lib/python3.7/site-packages/pip (python 3.7)
4. pip-tools version: pip-compile, version 3.7.0

##### Steps to replicate

1. requirements.in:
```
cat << EOF > requirements.in
--pre django
django<2.2rc1 --pre
EOF
```
2. `pip-compile -rqo-`

##### Expected result

```
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file=-
#
django==2.2b1
pytz==2019.1              # via django
sqlparse==0.3.0           # via django
```

##### Actual result

```
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file=-
#
django==2.1.8
pytz==2019.1              # via django
```


##### Works fine with

```
$ pip-compile -rqo- --pre
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file=- --pre
#
django==2.2b1
pytz==2019.1              # via django
sqlparse==0.3.0           # via django
```


Pull request description:
Respect --pre option in requirements.in file
Fixes #819.

**Changelog-friendly one-liner**: Respect `--pre` option in a `requirements.in` file

##### Contributor checklist

- [X] Provided the tests for the changes.
- [x] Requested a review from another contributor.
- [X] Gave a clear one-line description in the PR (that the maintainers can add to CHANGELOG.md on release).
- [x] Assign the PR to an existing or new milestone for the target version (following [Semantic Versioning](https://blog.versioneye.com/2014/01/16/semantic-versioning/)).


Patch:
diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py
index 8e4e6a0..a959d2e 100755
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -348,7 +348,7 @@ def cli(
         resolver = Resolver(
             constraints,
             repository,
-            prereleases=pre,
+            prereleases=repository.finder.allow_all_prereleases or pre,
             clear_caches=rebuild,
             allow_unsafe=allow_unsafe,
         )


Test patch:
diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py
index 542ff45..46b1463 100644
--- a/tests/test_cli_compile.py
+++ b/tests/test_cli_compile.py
@@ -649,22 +649,28 @@ def test_build_isolation_option(MockPyPIRepository, runner, option, expected):
 
 
 @pytest.mark.parametrize(
-    "pre_option, expected_package",
+    "cli_option, infile_option, expected_package",
     [
         # no --pre pip-compile should resolve to the last stable version
-        ([], "small-fake-a==0.2"),
+        (False, False, "small-fake-a==0.2"),
         # pip-compile --pre should resolve to the last pre-released version
-        (["-p"], "small-fake-a==0.3b1"),
+        (True, False, "small-fake-a==0.3b1"),
+        (False, True, "small-fake-a==0.3b1"),
+        (True, True, "small-fake-a==0.3b1"),
     ],
 )
-def test_pre_option(runner, pre_option, expected_package):
+def test_pre_option(runner, cli_option, infile_option, expected_package):
     """
     Tests pip-compile respects --pre option.
     """
     with open("requirements.in", "w") as req_in:
+        if infile_option:
+            req_in.write("--pre\n")
         req_in.write("small-fake-a\n")
 
-    out = runner.invoke(cli, ["-n", "-f", MINIMAL_WHEELS_PATH] + pre_option)
+    out = runner.invoke(
+        cli, ["-n", "-f", MINIMAL_WHEELS_PATH] + (["-p"] if cli_option else [])
+    )
 
     assert out.exit_code == 0, out.output
     assert expected_package in out.output.splitlines(), out.output