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

extend PyConfig to enable program name to be set via Py_SetProgramName #515

Open
mike-hunhoff opened this issue Jan 24, 2024 · 2 comments
Open

Comments

@mike-hunhoff
Copy link

Is your feature request related to a problem? Please describe.
I'm attempting to create an environment for Jep that mirrors that of the Python interpreter from which it was installed. This includes sys.prefix, sys.exec_prefix, sys.executable, sys._base_executable, etc. My understanding is that Python derives these and others from the path that is set via Py_SetProgramName. AFAIK Jep does not support configuring Python via Py_SetProgramName. Unfortunately I cannot rely on environment variables to determine how sys.prefix, etc. are set e.g. when running in a virtual environment.

Describe the solution you'd like
I'd like to see PyConfig extended to include protected String programName set via public PyConfig setProgramName(String programName) { ... and passed to Py_SetProgramName before Py_Initialize. This should prompt the embedded Python interpreter to properly set sys.prefix, etc.

Describe alternatives you've considered
I've considered setting sys.prefix, etc. manually from Python after Python has been initialized but it's nuanced and difficult to get the ordering correct. I'm open to suggestions here as well.

Additional context
NA

@bsteffensmeier
Copy link
Member

I am in favor of this change. Conceptually I think the jep PyConfig class should mirror the cpython PyConfig type wherever it is useful. The code for the new configuration should be almost identical to how we handle python home so it shouldn't be hard to figure out how to pass program name around. I think we should include this in the next release.

@mike-hunhoff If you would like to submit a PR that is the best way to ensure this gets included. Otherwise I have been meaning to update some code in that area to clean up deprecation warnings in newer Python versions so if I get to that I will also add this in.

@mike-hunhoff
Copy link
Author

Thanks for the response @bsteffensmeier ! I'm not sure I'll be able to get to this before you but I'll keep it on my list in case I come across extra cycles. I think this would be a big win for configuring the embedded Python interpreter using Jep's API.

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