Issue 9910: Add Py_SetPath API for embedding python (original) (raw)

Created on 2010-09-21 06:32 by kristjan.jonsson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
py_setpath.patch kristjan.jonsson,2010-09-21 06:32
py_setpath.patch kristjan.jonsson,2010-09-25 03:03
Messages (6)
msg117030 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-21 06:32
When calling Py_Initialize() from an embedding application, there is currently no way for the application to override Python's initial settin g of sys.path. An elaborate mechanism in getpathp.c kicks in, guessing the path based on several criteria. Ideally, this mechanism, which is valid only for python.exe and its semantics, should be opt in. It forces embedders that have their own libraries to go through complicated hoops (with environment variables and what not) to direct their embedded interpreter at the right place for modules, and to make sure that it is not confused by any other python distribution present on the system. This submission adds a Py_SetPath() function to the API. This has been successfully used by CCP in EVE Online and other products to completely override python's path guessing mechanics. If called with a semicolon separated path prior to Py_Initialize, it will be used as the fodder for the initial sys.path.
msg117041 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-21 09:18
You must also update Modules/getpath.c. You should also add documentation.
msg117345 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-25 03:03
Right, forgot about getpath.c. Added documentation. See the latest version of the patch. Please note that I was unable to test the non-windows compile.
msg117394 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-25 21:34
The patch compiles fine under Linux, but please don't use tabs for indentation of C files.
msg117398 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-26 02:13
Sorry, my mistake, I work in a mixed environment. If there are no objections, I´ll submit this (with fixed whitespace)
msg117437 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-27 05:33
Completed in revision 85028
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54119
2010-09-27 05:33:35 kristjan.jonsson set status: open -> closedresolution: acceptedmessages: +
2010-09-26 02:13:48 kristjan.jonsson set messages: +
2010-09-25 21:34:36 pitrou set messages: +
2010-09-25 03:22:50 kristjan.jonsson set title: Add Py_SetPath API for embeddint python -> Add Py_SetPath API for embedding python
2010-09-25 03:03:43 kristjan.jonsson set files: + py_setpath.patchmessages: +
2010-09-21 09🔞41 pitrou set nosy: + pitroumessages: +
2010-09-21 06:32:33 kristjan.jonsson create