Skip to content
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

gh-129294: use winapi to determine win version before invoking cmd.exe #129295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomergert
Copy link

@tomergert tomergert commented Jan 25, 2025

Improve platform module: use rtlGetVersion to determine win version before trying to use cmd.exe

…before trying to create a process using cmd.exe ver"
Copy link

cpython-cla-bot bot commented Jan 25, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 25, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@@ -110,7 +110,7 @@

"""

__version__ = '1.0.9'
__version__ = '1.0.10'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be updated?

Suggested change
__version__ = '1.0.10'
__version__ = '1.0.9'

It was updated a couple of months ago in #122547, but the previous change was 10 years ago (b9f4fea), and there have been lots of updates in the past decade that didn't change it:

https://github.com/python/cpython/commits/main/Lib/platform.py

Copy link
Member

@terryjreedy terryjreedy Jan 26, 2025

Choose a reason for hiding this comment

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

Is the module __version__ attribute really still needed? I thought that these were obsolete. If kept, is the use defined anywhere in a manner that would say when to bump it?

Copy link
Author

Choose a reason for hiding this comment

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

As I understand it just wasn't kept properly. Each change should increase the version (path, minor, major as needed).

@ZeroIntensity ZeroIntensity requested a review from zooba January 25, 2025 12:46
@terryjreedy
Copy link
Member

The issue quoted existing code for cmd in ('ver', 'command /c ver', 'cmd /c ver'):. Are all 3 options still needed for the Windows versions we currently support? Are any of these specific to Win95, ..., WinXp, etc?

@tomergert
Copy link
Author

The issue quoted existing code for cmd in ('ver', 'command /c ver', 'cmd /c ver'):. Are all 3 options still needed for the Windows versions we currently support? Are any of these specific to Win95, ..., WinXp, etc?

'command /c ver' - I think its relevant till Windows ME actually.
ver - straight from cmd.exe
cmd /c ver - will work on cmd.exe, although as i understand it intended for powershell.

I think we should remove this code completely, but if not it will be better to stay just with ver

Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

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

We should avoid using ctypes here, and use a native function. sys.getwindowsversion already exists and is already used in this code, and WMI gets the most accurate result and is tried first.

There is no need for this change, but at the very least, it should not use ctypes and should not use kernel mode APIs when user mode ones exist.

@bedevere-app
Copy link

bedevere-app bot commented Jan 27, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@zooba
Copy link
Member

zooba commented Jan 27, 2025

That said, the actual executable that is run could be improved. Explicitly launching cmd /C ver seems best to me - the others make more assumptions that we can avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants