Skip to content

gh-84461: Add sys._emscripten_info, improve docs and build (gh-91781) #91781

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 2 commits into from
Apr 23, 2022

Conversation

tiran
Copy link
Member

@tiran tiran commented Apr 21, 2022

No description provided.

@tiran tiran force-pushed the bpo-40280-emscripten_info branch from 91bfe71 to 3acf409 Compare April 21, 2022 10:06
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

What's the recipe using this new attribute to test if Python runs in a browser?

def is_browser():
  return (not sys._emscripten_info.runtime.startswith("Node.js ")
          and sys._emscripten_info.runtime != "UNKNOWN")

Is that correct? What if the browser lies to set its user agent to "Node.js v1.0"?

Maybe you can rename runtime to runtime_version, and add a new runtime_name member which would be: "browser", "node" or "unknown"?

sys.implementation separates the Python implementation name from its version for example.

@tiran
Copy link
Member Author

tiran commented Apr 21, 2022

Why would you want to know that? The runtime is just for diagnostic purposes.

@vstinner
Copy link
Member

Why would you want to know that? The runtime is just for diagnostic purposes.

I expect that some things only work on Node but not in a browser. For example, we might use it to skip some tests.

If all runtime would be the exactly the same, it wouldn't be useful to add this new sys attribute :-) Python has many variables like that, used to skip tests: sys.thread_info, sys.int_info, sys.implementation, etc.

@tiran
Copy link
Member Author

tiran commented Apr 21, 2022

I call YAGNI

It is unlikely that we need to differentiate between browser and node as runtime. If we ever need to check for it, then a naive browser vs. node is probably insufficient. Instead we will have to check for optional WASM runtime features like simd128, atomics, or SAB.

Let's revisit the problem when it arises. The API is deliberately marked as private and provisional for 3.11.

@vstinner
Copy link
Member

It is unlikely that we need to differentiate between browser and node as runtime.

If they would be the same, the list of disabled C extensions would be the same.

Instead we will have to check for optional WASM runtime features like simd128, atomics, or SAB.

That's a different issue, no?

@tiran
Copy link
Member Author

tiran commented Apr 21, 2022

If they would be the same, the list of disabled C extensions would be the same.

That is a different issue.

@tiran tiran changed the title gh-84461: Add sys._emscripten_info, improve docs and build gh-84461: Add sys._emscripten_info, improve docs and build (gh-91781) Apr 23, 2022
@tiran tiran merged commit 9b5ca54 into python:main Apr 23, 2022
@tiran tiran deleted the bpo-40280-emscripten_info branch April 23, 2022 07:52
@vstinner
Copy link
Member

Nice enhancement!

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

Successfully merging this pull request may close these issues.

4 participants