python / cpython

The Python programming language
https://www.python.org/
Other
60.83k stars 29.36k forks source link

webbrowser.open outputs xdg-open deprecation warning #74405

Open 3b6a3ebd-2680-4fd8-9657-0a347350b1fc opened 7 years ago

3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago
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: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'library'] title = 'webbrowser.open outputs xdg-open deprecation warning' updated_at = user = 'https://github.com/desbma' ``` bugs.python.org fields: ```python activity = actor = 'desbma' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = 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'] ```

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago
    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:

    serhiy-storchaka commented 7 years ago

    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

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

    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.

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

    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.

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

    Ping

    vstinner commented 7 years ago
    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?

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

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

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

    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 commented 7 years ago

    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?

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

    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 commented 7 years ago

    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 commented 7 years ago

    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.

    3b6a3ebd-2680-4fd8-9657-0a347350b1fc commented 7 years ago

    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.