Skip to content

Fix -x option documentation #76231

Closed
Closed

Description

@vstinner
BPO 32050
Nosy @terryjreedy, @pfmoore, @vstinner, @tjguk, @zware, @serhiy-storchaka, @zooba
PRs
  • [2.7] bpo-32050: Fix -x option documentation #4423
  • bpo-32050: Deprecate -x option #4424
  • bpo-32050: Fix -x option documentation #4475
  • [3.6] bpo-32050: Fix -x option documentation (GH-4475) #4477
  • 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 2017-11-24.01:24:27.926>
    created_at = <Date 2017-11-16.15:49:19.715>
    labels = ['3.7', 'OS-windows']
    title = 'Fix -x option documentation'
    updated_at = <Date 2017-11-24.01:24:27.925>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-11-24.01:24:27.925>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-24.01:24:27.926>
    closer = 'vstinner'
    components = ['Windows']
    creation = <Date 2017-11-16.15:49:19.715>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32050
    keywords = ['patch']
    message_count = 17.0
    messages = ['306365', '306366', '306369', '306371', '306376', '306377', '306381', '306472', '306475', '306476', '306477', '306551', '306561', '306563', '306564', '306566', '306869']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'paul.moore', 'vstinner', 'tim.golden', 'zach.ware', 'serhiy.storchaka', 'steve.dower']
    pr_nums = ['4423', '4424', '4475', '4477']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32050'
    versions = ['Python 3.7']

    Activity

    1. vstinner commented on Nov 16, 2017

      @vstinner
      MemberAuthor

      Python has a -x option documented as a "DOS specific hack only":
      https://docs.python.org/dev/using/cmdline.html#cmdoption-x

      Python doesn't support MS-DOS since Python 2.1:
      https://www.python.org/dev/peps/pep-0011/#no-longer-supported-platforms

      I propose to deprecate the option in Python 3.7: using it emits a DeprecationWarning, option deprecated in the documentation; and remove the option in Python 3.8.

    2. added
      interpreter-core
      3.7 (EOL)
      on Nov 16, 2017
    3. vstinner commented on Nov 16, 2017

      @vstinner
      MemberAuthor

      The note in the documentation is wrong: the line number is correct when using the -x option, even if the first line is skipped.

      Example with Python 2.7:
      ---

      $ cat x.py 
      print(1)
      print(2)
      x
      $ python2 x.py 
      1
      2
      Traceback (most recent call last):
        File "x.py", line 3, in <module>
          x
      NameError: name 'x' is not defined
      
      $ python2 -x x.py 
      2
      Traceback (most recent call last):
        File "x.py", line 3, in <module>
          x
      NameError: name 'x' is not defined

      Attached PR 4423 fixes Python 2.7 documentation.

    4. serhiy-storchaka commented on Nov 16, 2017

      @serhiy-storchaka
      Member

      Python still supports Windows.

    5. vstinner commented on Nov 16, 2017

      @vstinner
      MemberAuthor

      Python still supports Windows.

      What is the use case for this option on Windows?

      On Unix, the first line is usually used for the shebang, a line like:

      #!/usr/bin/env python3

      But this shebang is seen as a comment in Python and Python simply ignore the shebang, seen as a comment.

    6. serhiy-storchaka commented on Nov 16, 2017

      @serhiy-storchaka
      Member

      The same as on DOS.

      Change the extension of the Python script from .py to .bat, and insert the following first line:

      @path\to\python -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9

      Now you can run it as a bat-file. The command in the first line will run Python, passing the name of this file and up to 9 arguments (you can make it passing more than 9 arguments, but I don't remember the syntax). "@" disables printing this command itself. The first line is not valid Python syntax, but due to the -x option it will be skipped.

    7. vstinner commented on Nov 16, 2017

      @vstinner
      MemberAuthor

      @path\to\python -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9

      Oh wow, I never saw that before.

      There is now a "py" launcher on Windows, do we still need such "hack"?

    8. added and removed
      interpreter-core
      on Nov 16, 2017
    9. serhiy-storchaka commented on Nov 16, 2017

      @serhiy-storchaka
      Member

      Yes, of course. The py launcher is not an alternative to this "hack". It just allows you to specify just "py" (with possible options -2, -3, -3.6) instead of hardcoding the full name to the Python binary or add the path to directory containing the Python binary to your PATH.

    10. terryjreedy commented on Nov 18, 2017

      @terryjreedy
      Member

      So the hack is not specific to DOS but is still needed for Windows .bat files. They run in Command Prompt, which was once called the DOS box. (I don't know if they work unaltered in PowerShell.) It seems that the doc should be updated.

    11. serhiy-storchaka commented on Nov 18, 2017

      @serhiy-storchaka
      Member

      The current short line of the description was enough to me for understanding what is the purpose of this option and how it can be used (I didn't use Windows for more than 10 years). But I was surprised not founding more detailed information about this feature in the documentation. Definitely it should be better documented. Most of users will have no ideas about this feature.

    12. serhiy-storchaka commented on Nov 18, 2017

      @serhiy-storchaka
      Member

      It seems to me that the best way is to add the following line at the start of the script:

      @path\to\python -x %0 %* & exit /b
      

      Or

      @py -3 -x %0 %* & exit /b
      
    13. vstinner commented on Nov 18, 2017

      @vstinner
      MemberAuthor

      Ok, I will update the doc instead of deprecating the option.

    14. vstinner commented on Nov 20, 2017

      @vstinner
      MemberAuthor

      New changeset 733b5f3 by Victor Stinner in branch '2.7':
      bpo-32050: Fix -x option documentation (bpo-4423)
      733b5f3

    15. changed the title [-]Deprecated python3 -x option[/-] [+]Fix -x option documentation[/+] on Nov 20, 2017
    16. vstinner commented on Nov 20, 2017

      @vstinner
      MemberAuthor

      New changeset c5a2071 by Victor Stinner in branch 'master':
      bpo-32050: Fix -x option documentation (bpo-4475)
      c5a2071

    17. vstinner commented on Nov 20, 2017

      @vstinner
      MemberAuthor

      New changeset 60a376c by Victor Stinner (Miss Islington (bot)) in branch '3.6':
      bpo-32050: Fix -x option documentation (GH-4475) (bpo-4477)
      60a376c

    18. vstinner commented on Nov 20, 2017

      @vstinner
      MemberAuthor

      I removed the note from the documentation since it was outdated.

      Serhiy, Terry: Do you want to work on a patch to rephrase the "DOS specific hack only" sentence?

      @py -3 -x %0 %* & exit /b

      I'm not a BATCH expert, so I don't know if this command works on all Windows version, or even on MS-DOS. So I'm not confident to propose such doc change myself, sorry.

    19. terryjreedy commented on Nov 20, 2017

      @terryjreedy
      Member

      I don't know either. Once of the Windows experts should review and revise.

    20. vstinner commented on Nov 24, 2017

      @vstinner
      MemberAuthor

      The initial proposition was to *deprecate* the option.

      In the meanwhile, I removed an outdated note.

      While the documentation is not perfect, I don't feel confortable to fix it, so I left it unchanged.

      I close this PR. Please open a new issue (with a PR if possible ;-)) if you want to enhance -x option documentation.

    21. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions