8000 bpo-34532: Fixed exit code for py.exe list versions arg by bgerrity · Pull Request #9039 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-34532: Fixed exit code for py.exe list versions arg #9039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes exit code of list version arguments for py.exe.
48 changes: 23 additions & 25 deletions PC/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ process(int argc, wchar_t ** argv)
size_t plen;
INSTALLED_PYTHON * ip;
BOOL valid;
BOOL version_call = FALSE;
DWORD size, attrs;
HRESULT hr;
wchar_t message[MSGSIZE];
Expand Down Expand Up @@ -1600,14 +1601,15 @@ process(int argc, wchar_t ** argv)
}
else {
p = argv[1];
plen = wcslen(p);
if ((argc == 2) &&
(!wcsncmp(p, L"-0", wcslen(L"-0")) || /* Starts with -0 or --list */
!wcsncmp(p, L"--list", wcslen(L"--list"))))
(!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") || /* Version args. */
!_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths")))
{
valid = show_python_list(argv); /* Check for -0 or --list FIRST */
show_python_list(argv);
version_call = TRUE;
executable = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Why not just return immediately from here? There doesn't seem to be any cleanup that has to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote it to imitate the behavior of -h where it'll search for any Python version and return RC_NO_PYTHON if nothing is found. If that's not desirable, could just bump the check up a level.

}
valid = valid && (*p == L'-') && validate_version(&p[1]);
valid = !version_call && (*p == L'-') && validate_version(&p[1]);
if (valid) {
ip = locate_python(&p[1], FALSE);
if (ip == NULL)
Expand Down Expand Up @@ -1638,29 +1640,25 @@ installed, use -0 for available pythons", &p[1]);
if (!valid) {
if ((argc == 2) && (!_wcsicmp(p, L"-h") || !_wcsicmp(p, L"--help")))
show_help_text(argv);
if ((argc == 2) &&
(!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") ||
!_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths")))
{
executable = NULL; /* Info call only */
}
else {
/* Look for an active virtualenv */
executable = find_python_by_venv();

/* If we didn't find one, look for the default Python */
if (executable == NULL) {
ip = locate_python(L"", FALSE);
if (ip == NULL)
error(RC_NO_PYTHON, L"Can't find a default Python.");
executable = ip->executable;
}

/* Look for an active virtualenv */
executable = find_python_by_venv();

/* If we didn't find one, look for the default Python */
if (executable == NULL) {
ip = locate_python(L"", FALSE);
if (ip == NULL)
error(RC_NO_PYTHON, L"Can't find a default Python.");
executable = ip->executable;
}
}
if (executable != NULL)
invoke_child(executable, NULL, command);
else
if (executable == NULL) {
rc = RC_NO_PYTHON;
}
else if (!version_call) {
invoke_child(executable, NULL, command);
}

return rc;
}

Expand Down
0