Skip to content

platform.python_implementation returning "CPython" #4111

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

Closed
ecpost opened this issue Aug 20, 2022 · 8 comments
Closed

platform.python_implementation returning "CPython" #4111

ecpost opened this issue Aug 20, 2022 · 8 comments

Comments

@ecpost
Copy link
Contributor

ecpost commented Aug 20, 2022

Python's platform.python_implementation function is now returning "CPython" instead of "RustPython". I believe it is because Lib/platform.py was refreshed recently (2daddd9) with the latest from CPython, which contains the python_implementation function. Previously, that function (among other things) had been removed from Lib/platform.py back in 2020 (bbb04c3) so that the Rust version of that function in stdlib/src/platform.rs would handle the implementation.

I noticed this because it breaks whats_left.py. (There's a check to make sure the sub-process isn't running CPython, and it now thinks it is, even though it's from "cargo run...".)

I can work on a PR, but I wasn't sure if there's more to this, like other related changes in the works or whatever. If not, I could bascially mimic what was done in bbb04c3. Let me know if I can help.

@youknowone
Copy link
Member

Oh, thank you! it was a mistake. It will be great if you can try.

@palaviv do you have advice?

@ecpost
Copy link
Contributor Author

ecpost commented Aug 21, 2022

Comparing the last version of platform.py (prior to the 3.10.6 update) to the very first version (which matches the CPython version from late 2019), there are 3 areas with changes:

  • The libc_ver function has a TODO comment and immediate return of the defaults at the beginning of the function.
  • The _syscmd_uname function has a similar change.
  • A large section of code is removed (compiled regexes, a cache, and all the python_* functions that were redone in Rust) and replaced with from _platform import *.

That should be easy enough for me to do to the 3.10.6 version. I can wait a bit to see if palaviv has any comments first.

Regarding the old TODO's in there, I could take a closer look at those too and see if I can take care of them. I'm thinking it should be a separate PR so the "CPython" platform issue is fixed sooner rather than later.

@youknowone
Copy link
Member

palaviv is not very active these days. You can go ahead as you want. Your analysis sounds very clear

@ecpost
Copy link
Contributor Author

ecpost commented Aug 23, 2022

Ok, thanks. I have it ready. I'm not able to build at the moment, I think because of #4117? I'll submit the PR later...

@youknowone
Copy link
Member

That must be not a problem when you build from project root. How it fails?

@youknowone
Copy link
Member

Deleting code can mislead future update if the CPython code is updated - exactly what I thought.
The typical python flow to check native module is checking import error.

try:
    from _platform import *
except ModuleNotFound:
    # Add python function here

This pattern will prevent it.

@youknowone
Copy link
Member

@ecpost if you are looking for easy-medium level issues, we have a series of TODO list in number protocol: #3244

@ecpost
Copy link
Contributor Author

ecpost commented Aug 23, 2022

That must be not a problem when you build from project root. How it fails?

I'll put the details in #4117. (Or let me know if it's better to open a new issue.)


I see your platform.py change in #4128 -- is that just a temporary workaround, and I should still continue with the original change to platform.py I proposed (apply the 2020 changes to the new 3.10.6 version)?


... This pattern will prevent it.

Are you suggesting I take the code I was going to delete and put it in that except block? Just confirming.

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

No branches or pull requests

2 participants