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

Detecting whether a Python was built by python-build-standalone #382

Open
charliermarsh opened this issue Oct 24, 2024 · 9 comments
Open
Labels
enhancement New feature or request

Comments

@charliermarsh
Copy link
Member

Due to #380, I'm looking for a way to detect whether a given Python interpreter was built by python-build-standalone. Is there any reliable metadata (maybe something on sysconfig.get_config_vars()) to support this?

@charliermarsh
Copy link
Member Author

charliermarsh commented Oct 24, 2024

For example, this is a candidate though could obviously cause problems (false negatives or false positives):

>>> sysconfig.get_config_vars()['prefix']
'/install'

But if there's some kind of dedicated flag or metadata, it would of course be preferable.

@zanieb
Copy link
Member

zanieb commented Oct 24, 2024

There shouldn't be false negatives from the sysconfig prefix variable, unless of course, the build process changes. I'm not opposed to setting something specific to reflect that it's a python-build-standalone build. I'm not sure where the correct place for that is. Probably something in sysconfig still?

@charliermarsh
Copy link
Member Author

(I just meant false negatives in the event that the value differed at some previous point in the python-build-standalone history -- but I didn't verify whether that's true.)

@charliermarsh
Copy link
Member Author

For what it's worth, I think there are good reasons not to have this exposed. It does enable clients to special-case python-build-standalone which ideally they shouldn't have to do.

@zanieb
Copy link
Member

zanieb commented Oct 24, 2024

The standalone distributions do need to be special cased though, i.e., sysconfig is known to be broken and installers (or other consumers) need to understand that and adjust their behavior accordingly — there's no clear path towards fixing these values at build time.

@indygreg
Copy link
Collaborator

Analogy to a web browser...

Issue is asking to use User-Agent detection.

Seasoned web developers will tell you to sniff for features/bugs and not use the UA string as a proxy.

For the same reason you shouldn't use UA strings, we shouldn't key off an "is PBS" flag.

But it could be nice to know a Python is PBS.

If someone wants to footgun themselves keying functionality off that flag, so be it.

Perhaps we could add the PBS advertisement in the Python --version output? I think there's a configure flag to add supplemental text here. It's analogous to a UA string and feels like the right place to put it.

@charliermarsh
Copy link
Member Author

@indygreg -- Can you think of anything we might use for the existing releases? :)

@indygreg
Copy link
Collaborator

For existing releases, the /install or /build references are probably the best we have. And those are prone to false positives.

It makes sense to expose something more explicit going forward.

Something in the version metadata (I think there's a vendor string or something) and maybe a new sysconfig define if a vendor string can't be easily read/parsed at runtime.

@charliermarsh charliermarsh added the enhancement New feature or request label Dec 18, 2024
@charliermarsh
Copy link
Member Author

(In uv, we now mark this in sysconfig after we unzip.)

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

No branches or pull requests

3 participants