summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2022-05-19 22:45:41 (GMT)
committerGitHub <noreply@github.com>2022-05-19 22:45:41 (GMT)
commit73473fdeac3ff9d75ac9d189bb8552b7459812f1 (patch)
tree0cb9122b65efa21a2790a85105a2c9ee7969fba0 /PC
parent38feffa09c74d9a853745908b7813903bae33b96 (diff)
downloadcpython-73473fdeac3ff9d75ac9d189bb8552b7459812f1.zip
cpython-73473fdeac3ff9d75ac9d189bb8552b7459812f1.tar.gz
cpython-73473fdeac3ff9d75ac9d189bb8552b7459812f1.tar.bz2
gh-92817: Fix precedence of options to py.exe launcher (GH-92988)
Diffstat (limited to 'PC')
-rw-r--r--PC/launcher2.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/PC/launcher2.c b/PC/launcher2.c
index 35c932a..763bc13 100644
--- a/PC/launcher2.c
+++ b/PC/launcher2.c
@@ -386,6 +386,12 @@ typedef struct {
int tagLength;
// if true, treats 'tag' as a non-PEP 514 filter
bool oldStyleTag;
+ // if true, ignores 'tag' when a high priority environment is found
+ // gh-92817: This is currently set when a tag is read from configuration or
+ // the environment, rather than the command line or a shebang line, and the
+ // only currently possible high priority environment is an active virtual
+ // environment
+ bool lowPriorityTag;
// if true, we had an old-style tag with '-64' suffix, and so do not
// want to match tags like '3.x-32'
bool exclude32Bit;
@@ -475,6 +481,7 @@ dumpSearchInfo(SearchInfo *search)
DEBUG_2(company, companyLength);
DEBUG_2(tag, tagLength);
DEBUG_BOOL(oldStyleTag);
+ DEBUG_BOOL(lowPriorityTag);
DEBUG_BOOL(exclude32Bit);
DEBUG_BOOL(only32Bit);
DEBUG_BOOL(allowDefaults);
@@ -965,6 +972,9 @@ checkDefaults(SearchInfo *search)
if (!slash) {
search->tag = tag;
search->tagLength = n;
+ // gh-92817: allow a high priority env to be selected even if it
+ // doesn't match the tag
+ search->lowPriorityTag = true;
} else {
search->company = tag;
search->companyLength = (int)(slash - tag);
@@ -995,7 +1005,7 @@ typedef struct EnvironmentInfo {
const wchar_t *executableArgs;
const wchar_t *architecture;
const wchar_t *displayName;
- bool isActiveVenv;
+ bool highPriority;
} EnvironmentInfo;
@@ -1481,7 +1491,7 @@ virtualenvSearch(const SearchInfo *search, EnvironmentInfo **result)
if (!env) {
return RC_NO_MEMORY;
}
- env->isActiveVenv = true;
+ env->highPriority = true;
env->internalSortKey = 20;
exitCode = copyWstr(&env->displayName, L"Active venv");
if (exitCode) {
@@ -1821,6 +1831,15 @@ _selectEnvironment(const SearchInfo *search, EnvironmentInfo *env, EnvironmentIn
return 0;
}
+ if (env->highPriority && search->lowPriorityTag) {
+ // This environment is marked high priority, and the search allows
+ // it to be selected even though a tag is specified, so select it
+ // gh-92817: this allows an active venv to be selected even when a
+ // default tag has been found in py.ini or the environment
+ *best = env;
+ return 0;
+ }
+
if (!search->oldStyleTag) {
if (_companyMatches(search, env) && _tagMatches(search, env)) {
// Because of how our sort tree is set up, we will walk up the