Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08d8058

Browse files
gh-96559: Fixes Windows launcher handling of defaults using old-style tags, and adds What's New section (GH-96595)
(cherry picked from commit 80a9bd2) Co-authored-by: Steve Dower <[email protected]>
1 parent a5a9d05 commit 08d8058

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,28 @@ PEP 563 May Not Be the Future
352352
that was planned for this release has been indefinitely postponed.
353353
See `this message <https://mail.python.org/archives/list/[email protected]/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/>`_ for more information.
354354

355+
Windows py.exe launcher improvements
356+
------------------------------------
357+
358+
The copy of :ref:`launcher` included with Python 3.11 has been significantly
359+
updated. It now supports company/tag syntax as defined in :pep:`514` using the
360+
``-V:<company>/<tag>`` argument instead of the limited ``-x.y`` argument. This
361+
allows launching distributions other than ``PythonCore``, which is the one
362+
obtained from `python.org <https://python.org>`_.
363+
364+
When using ``-V:`` selectors, either company or tag can be omitted, but all
365+
installs will be searched. For example, ``-V:OtherPython/`` will select the
366+
"best" tag registered for ``OtherPython``, while ``-V:3.11`` or ``-V:/3.11``
367+
will select the "best" distribution with tag ``3.11``.
368+
369+
When using legacy ``-x``, ``-x.y``, ``-x-ZZ`` or ``-x.y-ZZ`` arguments, all
370+
existing behaviour should be preserved from past versions. Only releases from
371+
``PythonCore`` will be selected. However, the ``-64`` suffix now implies "not
372+
32-bit", as there are multiple supported 64-bit platforms. 32-bit runtimes are
373+
detected by checking its tag for a ``-32`` suffix. All releases of Python
374+
since 3.5 have included this in their 32-bit builds.
375+
376+
355377
Other Language Changes
356378
======================
357379

Lib/test/test_launcher.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ def test_py_shebang_short_argv0(self):
559559
self.assertEqual("3.100", data["SearchInfo.tag"])
560560
self.assertEqual(f'X.Y.exe -prearg "{script}" -postarg', data["stdout"].strip())
561561

562+
def test_py_handle_64_in_ini(self):
563+
with self.py_ini("\n".join(["[defaults]", "python=3.999-64"])):
564+
# Expect this to fail, but should get oldStyleTag flipped on
565+
data = self.run_py([], allow_fail=True, expect_returncode=103)
566+
self.assertEqual("3.999-64", data["SearchInfo.tag"])
567+
self.assertEqual("True", data["SearchInfo.oldStyleTag"])
568+
562569
def test_search_path(self):
563570
stem = Path(sys.executable).stem
564571
with self.py_ini(TEST_PY_COMMANDS):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes the Windows launcher not using the compatible interpretation of
2+
default tags found in configuration files when no tag was passed to the
3+
command.

PC/launcher2.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,6 @@ typedef struct {
393393
// only currently possible high priority environment is an active virtual
394394
// environment
395395
bool lowPriorityTag;
396-
// if true, we had an old-style tag with '-64' suffix, and so do not
397-
// want to match tags like '3.x-32'
398-
bool exclude32Bit;
399-
// if true, we had an old-style tag with '-32' suffix, and so *only*
400-
// want to match tags like '3.x-32'
401-
bool only32Bit;
402396
// if true, allow PEP 514 lookup to override 'executable'
403397
bool allowExecutableOverride;
404398
// if true, allow a nearby pyvenv.cfg to locate the executable
@@ -483,8 +477,6 @@ dumpSearchInfo(SearchInfo *search)
483477
DEBUG_2(tag, tagLength);
484478
DEBUG_BOOL(oldStyleTag);
485479
DEBUG_BOOL(lowPriorityTag);
486-
DEBUG_BOOL(exclude32Bit);
487-
DEBUG_BOOL(only32Bit);
488480
DEBUG_BOOL(allowDefaults);
489481
DEBUG_BOOL(allowExecutableOverride);
490482
DEBUG_BOOL(windowed);
@@ -649,17 +641,6 @@ parseCommandLine(SearchInfo *search)
649641
search->tagLength = argLen;
650642
search->oldStyleTag = true;
651643
search->restOfCmdLine = tail;
652-
// If the tag ends with -64, we want to exclude 32-bit runtimes
653-
// (If the tag ends with -32, it will be filtered later)
654-
if (argLen > 3) {
655-
if (0 == _compareArgument(&arg[argLen - 3], 3, L"-64", 3)) {
656-
search->tagLength -= 3;
657-
search->exclude32Bit = true;
658-
} else if (0 == _compareArgument(&arg[argLen - 3], 3, L"-32", 3)) {
659-
search->tagLength -= 3;
660-
search->only32Bit = true;
661-
}
662-
}
663644
} else if (STARTSWITH(L"V:") || STARTSWITH(L"-version:")) {
664645
// Arguments starting with 'V:' specify company and/or tag
665646
const wchar_t *argStart = wcschr(arg, L':') + 1;
@@ -1087,6 +1068,7 @@ checkDefaults(SearchInfo *search)
10871068
if (!slash) {
10881069
search->tag = tag;
10891070
search->tagLength = n;
1071+
search->oldStyleTag = true;
10901072
} else {
10911073
search->company = tag;
10921074
search->companyLength = (int)(slash - tag);
@@ -1966,10 +1948,25 @@ _selectEnvironment(const SearchInfo *search, EnvironmentInfo *env, EnvironmentIn
19661948
}
19671949
} else if (0 == _compare(env->company, -1, L"PythonCore", -1)) {
19681950
// Old-style tags can only match PythonCore entries
1969-
if (_startsWith(env->tag, -1, search->tag, search->tagLength)) {
1970-
if (search->exclude32Bit && _is32Bit(env)) {
1951+
1952+
// If the tag ends with -64, we want to exclude 32-bit runtimes
1953+
// (If the tag ends with -32, it will be filtered later)
1954+
int tagLength = search->tagLength;
1955+
bool exclude32Bit = false, only32Bit = false;
1956+
if (tagLength > 3) {
1957+
if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-64", 3)) {
1958+
tagLength -= 3;
1959+
exclude32Bit = true;
1960+
} else if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-32", 3)) {
1961+
tagLength -= 3;
1962+
only32Bit = true;
1963+
}
1964+
}
1965+
1966+
if (_startsWith(env->tag, -1, search->tag, tagLength)) {
1967+
if (exclude32Bit && _is32Bit(env)) {
19711968
debug(L"# Excluding %s/%s because it looks like 32bit\n", env->company, env->tag);
1972-
} else if (search->only32Bit && !_is32Bit(env)) {
1969+
} else if (only32Bit && !_is32Bit(env)) {
19731970
debug(L"# Excluding %s/%s because it doesn't look 32bit\n", env->company, env->tag);
19741971
} else {
19751972
*best = env;

0 commit comments

Comments
 (0)