Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-102536: Added_architecture field tosys.implementation#124582

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rruuaanng wants to merge28 commits intopython:main
base:main
Choose a base branch
Loading
fromrruuaanng:gh102536

Conversation

rruuaanng
Copy link
Contributor

@rruuaanngrruuaanng commentedSep 26, 2024
edited by bedevere-appbot
Loading

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

I'd like to have tests as well please.

@rruuaanng
Copy link
ContributorAuthor

I'd like to have tests as well please.

Okay, I have make change.

picnixz
picnixz previously requested changesSep 26, 2024
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

Sorry but this requires more investigation. The value being added is not the correct one (sys.platform is already exposed so it does not make sense to havesys.implementation._architecture being the same IMO).

@rruuaanng
Copy link
ContributorAuthor

rruuaanng commentedSep 26, 2024
edited
Loading

Sorry but this requires more investigation. The value being added is not the correct one (sys.platform is already exposed so it does not make sense to havesys.implementation._architecture being the same IMO).

According tozooba description, it seems that adding this attribute can make the information ofsys.implementation more comprehensive (although I personally don't think this is necessary.
In fact, all fields in the implementation have corresponding Python APIs for obtaining.

@picnixz
Copy link
Member

Yes but the attribute being added is not the one that you added. You need to get the one stored inpython.props (but I don't know how to retrieve it).

@rruuaanng
Copy link
ContributorAuthor

rruuaanng commentedSep 26, 2024
edited
Loading

Yes but the attribute being added is not the one that you added. You need to get the one stored inpython.props (but I don't know how to retrieve it).

Hmmm, I know how to get the architecture information in capi, but it seems that this is only supported on unix-like.

@picnixz
Copy link
Member

picnixz commentedSep 26, 2024
edited
Loading

On the issue:

sys.implementation._architecture and make it the value of$(ArchName)? frompython.props

So we need to know how to recover$(ArchName). This is what we want to get andpython.props is something that is Windows-only I think. You can have a look at the script:

PYTHON_PROPS_NAME="python.props"
.

I'll leave it to@zooba to explain exactly what he had in mind. But AFAICT, the value ofsys.implementation._architecture should be the same as the one of$(ArchName).

@rruuaanng
Copy link
ContributorAuthor

On the issue:

sys.implementation._architecture and make it the value of$(ArchName)? frompython.props

So we need to know how to recover$(ArchName). This is what we want to get andpython.props is something that is Windows-only I think. You can have a look at the script:

PYTHON_PROPS_NAME="python.props"
.

I'll leave it to@zooba to explain exactly what he had in mind. But AFAICT, the value ofsys.implementation._architecture should be the same as the one of$(ArchName).

He probably needs a descriptive field for the current system architecture in the implementation (since ArchName is limited to this purpose). I think that's what he had in mind, so my PR applies to all targets that support theuname system call. This way, they can obtain information about their current platform through the implementation.

@zooba
Copy link
Member

So we need to know how to recover$(ArchName). This is what we want to get andpython.props is something that is Windows-only I think.

Yeah, this is compile-time information that isn't accessible at runtime (remembering that Windows supports CPU emulation, so an x64 machine can run a 32-bit build, and an ARM64 machine can run an x86 or x64 build).platform.machine() will tell you what the current hardware actually is, but$(ArchName) will tell you what your running Python was compiled for. The best we have right now for this issys.winver.

As for how to get it at compile time, look inPCbuild/pythoncore.vcxproj forMS_DLL_ID, which is how we pass the value ofsys.winver in. We should be able to use something simpler here (winver gets passed around all over the place, unfortunately), and just havesysmodule.c see if the preprocessor value is defined and if so, add it to the implementation struct.

@rruuaanng
Copy link
ContributorAuthor

rruuaanng commentedSep 26, 2024
edited
Loading

So we need to know how to recover$(ArchName). This is what we want to get andpython.props is something that is Windows-only I think.

Yeah, this is compile-time information that isn't accessible at runtime (remembering that Windows supports CPU emulation, so an x64 machine can run a 32-bit build, and an ARM64 machine can run an x86 or x64 build).platform.machine() will tell you what the current hardware actually is, but$(ArchName) will tell you what your running Python was compiled for. The best we have right now for this issys.winver.

As for how to get it at compile time, look inPCbuild/pythoncore.vcxproj forMS_DLL_ID, which is how we pass the value ofsys.winver in. We should be able to use something simpler here (winver gets passed around all over the place, unfortunately), and just havesysmodule.c see if the preprocessor value is defined and if so, add it to the implementation struct.

In other words, what is needed is theMS_DLL_ID value, rather than the runtime machine architecture (platform.machine()).
cc@zooba
Need this

>>> import sys;sys.winver'3.14'

Don't this

>>> import platform;platform.machine()'AMD64'

@rruuaanng
Copy link
ContributorAuthor

rruuaanng commentedSep 27, 2024
edited
Loading

I found this in python.prop

    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'x64'">amd64</ArchName>    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'ARM'">arm32</ArchName>    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'ARM64'">arm64</ArchName>    <ArchName Condition="'$(ArchName)' == ''">win32</ArchName>

If what you mentioned byArchName refers to this, then my current PR would not require any modifications to be merged.
Because it is used for obtaining the runtime architecture(Sorry, I didn't really get what you guys are after from our conversation).
I agree with picnixz's description, sys.implementation._architecture should be the same as the one of $(ArchName), Or perhapsI can change it to a tuple(MS_DLL_ID,ArchName).
It's will

>> sys.implementation._architecture('3.14', 'AMD64')Equal to>> print((sys.winver, platform.machine()))('3.14', 'AMD64')

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

The issue is called "Issue: extend sys module on windows" but your implementation is only for non-Windows platforms.

@ericsnowcurrently
Copy link
Member

In case it got lost in the shuffle, I want to reiterate thatsys.implementation is not the right place for this.

Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

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

Is this supposed to be a public interface (just prefixed with_ to denote platform incompatibility), or a private implementation detail that we need internally? If it's the former, then I agree with Eric.

@zooba
Copy link
Member

Does it belong insysconfig then? As a compile-time option

@zooba
Copy link
Member

Even if we make it available insysconfig, it still has to be made available in a native module forsysconfig, as we don't have any other places to store it on Windows. There's no makefile or similar bundled with the runtime.

@rruuaanng
Copy link
ContributorAuthor

rruuaanng commentedOct 16, 2024
edited
Loading

Your idea is that if he is not in sysconfig, then we need it and he also provides it in sysconfig.

Edit

If I understand your idea correctly, then this question should open a new PR, and I can make him support it.

@rruuaanng
Copy link
ContributorAuthor

Why does this test fail?
test_no_stale_references (test.test_concurrent_futures.test_interpreter_pool.InterpreterPoolExecutorTest.test_no_stale_references) ... Fatal Python error: Segmentation fault

@vstinner
Copy link
Member

@rruuaanng: Please follow what@erlend-aasland said:

The discussion on the issue did not conclude about which API to introduce; please discuss the API first, and then propose the change. I propose to close this premature PR until we know how to introduce this feature.

@rruuaanngrruuaanng marked this pull request as draftOctober 17, 2024 08:14
@vstinner
Copy link
Member

I close the issue for now, I suggest to discuss on the issue and/or on thehttps://discuss.python.org/t/regarding-whether-we-should-add-py-currentarch-or-py-archname-function/65191 discussion.

@rruuaanng
Copy link
ContributorAuthor

I think so. If there are concrete results in the community discussion, maybe I can reopen this PR (it was closed by someone else, so I can't reopen it).

@zooba
Copy link
Member

No reason to close the PR yet.

rruuaanng reacted with thumbs up emoji

@rruuaanng
Copy link
ContributorAuthor

Thanks for zooba support. I agree. In fact, this issue has been discussed. And it has met all the requirements of the merger. I really like this function. It seems that only this can get the information at the time of build.

@ZeroIntensity
Copy link
Member

@zooba I'm curious about the reason to put this insys.implementation. I'm fine with putting it insys (and that's probably the best place to put it), butimplementation seems somewhat random. Why not just invent a new attribute e.g.sys._architecture?

erlend-aasland reacted with thumbs up emoji

@rruuaanng
Copy link
ContributorAuthor

@zooba I'm curious about the reason to put this insys.implementation. I'm fine with putting it insys (and that's probably the best place to put it), butimplementation seems somewhat random. Why not just invent a new attribute e.g.sys._architecture?

zooba comment from this PR of issue.

More importantly, and relevant for this case, is that platform.architecture() can't return the difference, even if it could detect it, because it's defined as only returning "64" or "32". And PEP 421 explicitly suggests sys.implementation is the place to store information that would be returned from platform about the Python implementation. The architecture the current runtime was compiled for sure seems to be related to the implementation, and since platform would be the obvious place to return such information (as it already is, albeit insufficiently), adding the field to sys.implementation seems fine.

@zooba
Copy link
Member

@ZeroIntensity My rationale is on the issue:#102536 (comment)

ZeroIntensity reacted with heart emoji

@@ -1122,6 +1122,12 @@ always available.
``cache_tag`` is set to ``None``, it indicates that module caching should
be disabled.

*arch* describes the architecture of the current interpreter runtime system.

Choose a reason for hiding this comment

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

"current interpreter runtime system" is wrong--_architecture defines what architecture CPython was built with, not what it's currently running under.

Copy link
Member

Choose a reason for hiding this comment

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

It's close. It specifies the architecture it was builtto run as, which is independent from both the one it was builton, and the one it's currentlyrunning on.

But it's the only one that is specific to the currently running interpreter. So at most, I'd only change this to "the native architecture of the current interpreter", and possibly add "which will usually match the architecture of the current system" (though that's probably more words than it's worth).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@zoobazoobazooba left review comments

@ZeroIntensityZeroIntensityZeroIntensity requested changes

@picnixzpicnixzpicnixz left review comments

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

Assignees
No one assigned
Labels
DO-NOT-MERGEpendingThe issue will be closed if no feedback is provided
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@rruuaanng@picnixz@zooba@erlend-aasland@ericsnowcurrently@vstinner@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp