Skip to content

Remove support for -dbackend argv. #8148

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

Merged
merged 1 commit into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/api_changes/2017-02-25-AL_dbackend.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``-d$backend`` no longer sets the backend
`````````````````````````````````````````

It is no longer possible to set the backend by passing ``-d$backend`` at the command line. Use the ``MPLBACKEND`` environment variable instead.
7 changes: 1 addition & 6 deletions doc/devel/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,24 +415,19 @@ Developing a new backend

If you are working on a custom backend, the *backend* setting in
:file:`matplotlibrc` (:ref:`customizing-matplotlib`) supports an
external backend via the ``module`` directive. if
external backend via the ``module`` directive. If
:file:`my_backend.py` is a Matplotlib backend in your
:envvar:`PYTHONPATH`, you can set it on one of several ways

* in :file:`matplotlibrc`::

backend : module://my_backend


* with the :envvar:`MPLBACKEND` environment variable::

> export MPLBACKEND="module://my_backend"
> python simple_plot.py

* from the command shell with the `-d` flag::

> python simple_plot.py -dmodule://my_backend

* with the use directive in your script::

import matplotlib
Expand Down
5 changes: 2 additions & 3 deletions doc/faq/environment_variables_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ Environment Variables

.. envvar:: MPLBACKEND

This optional variable can be set to choose the matplotlib backend. Using the
`-d` command line parameter or the :func:`~matplotlib.use` function will
override this value. See :ref:`what-is-a-backend`.
This optional variable can be set to choose the matplotlib backend. See
:ref:`what-is-a-backend`.

.. _setting-linux-osx-environment-variables:

Expand Down
10 changes: 0 additions & 10 deletions doc/faq/usage_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,6 @@ the method mentioned last in the following list will be used, e.g. calling
globally, e.g. in your ``.bashrc`` or ``.profile``, is discouraged as it
might lead to counter-intuitive behavior.

#. To set the backend for a single script, you can alternatively use the `-d`
command line argument::

> python script.py -dbackend

This method is **deprecated** as the `-d` argument might conflict with
scripts which parse command line arguments (see issue
`#1986 <https://github.com/matplotlib/matplotlib/issues/1986>`_). You
should use :envvar:`MPLBACKEND` instead.

#. If your script depends on a specific backend you can use the
:func:`~matplotlib.use` function::

Expand Down
34 changes: 7 additions & 27 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ def rc_file_defaults():
"""
rcParams.update(rcParamsOrig)


_use_error_msg = """
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
Expand Down Expand Up @@ -1408,6 +1409,12 @@ def use(arg, warn=True, force=False):
reload(sys.modules['matplotlib.backends'])


try:
use(os.environ['MPLBACKEND'])
except KeyError:
pass


def get_backend():
"""Return the name of the current backend."""
return rcParams['backend']
Expand Down Expand Up @@ -1435,33 +1442,6 @@ def tk_window_focus():
return False
return rcParams['tk.window_focus']

# Now allow command line to override

# Allow command line access to the backend with -d (MATLAB compatible
# flag)

for s in sys.argv[1:]:
# cast to str because we are using unicode_literals,
# and argv is always str
if s.startswith(str('-d')) and len(s) > 2: # look for a -d flag
try:
use(s[2:])
warnings.warn("Using the -d command line argument to select a "
"matplotlib backend is deprecated. Please use the "
"MPLBACKEND environment variable instead.",
mplDeprecation)
break
except (KeyError, ValueError):
pass
# we don't want to assume all -d flags are backends, e.g., -debug
else:
# no backend selected from the command line, so we check the environment
# variable MPLBACKEND
try:
use(os.environ['MPLBACKEND'])
except KeyError:
pass


# Jupyter extension paths
def _jupyter_nbextension_paths():
Expand Down