Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

@AWhetter AWhetter Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines have been borrowed from here:

# prefer the built-in venv 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"