Lines Matching +full:shebang +full:- +full:command
5 * runtime to be launched. It also enables auto-install of versions when they
62 buffer[r--] = L'\0'; in debug()
99 _snwprintf_s(&message[len], MSGSIZE - len, _TRUNCATE, L": %s", in winerror()
149 // We should always be a 32-bit executable, so if running in _getNativeMachine()
150 // under emulation, it must be a 64-bit host. in _getNativeMachine()
182 /* only looking for non-empty, which means at least one character in isEnvVarSet()
203 return (!y || !yLen) ? 0 : -1; in _compare()
213 return -1; in _compare()
220 return -1; in _compare()
230 return (!y || !yLen) ? 0 : -1; in _compareArgument()
240 return -1; in _compareArgument()
247 return -1; in _compareArgument()
256 return !y || !yLen ? 0 : -1; in _comparePath()
262 return -1; in _comparePath()
269 return -1; in _comparePath()
330 // The help text is stored in launcher-usage.txt, which is compiled into in showHelpText()
333 // The file must be UTF-8. There are two substitutions: in showHelpText()
334 // %ls - PY_VERSION (as wchar_t*) in showHelpText()
335 // %ls - argv[0] (as wchar_t*) in showHelpText()
390 // shebang line, if any. Length can be -1 if the string is null
395 // name of the target executable. Length can be -1 if the string
400 // arguments to include before restOfCmdLine. Length can be -1 if
405 // company name for PEP 514 lookup. Length can be -1 if the string
410 // tag for PEP 514 lookup. Length can be -1 if the string is
414 // if true, treats 'tag' as a non-PEP 514 filter
417 // gh-92817: This is currently set when a tag is read from configuration or
418 // the environment, rather than the command line or a shebang line, and the
428 // if true, prefer windowed (console-less) executable
454 buffer->next = search->_buffer; in allocSearchInfoBuffer()
455 search->_buffer = buffer; in allocSearchInfoBuffer()
456 return buffer->buffer; in allocSearchInfoBuffer()
463 struct _SearchInfoBuffer *b = search->_buffer; in freeSearchInfo()
464 search->_buffer = NULL; in freeSearchInfo()
466 struct _SearchInfoBuffer *nextB = b->next; in freeSearchInfo()
496 #define DEBUG(s) debug(DEBUGNAME(#s) L": %s\n", (search->s) ? (search->s) : L"(null)") in dumpSearchInfo()
497 #define DEBUG_2(s, sl) _debugStringAndLength((search->s), (search->sl), DEBUGNAME(#s)) in dumpSearchInfo()
498 #define DEBUG_BOOL(s) debug(DEBUGNAME(#s) L": %s\n", (search->s) ? L"True" : L"False") in dumpSearchInfo()
561 *** COMMAND-LINE PARSING ***
568 if (!search || !search->originalCmdLine) { in parseCommandLine()
572 const wchar_t *argv0End = findArgv0End(search->originalCmdLine, -1); in parseCommandLine()
575 search->restOfCmdLine = argv0End; // will be first space after argv0 in parseCommandLine()
576 while (--tail != search->originalCmdLine) { in parseCommandLine()
588 if (tail == search->originalCmdLine && tail[0] == L'"') { in parseCommandLine()
592 int tailLen = (int)(end ? (end - tail) : wcsnlen_s(tail, MAXLEN)); in parseCommandLine()
593 search->executableLength = -1; in parseCommandLine()
596 #define MATCHES(s) (0 == _comparePath(tail, tailLen, (s), -1)) in parseCommandLine()
597 #define STARTSWITH(s) _startsWith(tail, tailLen, (s), -1) in parseCommandLine()
599 search->executable = L"python.exe"; in parseCommandLine()
600 search->allowExecutableOverride = true; in parseCommandLine()
601 search->allowDefaults = true; in parseCommandLine()
603 search->executable = L"pythonw.exe"; in parseCommandLine()
604 search->allowExecutableOverride = true; in parseCommandLine()
605 search->allowDefaults = true; in parseCommandLine()
606 search->windowed = true; in parseCommandLine()
608 search->executable = L"python_d.exe"; in parseCommandLine()
609 search->allowExecutableOverride = true; in parseCommandLine()
610 search->allowDefaults = true; in parseCommandLine()
612 search->executable = L"pythonw_d.exe"; in parseCommandLine()
613 search->allowExecutableOverride = true; in parseCommandLine()
614 search->allowDefaults = true; in parseCommandLine()
615 search->windowed = true; in parseCommandLine()
617 search->executable = L"python.exe"; in parseCommandLine()
618 search->tag = &tail[6]; in parseCommandLine()
619 search->tagLength = tailLen - 6; in parseCommandLine()
620 search->allowExecutableOverride = true; in parseCommandLine()
621 search->oldStyleTag = true; in parseCommandLine()
622 search->allowPyvenvCfg = true; in parseCommandLine()
624 search->executable = L"pythonw.exe"; in parseCommandLine()
625 search->tag = &tail[7]; in parseCommandLine()
626 search->tagLength = tailLen - 7; in parseCommandLine()
627 search->allowExecutableOverride = true; in parseCommandLine()
628 search->oldStyleTag = true; in parseCommandLine()
629 search->allowPyvenvCfg = true; in parseCommandLine()
630 search->windowed = true; in parseCommandLine()
632 search->executable = tail; in parseCommandLine()
633 search->executableLength = tailLen; in parseCommandLine()
634 search->allowPyvenvCfg = true; in parseCommandLine()
641 const wchar_t *arg = search->restOfCmdLine; in parseCommandLine()
643 #define MATCHES(s) (0 == _compareArgument(arg, argLen, (s), -1)) in parseCommandLine()
644 #define STARTSWITH(s) _startsWithArgument(arg, argLen, (s), -1) in parseCommandLine()
645 if (*arg && *arg == L'-' && *++arg) { in parseCommandLine()
648 int argLen = (int)(tail - arg); in parseCommandLine()
652 search->tag = arg; in parseCommandLine()
653 search->tagLength = argLen; in parseCommandLine()
654 search->oldStyleTag = true; in parseCommandLine()
655 search->restOfCmdLine = tail; in parseCommandLine()
656 } else if (STARTSWITH(L"V:") || STARTSWITH(L"-version:")) { in parseCommandLine()
661 search->company = argStart; in parseCommandLine()
662 search->companyLength = (int)(tagStart - argStart); in parseCommandLine()
663 search->tag = tagStart + 1; in parseCommandLine()
665 search->tag = argStart; in parseCommandLine()
667 search->tagLength = (int)(tail - search->tag); in parseCommandLine()
668 search->allowDefaults = false; in parseCommandLine()
669 search->restOfCmdLine = tail; in parseCommandLine()
670 } else if (MATCHES(L"0") || MATCHES(L"-list")) { in parseCommandLine()
671 search->list = true; in parseCommandLine()
672 search->restOfCmdLine = tail; in parseCommandLine()
673 } else if (MATCHES(L"0p") || MATCHES(L"-list-paths")) { in parseCommandLine()
674 search->listPaths = true; in parseCommandLine()
675 search->restOfCmdLine = tail; in parseCommandLine()
676 } else if (MATCHES(L"h") || MATCHES(L"-help")) { in parseCommandLine()
677 search->help = true; in parseCommandLine()
688 arg = search->restOfCmdLine; in parseCommandLine()
690 if (*arg && *arg != L'-') { in parseCommandLine()
691 search->scriptFile = arg; in parseCommandLine()
693 ++search->scriptFile; in parseCommandLine()
698 search->scriptFileLength = (int)(arg - search->scriptFile); in parseCommandLine()
714 debug(L"# Failed to decode shebang line (0x%08X)\n", GetLastError()); in _decodeShebang()
724 debug(L"# Failed to decode shebang line (0x%08X)\n", GetLastError()); in _decodeShebang()
749 *firstArgumentLength = i - prefixLength; in _shebangStartsWith()
756 searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength) in searchPath() argument
762 wchar_t *command; in searchPath() local
764 if (!_shebangStartsWith(shebang, shebangLength, L"/usr/bin/env ", &command, &commandLength)) { in searchPath()
773 while (lastDot > 0 && command[lastDot] != L'.') { in searchPath()
774 lastDot -= 1; in searchPath()
781 if (wcsncpy_s(filename, MAXLEN, command, lastDot)) { in searchPath()
786 // If the command already has an extension, we do not want to add it again in searchPath()
787 if (!lastDot || _comparePath(&filename[lastDot], -1, ext, -1)) { in searchPath()
817 // If we are, pretend there was no shebang and let normal handling take over in searchPath()
819 0 == _comparePath(filename, -1, buffer, -1)) { in searchPath()
820 debug(L"# ignoring recursive shebang command\n"); in searchPath()
829 search->executablePath = buf; in searchPath()
830 search->executableArgs = &command[commandLength]; in searchPath()
831 search->executableArgsLength = shebangLength - commandLength; in searchPath()
875 _findCommand(SearchInfo *search, const wchar_t *command, int commandLength) in _findCommand() argument
879 wcsncpy_s(commandBuffer, MAXLEN, command, commandLength); in _findCommand()
889 search->executablePath = path; in _findCommand()
895 _useShebangAsExecutable(SearchInfo *search, const wchar_t *shebang, int shebangLength) in _useShebangAsExecutable() argument
899 wchar_t command[MAXLEN]; in _useShebangAsExecutable() local
904 if (!shebang || !shebangLength) { in _useShebangAsExecutable()
908 wchar_t *pC = command; in _useShebangAsExecutable()
910 wchar_t c = shebang[i]; in _useShebangAsExecutable()
925 wcsncpy_s(script, MAXLEN, search->scriptFile, search->scriptFileLength) || in _useShebangAsExecutable()
929 FAILED(PathCchCombineEx(buffer, MAXLEN, buffer, command, in _useShebangAsExecutable()
941 search->executablePath = path; in _useShebangAsExecutable()
943 search->executableArgs = &shebang[commandLength]; in _useShebangAsExecutable()
944 search->executableArgsLength = shebangLength - commandLength; in _useShebangAsExecutable()
953 // Do not check shebang if a tag was provided or if no script file in checkShebang()
954 // was found on the command line. in checkShebang()
955 if (search->tag || !search->scriptFile) { in checkShebang()
959 if (search->scriptFileLength < 0) { in checkShebang()
960 search->scriptFileLength = (int)wcsnlen_s(search->scriptFile, MAXLEN); in checkShebang()
963 wchar_t *scriptFile = (wchar_t*)malloc(sizeof(wchar_t) * (search->scriptFileLength + 1)); in checkShebang()
968 wcsncpy_s(scriptFile, search->scriptFileLength + 1, in checkShebang()
969 search->scriptFile, search->scriptFileLength); in checkShebang()
976 debug(L"# Failed to open %s for shebang parsing (0x%08X)\n", in checkShebang()
985 debug(L"# Failed to read %s for shebang parsing (0x%08X)\n", in checkShebang()
992 debug(L"# Read %d bytes from %s to find shebang line\n", bytesRead, scriptFile); in checkShebang()
1000 // Allow a UTF-8 BOM in checkShebang()
1002 bytesRead -= 3; in checkShebang()
1005 debug(L"# Invalid BOM in shebang line"); in checkShebang()
1010 // No shebang (#!) at start of line in checkShebang()
1011 debug(L"# No valid shebang line"); in checkShebang()
1015 --bytesRead; in checkShebang()
1016 while (--bytesRead > 0 && isspace(*++b)) { } in checkShebang()
1018 while (--bytesRead > 0 && *++b != '\r' && *b != '\n') { } in checkShebang()
1019 wchar_t *shebang; in checkShebang() local
1023 …int exitCode = _decodeShebang(search, start, (int)(b - start + (bytesRead == 0)), onlyUtf8, &sheba… in checkShebang()
1027 debug(L"Shebang: %s\n", shebang); in checkShebang()
1030 exitCode = searchPath(search, shebang, shebangLength); in checkShebang()
1035 // Handle some known, case-sensitive shebangs in checkShebang()
1036 const wchar_t *command; in checkShebang() local
1049 assert(0 == wcscmp(L"python", (*tmpl) + wcslen(*tmpl) - 6)); in checkShebang()
1051 if (_shebangStartsWith(shebang, shebangLength, *tmpl, &command, &commandLength)) { in checkShebang()
1052 // Search for "python{command}" overrides. All templates end with in checkShebang()
1054 if (_findCommand(search, &command[-6], commandLength + 6)) { in checkShebang()
1055 search->executableArgs = &command[commandLength]; in checkShebang()
1056 search->executableArgsLength = shebangLength - commandLength; in checkShebang()
1057 debug(L"# Treating shebang command '%.*s' as %s\n", in checkShebang()
1058 commandLength + 6, &command[-6], search->executablePath); in checkShebang()
1062 search->tag = command; in checkShebang()
1063 search->tagLength = commandLength; in checkShebang()
1066 if (search->tagLength > 4) { in checkShebang()
1067 const wchar_t *suffix = &search->tag[search->tagLength - 4]; in checkShebang()
1068 if (0 == _comparePath(suffix, 4, L".exe", -1)) { in checkShebang()
1069 search->tagLength -= 4; in checkShebang()
1074 if (search->tagLength > 2) { in checkShebang()
1075 const wchar_t *suffix = &search->tag[search->tagLength - 2]; in checkShebang()
1076 if (0 == _comparePath(suffix, 2, L"_d", -1)) { in checkShebang()
1077 search->tagLength -= 2; in checkShebang()
1080 search->oldStyleTag = true; in checkShebang()
1081 search->executableArgs = &command[commandLength]; in checkShebang()
1082 search->executableArgsLength = shebangLength - commandLength; in checkShebang()
1083 if (search->tag && search->tagLength) { in checkShebang()
1084 debug(L"# Treating shebang command '%.*s' as 'py -%.*s'\n", in checkShebang()
1085 commandLength, command, search->tagLength, search->tag); in checkShebang()
1087 debug(L"# Treating shebang command '%.*s' as 'py'\n", in checkShebang()
1088 commandLength, command); in checkShebang()
1094 // Unrecognised executables are first tried as command aliases in checkShebang()
1096 while (commandLength < shebangLength && !isspace(shebang[commandLength])) { in checkShebang()
1099 if (_findCommand(search, shebang, commandLength)) { in checkShebang()
1100 search->executableArgs = &shebang[commandLength]; in checkShebang()
1101 search->executableArgsLength = shebangLength - commandLength; in checkShebang()
1102 debug(L"# Treating shebang command '%.*s' as %s\n", in checkShebang()
1103 commandLength, shebang, search->executablePath); in checkShebang()
1109 return _useShebangAsExecutable(search, shebang, shebangLength); in checkShebang()
1116 if (!search->allowDefaults) { in checkDefaults()
1120 // Only resolve old-style (or absent) tags to defaults in checkDefaults()
1121 if (search->tag && search->tagLength && !search->oldStyleTag) { in checkDefaults()
1129 if (!search->tag || !search->tagLength) { in checkDefaults()
1132 } else if (0 == wcsncmp(search->tag, L"3", search->tagLength)) { in checkDefaults()
1135 } else if (0 == wcsncmp(search->tag, L"2", search->tagLength)) { in checkDefaults()
1139 debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag); in checkDefaults()
1160 search->tag = tag; in checkDefaults()
1161 search->tagLength = n; in checkDefaults()
1162 search->oldStyleTag = true; in checkDefaults()
1164 search->company = tag; in checkDefaults()
1165 search->companyLength = (int)(slash - tag); in checkDefaults()
1166 search->tag = slash + 1; in checkDefaults()
1167 search->tagLength = n - (search->companyLength + 1); in checkDefaults()
1168 search->oldStyleTag = false; in checkDefaults()
1170 // gh-92817: allow a high priority env to be selected even if it in checkDefaults()
1172 search->lowPriorityTag = true; in checkDefaults()
1210 size_t n = wcsnlen_s(src, MAXLEN - 1) + 1; in copyWstr()
1215 wcsncpy_s(buffer, n, src, n - 1); in copyWstr()
1229 int exitCode = copyWstr(&env->company, company); in newEnvironmentInfo()
1234 exitCode = copyWstr(&env->tag, tag); in newEnvironmentInfo()
1236 free((void *)env->company); in newEnvironmentInfo()
1248 free((void *)env->company); in freeEnvironmentInfo()
1249 free((void *)env->tag); in freeEnvironmentInfo()
1250 free((void *)env->installDir); in freeEnvironmentInfo()
1251 free((void *)env->executablePath); in freeEnvironmentInfo()
1252 free((void *)env->executableArgs); in freeEnvironmentInfo()
1253 free((void *)env->displayName); in freeEnvironmentInfo()
1254 freeEnvironmentInfo(env->prev); in freeEnvironmentInfo()
1255 env->prev = NULL; in freeEnvironmentInfo()
1256 freeEnvironmentInfo(env->next); in freeEnvironmentInfo()
1257 env->next = NULL; in freeEnvironmentInfo()
1271 return -1; in _compareCompany()
1276 bool coreX = 0 == _compare(x, -1, L"PythonCore", -1); in _compareCompany()
1277 bool coreY = 0 == _compare(y, -1, L"PythonCore", -1); in _compareCompany()
1279 return coreY ? 0 : -1; in _compareCompany()
1283 return _compare(x, -1, y, -1); in _compareCompany()
1293 return -1; in _compareTag()
1299 const wchar_t *xDash = wcschr(x, L'-'); in _compareTag()
1300 const wchar_t *yDash = wcschr(y, L'-'); in _compareTag()
1301 int xToDash = xDash ? (int)(xDash - x) : -1; in _compareTag()
1302 int yToDash = yDash ? (int)(yDash - y) : -1; in _compareTag()
1314 return _compare(yDash, -1, xDash, -1); in _compareTag()
1316 return -1; in _compareTag()
1330 node->parent = parent; in addEnvironmentInfo()
1334 switch (_compareCompany(node->company, r->company)) { in addEnvironmentInfo()
1335 case -1: in addEnvironmentInfo()
1336 return addEnvironmentInfo(&r->prev, r, node); in addEnvironmentInfo()
1338 return addEnvironmentInfo(&r->next, r, node); in addEnvironmentInfo()
1343 switch (_compareTag(node->tag, r->tag)) { in addEnvironmentInfo()
1344 case -1: in addEnvironmentInfo()
1345 return addEnvironmentInfo(&r->next, r, node); in addEnvironmentInfo()
1347 return addEnvironmentInfo(&r->prev, r, node); in addEnvironmentInfo()
1352 if (node->internalSortKey < r->internalSortKey) { in addEnvironmentInfo()
1354 node->parent = r->parent; in addEnvironmentInfo()
1355 if (node->parent) { in addEnvironmentInfo()
1356 if (node->parent->prev == r) { in addEnvironmentInfo()
1357 node->parent->prev = node; in addEnvironmentInfo()
1358 } else if (node->parent->next == r) { in addEnvironmentInfo()
1359 node->parent->next = node; in addEnvironmentInfo()
1370 node->next = r->next; in addEnvironmentInfo()
1371 node->prev = r->prev; in addEnvironmentInfo()
1373 debug(L"# replaced %s/%s/%i in tree\n", node->company, node->tag, node->internalSortKey); in addEnvironmentInfo()
1376 debug(L"# not adding %s/%s/%i to tree\n", node->company, node->tag, node->internalSortKey); in addEnvironmentInfo()
1433 // Check if backwards-compatibility is required. in _isLegacyVersion()
1434 // Specifically PythonCore versions 2.X and 3.0 - 3.5 do not implement PEP 514. in _isLegacyVersion()
1435 if (0 != _compare(env->company, -1, L"PythonCore", -1)) { in _isLegacyVersion()
1440 int n = swscanf_s(env->tag, L"%d.%d", &versionMajor, &versionMinor); in _isLegacyVersion()
1442 debug(L"# %s/%s has an invalid version tag\n", env->company, env->tag); in _isLegacyVersion()
1453 // Backwards-compatibility for PythonCore versions which do not implement PEP 514. in _registryReadLegacyEnvironment()
1455 &env->executablePath, in _registryReadLegacyEnvironment()
1456 env->installDir, in _registryReadLegacyEnvironment()
1457 search->executable, in _registryReadLegacyEnvironment()
1458 search->executableLength in _registryReadLegacyEnvironment()
1464 if (search->windowed) { in _registryReadLegacyEnvironment()
1465 …exitCode = _registryReadString(&env->executableArgs, root, L"InstallPath", L"WindowedExecutableArg… in _registryReadLegacyEnvironment()
1468 …exitCode = _registryReadString(&env->executableArgs, root, L"InstallPath", L"ExecutableArguments"); in _registryReadLegacyEnvironment()
1475 copyWstr(&env->architecture, fallbackArch); in _registryReadLegacyEnvironment()
1478 BOOL success = GetBinaryTypeW(env->executablePath, &binaryType); in _registryReadLegacyEnvironment()
1485 copyWstr(&env->architecture, L"32bit"); in _registryReadLegacyEnvironment()
1488 copyWstr(&env->architecture, L"64bit"); in _registryReadLegacyEnvironment()
1495 if (0 == _compare(env->architecture, -1, L"32bit", -1)) { in _registryReadLegacyEnvironment()
1496 size_t tagLength = wcslen(env->tag); in _registryReadLegacyEnvironment()
1497 if (tagLength <= 3 || 0 != _compare(&env->tag[tagLength - 3], 3, L"-32", 3)) { in _registryReadLegacyEnvironment()
1498 const wchar_t *rawTag = env->tag; in _registryReadLegacyEnvironment()
1504 int count = swprintf_s(realTag, tagLength + 4, L"%s-32", env->tag); in _registryReadLegacyEnvironment()
1505 if (count == -1) { in _registryReadLegacyEnvironment()
1510 env->tag = realTag; in _registryReadLegacyEnvironment()
1516 if (swprintf_s(buffer, MAXLEN, L"Python %s", env->tag)) { in _registryReadLegacyEnvironment()
1517 copyWstr(&env->displayName, buffer); in _registryReadLegacyEnvironment()
1527 int exitCode = _registryReadString(&env->installDir, root, L"InstallPath", NULL); in _registryReadEnvironment()
1531 if (!env->installDir) { in _registryReadEnvironment()
1540 if (search->windowed) { in _registryReadEnvironment()
1541 …exitCode = _registryReadString(&env->executablePath, root, L"InstallPath", L"WindowedExecutablePat… in _registryReadEnvironment()
1542 if (!exitCode && env->executablePath) { in _registryReadEnvironment()
1543 …exitCode = _registryReadString(&env->executableArgs, root, L"InstallPath", L"WindowedExecutableArg… in _registryReadEnvironment()
1550 // Missing windowed path or non-windowed request means we use ExecutablePath in _registryReadEnvironment()
1551 if (!env->executablePath) { in _registryReadEnvironment()
1552 … exitCode = _registryReadString(&env->executablePath, root, L"InstallPath", L"ExecutablePath"); in _registryReadEnvironment()
1553 if (!exitCode && env->executablePath) { in _registryReadEnvironment()
1554 …exitCode = _registryReadString(&env->executableArgs, root, L"InstallPath", L"ExecutableArguments"); in _registryReadEnvironment()
1561 if (!env->executablePath) { in _registryReadEnvironment()
1562 debug(L"# %s/%s has no executable path\n", env->company, env->tag); in _registryReadEnvironment()
1566 exitCode = _registryReadString(&env->architecture, root, NULL, L"SysArchitecture"); in _registryReadEnvironment()
1571 exitCode = _registryReadString(&env->displayName, root, NULL, L"DisplayName"); in _registryReadEnvironment()
1597 env->internalSortKey = sortKey; in _registrySearchTags()
1633 … if (search->limitToCompany && 0 != _compare(search->limitToCompany, -1, buffer, cchBuffer)) { in registrySearch()
1656 const wchar_t *exeName = search->executable; in appxSearch()
1657 if (!exeName || search->allowExecutableOverride) { in appxSearch()
1658 exeName = search->windowed ? L"pythonw.exe" : L"python.exe"; in appxSearch()
1673 // the '-arm64' on ARM64 host. in appxSearch()
1676 wcscat_s(realTag, 32, L"-arm64"); in appxSearch()
1683 env->internalSortKey = sortKey; in appxSearch()
1685 copyWstr(&env->architecture, L"64bit"); in appxSearch()
1687 copyWstr(&env->architecture, L"ARM64"); in appxSearch()
1690 copyWstr(&env->executablePath, buffer); in appxSearch()
1693 copyWstr(&env->displayName, buffer); in appxSearch()
1717 if (!search->executablePath) { in explicitOverrideSearch()
1725 env->internalSortKey = 10; in explicitOverrideSearch()
1726 int exitCode = copyWstr(&env->executablePath, search->executablePath); in explicitOverrideSearch()
1730 exitCode = copyWstr(&env->displayName, L"Explicit override"); in explicitOverrideSearch()
1760 if (!n || !join(buffer, MAXLEN, L"Scripts") || !join(buffer, MAXLEN, search->executable)) { in virtualenvSearch()
1773 env->highPriority = true; in virtualenvSearch()
1774 env->internalSortKey = 20; in virtualenvSearch()
1775 exitCode = copyWstr(&env->displayName, L"Active venv"); in virtualenvSearch()
1779 exitCode = copyWstr(&env->executablePath, buffer); in virtualenvSearch()
1845 // Powershell "Get-AppxPackage" cmdlet
1863 // Side-loadable releases. Note that the publisher ID changes whenever we
1864 // renew our code-signing certificate, so the newer ID has a higher
1901 if (env && !(search->list || search->listPaths)) { in collectEnvironments()
1905 for (struct RegistrySearchInfo *info = REGISTRY_SEARCH; info->subkey; ++info) { in collectEnvironments()
1906 if (ERROR_SUCCESS == RegOpenKeyExW(info->hive, info->subkey, 0, info->flags, &root)) { in collectEnvironments()
1907 exitCode = registrySearch(search, result, root, info->sortKey, info->fallbackArch); in collectEnvironments()
1915 if (search->limitToCompany) { in collectEnvironments()
1920 for (struct AppxSearchInfo *info = APPX_SEARCH; info->familyName; ++info) { in collectEnvironments()
1921 exitCode = appxSearch(search, result, info->familyName, info->tag, info->sortKey); in collectEnvironments()
1957 _installEnvironment(const wchar_t *command, const wchar_t *arguments) in _installEnvironment() argument
1963 command, arguments, NULL, in _installEnvironment()
1967 debug(L"# Installing with %s %s\n", command, arguments); in _installEnvironment()
1973 fwprintf_s(stdout, L"\"%s\" %s\n", command, arguments); in _installEnvironment()
1975 fwprintf_s(stdout, L"\"%s\"\n", command); in _installEnvironment()
2002 const wchar_t *WINGET_ARGUMENTS = L"install -q %s --exact --accept-package-agreements --source msst…
2004 const wchar_t *MSSTORE_COMMAND = L"ms-windows-store://pdp/?productid=%s";
2010 if (!search->tag || !search->tagLength) { in installEnvironment()
2016 if (!search->oldStyleTag && in installEnvironment()
2017 search->company && search->companyLength && in installEnvironment()
2018 0 != _compare(search->company, search->companyLength, L"PythonCore", -1)) { in installEnvironment()
2019 debug(L"# Cannot install for company %.*s\n", search->companyLength, search->company); in installEnvironment()
2024 for (struct StoreSearchInfo *info = STORE_SEARCH; info->tag; ++info) { in installEnvironment()
2025 if (0 == _compare(search->tag, search->tagLength, info->tag, -1)) { in installEnvironment()
2026 storeId = info->storeId; in installEnvironment()
2036 wchar_t command[MAXLEN]; in installEnvironment() local
2038 if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, command)) && in installEnvironment()
2039 join(command, MAXLEN, WINGET_COMMAND) && in installEnvironment()
2041 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(command)) { in installEnvironment()
2043 debug(L"# Skipping %s: %s\n", command, arguments); in installEnvironment()
2047 exitCode = _installEnvironment(command, arguments); in installEnvironment()
2050 Please check the install status and run your command again.", stderr); in installEnvironment()
2061 if (swprintf_s(command, MAXLEN, MSSTORE_COMMAND, storeId)) { in installEnvironment()
2063 L"please run your command again.\n", stderr); in installEnvironment()
2064 exitCode = _installEnvironment(command, NULL); in installEnvironment()
2081 if (!search->company || !search->companyLength) { in _companyMatches()
2084 return 0 == _compare(env->company, -1, search->company, search->companyLength); in _companyMatches()
2092 searchTagLength = search->tagLength; in _tagMatches()
2094 if (!search->tag || !searchTagLength) { in _tagMatches()
2097 return _startsWithSeparated(env->tag, -1, search->tag, searchTagLength, L".-"); in _tagMatches()
2104 if (env->architecture) { in _is32Bit()
2105 return 0 == _compare(env->architecture, -1, L"32bit", -1); in _is32Bit()
2116 exitCode = _selectEnvironment(search, env->prev, best); in _selectEnvironment()
2124 if (env->highPriority && search->lowPriorityTag) { in _selectEnvironment()
2127 // gh-92817: this allows an active venv to be selected even when a in _selectEnvironment()
2133 if (!search->oldStyleTag) { in _selectEnvironment()
2134 if (_companyMatches(search, env) && _tagMatches(search, env, -1)) { in _selectEnvironment()
2142 } else if (0 == _compare(env->company, -1, L"PythonCore", -1)) { in _selectEnvironment()
2143 // Old-style tags can only match PythonCore entries in _selectEnvironment()
2145 // If the tag ends with -64, we want to exclude 32-bit runtimes in _selectEnvironment()
2146 // (If the tag ends with -32, it will be filtered later) in _selectEnvironment()
2147 int tagLength = search->tagLength; in _selectEnvironment()
2150 if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-64", 3)) { in _selectEnvironment()
2151 tagLength -= 3; in _selectEnvironment()
2153 } else if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-32", 3)) { in _selectEnvironment()
2154 tagLength -= 3; in _selectEnvironment()
2161 … debug(L"# Excluding %s/%s because it looks like 32bit\n", env->company, env->tag); in _selectEnvironment()
2163 … debug(L"# Excluding %s/%s because it doesn't look 32bit\n", env->company, env->tag); in _selectEnvironment()
2171 env = env->next; in _selectEnvironment()
2207 if (env->executablePath && env->executablePath[0]) { in _printEnvironment()
2208 if (env->executableArgs && env->executableArgs[0]) { in _printEnvironment()
2209 … fwprintf(out, L" %-*s %s %s\n", TAGWIDTH, argument, env->executablePath, env->executableArgs); in _printEnvironment()
2211 fwprintf(out, L" %-*s %s\n", TAGWIDTH, argument, env->executablePath); in _printEnvironment()
2213 } else if (env->installDir && env->installDir[0]) { in _printEnvironment()
2214 fwprintf(out, L" %-*s %s\n", TAGWIDTH, argument, env->installDir); in _printEnvironment()
2218 } else if (env->displayName) { in _printEnvironment()
2219 fwprintf(out, L" %-*s %s\n", TAGWIDTH, argument, env->displayName); in _printEnvironment()
2233 int exitCode = _listAllEnvironments(env->prev, out, showPath, defaultEnv); in _listAllEnvironments()
2238 if (!env->company || !env->tag) { in _listAllEnvironments()
2240 } else if (0 == _compare(env->company, -1, L"PythonCore", -1)) { in _listAllEnvironments()
2241 swprintf_s(buffer, bufferSize, L"-V:%s", env->tag); in _listAllEnvironments()
2243 swprintf_s(buffer, bufferSize, L"-V:%s/%s", env->company, env->tag); in _listAllEnvironments()
2257 env = env->next; in _listAllEnvironments()
2272 In favour, helps users see that '-3' is a good option in listEnvironments()
2281 majorSearch.companyLength = -1; in listEnvironments()
2283 majorSearch.tagLength = -1; in listEnvironments()
2288 exitCode = _printEnvironment(major, out, showPath, L"-3 *"); in listEnvironments()
2298 exitCode = _printEnvironment(major, out, showPath, L"-2"); in listEnvironments()
2327 // Construct command line from a search override, or else the selected in calculateCommandLine()
2329 if (search->executablePath) { in calculateCommandLine()
2330 executablePath = search->executablePath; in calculateCommandLine()
2331 } else if (launch && launch->executablePath) { in calculateCommandLine()
2332 executablePath = launch->executablePath; in calculateCommandLine()
2335 // If we have an executable path, put it at the start of the command, but in calculateCommandLine()
2339 if (executablePath && search->allowExecutableOverride) { in calculateCommandLine()
2342 exitCode = wcscpy_s(&buffer[1], bufferLength - 1, executablePath); in calculateCommandLine()
2350 if (!launch->installDir) { in calculateCommandLine()
2352 launch->company, launch->tag); in calculateCommandLine()
2354 } else if (!search->executable || !search->executableLength) { in calculateCommandLine()
2356 launch->company, launch->tag); in calculateCommandLine()
2360 wcsncpy_s(executable, 256, search->executable, search->executableLength); in calculateCommandLine()
2361 if ((wcschr(launch->installDir, L' ') && launch->installDir[0] != L'"') || in calculateCommandLine()
2364 exitCode = wcscpy_s(&buffer[1], bufferLength - 1, launch->installDir); in calculateCommandLine()
2372 exitCode = wcscpy_s(buffer, bufferLength, launch->installDir); in calculateCommandLine()
2382 if (!exitCode && launch && launch->executableArgs) { in calculateCommandLine()
2385 exitCode = wcscat_s(buffer, bufferLength, launch->executableArgs); in calculateCommandLine()
2389 if (!exitCode && search->executableArgs) { in calculateCommandLine()
2390 if (search->executableArgsLength < 0) { in calculateCommandLine()
2391 exitCode = wcscat_s(buffer, bufferLength, search->executableArgs); in calculateCommandLine()
2392 } else if (search->executableArgsLength > 0) { in calculateCommandLine()
2394 if (end < bufferLength - (search->executableArgsLength + 1)) { in calculateCommandLine()
2395 exitCode = wcsncpy_s(&buffer[end], bufferLength - end, in calculateCommandLine()
2396 search->executableArgs, search->executableArgsLength); in calculateCommandLine()
2401 if (!exitCode && search->restOfCmdLine) { in calculateCommandLine()
2402 exitCode = wcscat_s(buffer, bufferLength, search->restOfCmdLine); in calculateCommandLine()
2468 of seconds, or until the app does something UI-ish (eg, creating a in launchEnvironment()
2473 https://bitbucket.org/vinay.sajip/pylauncher/issue/20/busy-cursor-for-a-long-time-when-running in launchEnvironment()
2507 winerror(0, L"Failed to update Control-C handler"); in launchEnvironment()
2539 // First parse the command line for options in performSearch()
2545 // Check for a shebang line in our script file in performSearch()
2557 // Resolve old-style tags (possibly from a shebang) against py.ini entries in performSearch()
2647 // Successful install, so we need to re-scan and select again in process()
2658 fputws(L"Pass --list (-0) to see all detected environments on your machine\n", stderr); in process()
2674 debug(L"env.company: %s\nenv.tag: %s\n", env->company, env->tag); in process()