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

import searchpaths as arguments #67324

Closed
c2621566 mannequin opened this issue Dec 30, 2014 · 4 comments
Closed

import searchpaths as arguments #67324

c2621566 mannequin opened this issue Dec 30, 2014 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@c2621566
Copy link
Mannequin

c2621566 mannequin commented Dec 30, 2014

BPO 23135
Nosy @ncoghlan, @bitdancer, @vadmium
Files
  • main.c.searchpatharg1.diff: feature import searchpaths as arguments as patch to /Module/main.c
  • Note: 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:

    assignee = None
    closed_at = <Date 2014-12-31.19:03:46.707>
    created_at = <Date 2014-12-30.19:10:31.817>
    labels = ['interpreter-core', 'type-feature']
    title = 'import searchpaths as arguments'
    updated_at = <Date 2014-12-31.19:03:46.706>
    user = 'https://bugs.python.org/c2621566'

    bugs.python.org fields:

    activity = <Date 2014-12-31.19:03:46.706>
    actor = 'c2621566'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-12-31.19:03:46.707>
    closer = 'c2621566'
    components = ['Interpreter Core']
    creation = <Date 2014-12-30.19:10:31.817>
    creator = 'c2621566'
    dependencies = []
    files = ['37567']
    hgrepos = []
    issue_num = 23135
    keywords = ['patch']
    message_count = 4.0
    messages = ['233216', '233218', '233262', '233269']
    nosy_count = 4.0
    nosy_names = ['ncoghlan', 'r.david.murray', 'martin.panter', 'c2621566']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23135'
    versions = ['Python 3.5']

    @c2621566
    Copy link
    Mannequin Author

    c2621566 mannequin commented Dec 30, 2014

    This patch allows specifying import searchpaths as -p path arguments to the interpreter, without touching environment variables.

    Avoiding environment variables simplifies a script of mine and is a portable way of swapping module implementation without touching the importing script.

    e.g.
    # python -p ~/.bin/customlib -p ~/.bin/other script.py
    is equivalent to
    # PYTHONPATH=/.bin/customlib:/.bin/other:$PYTHONPATH python script.py
    similarly to
    # ghci -i.bin/customlib:.bin/other foo.hs

    It is implemented by prepending the arguments to sys.path in Py_Main just after Py_Initialize is called.

    @c2621566 c2621566 mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Dec 30, 2014
    @bitdancer
    Copy link
    Member

    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.

    @ncoghlan
    Copy link
    Contributor

    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:

    @c2621566
    Copy link
    Mannequin Author

    c2621566 mannequin commented Dec 31, 2014

    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.

    @c2621566 c2621566 mannequin closed this as completed Dec 31, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants