-
Notifications
You must be signed in to change notification settings - Fork 226
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
chore: Simplify host platform logic #1498
Conversation
There is some duplicated code for deciding what the host platform is. This groups it together in util.py
return "linux" | ||
elif sys.platform == "darwin": | ||
return "macos" | ||
elif sys.platform == "win32": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to say sys.platform == "win32"
but this changes it to startswith("win")
. Am I introducing a bug with this behavior change? If so I'd like to add a comment explaining why we use == "win32"
here but in architecture we use startswith("win")
.
host_platform: PlatformName = ( | ||
"windows" | ||
if sys.platform.startswith("win") | ||
else ("macos" if sys.platform.startswith("darwin") else "linux") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this PR because it was bothering me that the logic here does not exactly match the logic in _compute_platform_ci()
.
HOST_IS_WINDOWS: Final[bool] = get_host_platform() == "windows" | ||
|
||
HOST_IS_WIN32: Final[bool] = sys.platform == "win32" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit excessive but I think it makes the intended distinction between these two checks 100% clear.
for more information, see https://pre-commit.ci
Well this seems to pass the tests. Maybe there should be more unit test coverage for the difference between |
This is one of those cases where backward compatibility was preferred over correctness - the 'win32' value applies even on 64-bit windows. See here: (Found via this SO answer) So there's no functional difference between |
It's a recommended practice to always use I personally don't like pulling this check out - I'd rather it just always be Footnotes
|
Agreed on the literal |
Okay will close this and do another which switches to using |
There is some duplicated code for deciding what the host platform is. This groups it together in util.py.
I was slightly confused in some places whether
startswith("win")
or== "win32"
was desired. I added a newHOST_IS_WIN32
variable since I think it's as explicit as possible that the intended check is specifically for win32 and not for windows in general. SinceHOST_IS_WINDOWS
is for that.