Skip to content

Commit

Permalink
Built in discovery class is always preferred over plugin supplied cla…
Browse files Browse the repository at this point in the history
…sses (#2088)
  • Loading branch information
AWhetter authored Apr 20, 2021
1 parent f198a65 commit 625d5d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2087.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Built in discovery class is always preferred over plugin supplied classes.
7 changes: 5 additions & 2 deletions src/virtualenv/run/plugin/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def get_discover(parser, args):
title="discovery",
description="discover and provide a target interpreter",
)
choices = _get_default_discovery(discover_types)
# prefer the builtin if present, otherwise fallback to first defined type
choices = sorted(choices, key=lambda a: 0 if a == "builtin" else 1)
discovery_parser.add_argument(
"--discovery",
choices=_get_default_discovery(discover_types),
default=next(i for i in discover_types.keys()),
choices=choices,
default=next(iter(choices)),
required=False,
help="interpreter discovery method",
)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/config/cli/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ def test_reset_app_data_does_not_conflict_clear():
session_via_cli(["--clear", "venv"], options=options)
assert options.clear is True
assert options.reset_app_data is False


def test_builtin_discovery_class_preferred(mocker):
mocker.patch(
"virtualenv.run.plugin.discovery._get_default_discovery",
return_value=["pluginA", "pluginX", "builtin", "Aplugin", "Xplugin"],
)

options = VirtualEnvOptions()
session_via_cli(["venv"], options=options)
assert options.discovery == "builtin"

0 comments on commit 625d5d8

Please sign in to comment.