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

Change sys.executable to include executable suffix #72627

Closed
embray opened this issue Oct 14, 2016 · 9 comments
Closed

Change sys.executable to include executable suffix #72627

embray opened this issue Oct 14, 2016 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@embray
Copy link
Contributor

embray commented Oct 14, 2016

BPO 28441
Nosy @methane, @embray, @zware, @ma8ma
PRs
  • bpo-28441: Ensure .exe suffix in sys.executable on MinGW and Cygwin #4348
  • [3.7] bpo-28441: Ensure .exe suffix in sys.executable on MinGW and Cygwin (GH-4348) #12063
  • Files
  • cygwin-sys-executable.patch
  • sys-executable-suffix.patch
  • sys-executable-suffix-2.patch
  • sys-executable-suffix-3.patch
  • 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 2018-10-05.11:46:28.309>
    created_at = <Date 2016-10-14.13:34:45.608>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = 'Change sys.executable to include executable suffix'
    updated_at = <Date 2019-02-27.17:10:20.021>
    user = 'https://github.com/embray'

    bugs.python.org fields:

    activity = <Date 2019-02-27.17:10:20.021>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-05.11:46:28.309>
    closer = 'methane'
    components = ['Interpreter Core']
    creation = <Date 2016-10-14.13:34:45.608>
    creator = 'erik.bray'
    dependencies = []
    files = ['45091', '45137', '45327', '45685']
    hgrepos = []
    issue_num = 28441
    keywords = ['patch', 'needs review']
    message_count = 9.0
    messages = ['278651', '278736', '278799', '278943', '279957', '280204', '281969', '327126', '336738']
    nosy_count = 4.0
    nosy_names = ['methane', 'erik.bray', 'zach.ware', 'masamoto']
    pr_nums = ['4348', '12063']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28441'
    versions = ['Python 3.7', 'Python 3.8']

    @embray
    Copy link
    Contributor Author

    embray commented Oct 14, 2016

    This actually came up previously in bpo-1543469 in the context of test_subprocess, but it's a more general issue that I thought was worth addressing somehow.

    The issue here is that as Cygwin tries to provide a "UNIX-like" experience, any system interfaces that take the path to an executable as an argument allow the .exe extension to be left off. This is particularly convenient for the shell experience, so that one can run, for example "python" or "ls" without typing "python.exe" or "ls.exe" (this is of course true of the Windows cmd shell as well).

    In the case of ambiguity however--such as when there is both a "python" and a "python.exe" in the same path, one must explicitly add the ".exe", otherwise the path without the exe is assumed. This is made even worse when you factor in case-insensitivity.

    Thus, this becomes a real annoyance when developing Python on Cygwin because you get both a "python.exe" and the "Python" directory in your source tree. This isn't so much of a problem, except that sys.executable leaves off the ".exe" (in UNIX-y fashion), so any test that calls Popen([sys.executable]) errors out because it thinks you're trying to execute a directory (Python/).

    I think the only reasonable fix is to take the patch suggested at bpo-1543469, and ensure that the ".exe" suffix is appended to sys.executable on Cygwin. I think that sys.executable should be as unambiguous as possible, and that's the only way to make it reasonably unambiguous on Cygwin.

    I've attached a patch adapted from the one in bpo-1543469 which solves the issue for me.

    @embray embray added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Oct 14, 2016
    @ma8ma
    Copy link
    Mannequin

    ma8ma mannequin commented Oct 15, 2016

    This patch has impact to end user, thus I don't agree to apply as far as Cygwin to avoid user surprise.
    I think to need a consistency between other platforms having executable suffix (e.g. MSYS2), and also the patch needs short documentation of changing behavior to description for sys.executable.

    @embray
    Copy link
    Contributor Author

    embray commented Oct 17, 2016

    I agree this has a slight change in behavior which I was at first hesitant about. But I think the previous behavior was wrong insofar as it was overly ambiguous. I agree it should apply on MSYS2 as well (I actually thought __CYGWIN__ was defined on MSYS2 but I could be wrong about that).

    I'm not sure what better solution there is. I thought of tinkering with subprocess specifically, but that was too fragile.

    @ma8ma
    Copy link
    Mannequin

    ma8ma mannequin commented Oct 18, 2016

    I agree to add the suffix to solve ambiguous path on Cygwin. And I think the patch should apply to all platforms having executable suffix.

    Therefore, I modified your patch to remove #if directive for Cygwin, and I changed title to spread covered platforms.
    This patch uses EXE_SUFFIX that is the EXE defined on Makefile. If platform doesn't have executable suffix, doesn't add anything process.

    @ma8ma ma8ma mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 18, 2016
    @ma8ma ma8ma mannequin changed the title sys.executable is ambiguous on Cygwin without .exe suffix Change sys.executable to include executable suffix Oct 18, 2016
    @ma8ma
    Copy link
    Mannequin

    ma8ma mannequin commented Nov 3, 2016

    I have missed a case of empty progpath. I updated the patch to avoid calling add_exe_suffix() at that case.

    @embray
    Copy link
    Contributor Author

    embray commented Nov 7, 2016

    Thanks! Setting EXE_SUFFIX from the Makefile is much better.

    @ma8ma
    Copy link
    Mannequin

    ma8ma mannequin commented Nov 29, 2016

    I updated a patch to check the made path because previous patch has added suffix even to symbolic link. New patch works that If made path is invalid, revert to original.

    @methane
    Copy link
    Member

    methane commented Oct 5, 2018

    New changeset 7a7693e by INADA Naoki (E. M. Bray) in branch 'master':
    bpo-28441: Ensure .exe suffix in sys.executable on MinGW and Cygwin (GH-4348)
    7a7693e

    @methane methane added 3.8 only security fixes and removed 3.7 (EOL) end of life labels Oct 5, 2018
    @methane methane closed this as completed Oct 5, 2018
    @methane
    Copy link
    Member

    methane commented Feb 27, 2019

    New changeset e5897b6 by Inada Naoki (Miss Islington (bot)) in branch '3.7':
    bpo-28441: Ensure .exe suffix in sys.executable on MinGW and Cygwin (GH-4348)
    e5897b6

    @ned-deily ned-deily added the 3.7 (EOL) end of life label Feb 27, 2019
    @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
    3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants