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

webbrowser.open outputs xdg-open deprecation warning #74405

Open
desbma mannequin opened this issue May 1, 2017 · 12 comments
Open

webbrowser.open outputs xdg-open deprecation warning #74405

desbma mannequin opened this issue May 1, 2017 · 12 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@desbma
Copy link
Mannequin

desbma mannequin commented May 1, 2017

BPO 30219
Nosy @vstinner, @serhiy-storchaka, @desbma
Files
  • issue30218-1.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 = None
    created_at = <Date 2017-05-01.12:34:17.421>
    labels = ['type-bug', 'library']
    title = 'webbrowser.open outputs xdg-open deprecation warning'
    updated_at = <Date 2017-05-12.20:31:16.055>
    user = 'https://github.com/desbma'

    bugs.python.org fields:

    activity = <Date 2017-05-12.20:31:16.055>
    actor = 'desbma'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-05-01.12:34:17.421>
    creator = 'desbma'
    dependencies = []
    files = ['46845']
    hgrepos = []
    issue_num = 30219
    keywords = ['patch']
    message_count = 12.0
    messages = ['292659', '292666', '292742', '292743', '293455', '293461', '293490', '293491', '293514', '293544', '293546', '293569']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'desbma']
    pr_nums = []
    priority = 'normal'
    resolution = 'third party'
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30219'
    versions = ['Python 3.6']

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 1, 2017

    Python 3.6.1 (default, Mar 27 2017, 00:27:06) 
    [GCC 6.3.1 20170306] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import webbrowser
    >>> webbrowser.open("https://www.google.com")
    True
    >>> This tool has been deprecated, use 'gio open' instead.
    See 'gio help open' for more info.

    A quick test reveals it is the invocation of xdg-open that outputs the warning:

    $ xdg-open --version
    xdg-open 1.1.0 rc3
    $ xdg-open https://www.google.com
    This tool has been deprecated, use 'gio open' instead.
    See 'gio help open' for more info.

    It can be quite annoying because in my program the message is outputted in a ncurses UI and it messes the display.

    Possible changes to fix this:

    • Silence xdg-open output (pass stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL in Popen call)
    • Detect and use "gio open" if available

    @desbma desbma mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 1, 2017
    @serhiy-storchaka
    Copy link
    Member

    Seems it outputs the warning only on Gnome. Actually, xdg-open tries to run gvfs-open if it is installed and it is the tool now depreciated. This issue is fixed in mainstream. [1]

    [1] https://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=0d6eebb27c562e8644ccf616ebdbddf82d0d2dd8

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 2, 2017

    I'm on Arch Linux with Cinnamon, all packages up to date and xdg-utils 1.1.1 (https://www.archlinux.org/packages/extra/any/xdg-utils/).

    The fix you mention has not been included in a release yet, last release of xdg-utils is from 2015 (https://portland.freedesktop.org/download/).

    So it likely many other Linux distributions are affected (eg. Ubuntu 16.04 LTS) and will never see a xdg-utils fix, if it is ever released.

    That is why I think we should consider silencing xdg-open's output at the Popen call line. I can't think of any downside of doing so.

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 2, 2017

    Also most other Popen calls in the webbrowser module already silence the called program's output, so it makes sense to do the same for the BackgroundBrowser class.

    Here is a small patch for discussion.

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 10, 2017

    Ping

    @vstinner
    Copy link
    Member

    p = subprocess.Popen(cmdline, close_fds=True,
    +                                     stdin=subprocess.DEVNULL,
    +                                     stdout=subprocess.DEVNULL,
    +                                     stderr=subprocess.DEVNULL,
                                          start_new_session=True)

    I don't think that always hiding output for any browser is a good idea.

    xdg-open is supposed to be cross-desktop (GNOME, XFCE, KDE, etc.).

    Maybe a better fix is to use "gio" if available, or fallback on xdg-open otherwise? But gio is specific to GNOME no? What if the user has GNOME and KDE installed?

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 11, 2017

    Why do you think this isn't a good idea?

    As a user, what am supposed to do with that warning:

    • about a program I have no idea I was calling (the webbrowser module abstraction is here so I don't have to think about it)
    • I have no control about it's invocation
    • the output comes asynchronously in my program and may be hard to link the the webbrowser.open call

    Also the specific example of this issue is a xdg-open deprecation warning, but it could be any other output that is hard for the user to take action on or understand where it's coming from.

    My understanding of the *current* code is that all graphical browsers are already started with their output tossed away (https://hg.python.org/cpython/file/tip/Lib/webbrowser.py#l196). It seems weird to keep it only for all the command line wrappers (xdg-open, gnome-open, etc.).
    Of course the TTY interactive browsers have a good reason to keep it, obviously.

    @vstinner
    Copy link
    Member

    Why do you think this isn't a good idea?

    If the command fails, you simplify have no idea of what happened. For example, thanks to stdout/stderr, you noticed the warning. Without stdout/stderr, the warning should be hidden.

    webbrowser is already able to detect that GNOME is running and uses gvfs-open in that case. Maybe we should exchange these two blocks of code to prefer gvfs-open over xdg-open on GNOME?

        # use xdg-open if around
        if shutil.which("xdg-open"):
            register("xdg-open", None, BackgroundBrowser("xdg-open"))
    
        # The default GNOME3 browser
        if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"):
            register("gvfs-open", None, BackgroundBrowser("gvfs-open"))

    Do you get the warning if you use gvfs-open?

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 11, 2017

    For example, thanks to stdout/stderr, you noticed the warning. Without stdout/stderr, the warning should be hidden.

    That is true, but as a Python user, it don't need to see that warning, only the xdg-utils developers do.
    I would have never seen it, and it would never have been a problem because xdg-util would have been updated to call gio open (with the commit mentioned above) long before gvfs-open is completely removed.

    Do you get the warning if you use gvfs-open?

    Of course, because gvfs-open is precisely the cause of the deprecation warning

    $ cat /usr/bin/gvfs-open
    #!/bin/sh
    replacement="gio open"
    help="gio help open"

    &2 echo "This tool has been deprecated, use '$replacement' instead."
    &2 echo "See '$help' for more info."
    &2 echo

    if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
      exec $help "$@:2"
    else
      exec $replacement "$@"
    fi

    @vstinner
    Copy link
    Member

    2017-05-11 20:42 GMT+02:00 desbma <report@bugs.python.org>:

    Of course, because gvfs-open is precisely the cause of the deprecation warning

    I don't understand something. Why do you consider that it's a Python
    bug, whereas xdg-open redirects to the deprecated gvfs-open tool?

    Why not reporting the bug to xdg-open?

    @serhiy-storchaka
    Copy link
    Member

    This bug already is fixed in develop branch of xdg-open. But the version including that fix still is not released. There may be years until it be released and main distributives update xdg-open.

    @desbma
    Copy link
    Mannequin Author

    desbma mannequin commented May 12, 2017

    The only issue with Python itself is that the output of a subprocess call hidden behind a high level abstraction is thrown into the user's face in an unexpected way.
    This just does not seem to be the right thing to do to me.

    The deprecation warning of xdg-open/gvfs-open is just a particular example that shows this problem.

    The "what if the output is actually useful?" argument does not hold IMHO, because the all the other browser invocations in the webbrowser module (except the TTY browsers of course) are properly silenced.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants