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
import searchpaths as arguments #67324
Comments
This patch allows specifying import searchpaths as Avoiding environment variables simplifies a script of mine and is a portable way of swapping module implementation without touching the importing script. e.g. It is implemented by prepending the arguments to sys.path in Py_Main just after Py_Initialize is called. |
Thank you for the suggestion and patch, but we have a general policy of not adding unnecessary command line options, so I don't know that it will be accepted. |
bpo-13475 provides some additional context for discussion of changes to the sys.path initialisation process. The status quo is that I'm currently wary of adding more complexity to an already fragile initialisation sequence for things that can be implemented by way of running a custom launch script that uses the runpy module to replicate the CPython script invocation options. In the specific case of this patch, while the idea is one we've considered before (and may end up implementing some day), this specific implementation adds new path initilisation logic directly in Py_Main, well away from getpath.c (which, in collaboration with site.py, is intended to fully handle the path initialisation logic), and without being separated out into a distinct API that embedding applications can easily take advantage of. A lot of Python code will also run *before* the command line arguments are processed, so you'll end up with a case where code run early may pick up a version of a module from later in sys.path, giving the appearance that the sys.path additions are being ignored, even though they appear in sys.path after the program is fully initialised. While the technical concerns mean it isn't likely this particular approach would be pursued further, as a practical matter, additional things that would be needed for a patch to the interpreter argument handling to be accepted include:
|
Thanks for the feedback. The technical arguments convinced me not to spend more time on this. I admit this patch is kind of an ugly hack. The effort needed for a technically satisfactory solution seems too much for this unimportant feature. |
import searchpaths as arguments
as patch to /Module/main.cNote: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: