Skip to content

Commit

Permalink
Add --no-allow-unsafe option to compile (#1265)
Browse files Browse the repository at this point in the history
In future versions of pip-tools, the --allow-unsafe behavior will used
by default. Adding the --no-allow-unsafe option now allows users to
continue using the old behavior in a backward compatible way.

Refs #989
  • Loading branch information
jdufresne authored Dec 30, 2020
1 parent bc9695c commit 4ac1490
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ This section lists ``pip-tools`` features that are currently deprecated.
- ``--index/--no-index`` command-line options, use instead
``--emit-index-url/--no-emit-index-url`` (since 5.2.0).

- In future versions, the ``--allow-unsafe`` behavior will be enabled by
default. Use ``--no-allow-unsafe`` to keep the old behavior. It is
recommended to pass the ``--allow-unsafe`` now to adapt to the upcoming
change.

Versions and compatibility
==========================

Expand Down
11 changes: 8 additions & 3 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ def has_arg(self, arg_name):
),
)
@click.option(
"--allow-unsafe",
"--allow-unsafe/--no-allow-unsafe",
is_flag=True,
default=False,
help="Pin packages considered unsafe: {}".format(
", ".join(sorted(UNSAFE_PACKAGES))
help=(
"Pin packages considered unsafe: {}.\n\n"
"WARNING: Future versions of pip-tools will enable this behavior by default. "
"Use --no-allow-unsafe to keep the old behavior. It is recommended to pass the "
"--allow-unsafe now to adapt to the upcoming change.".format(
", ".join(sorted(UNSAFE_PACKAGES))
)
),
)
@click.option(
Expand Down
6 changes: 5 additions & 1 deletion tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,11 @@ def test_annotate_option(pip_conf, runner, option, expected):

@pytest.mark.parametrize(
("option", "expected"),
(("--allow-unsafe", "small-fake-a==0.1"), (None, "# small-fake-a")),
(
("--allow-unsafe", "small-fake-a==0.1"),
("--no-allow-unsafe", "# small-fake-a"),
(None, "# small-fake-a"),
),
)
def test_allow_unsafe_option(pip_conf, monkeypatch, runner, option, expected):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def test_force_text(value, expected_text):
(["--no-emit-index-url"], "pip-compile --no-emit-index-url"),
(["--no-emit-trusted-host"], "pip-compile --no-emit-trusted-host"),
(["--no-annotate"], "pip-compile --no-annotate"),
(["--no-allow-unsafe"], "pip-compile"),
# Check that default values will be removed from the command
(["--emit-trusted-host"], "pip-compile"),
(["--annotate"], "pip-compile"),
Expand Down

0 comments on commit 4ac1490

Please sign in to comment.