Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Reintroduce examples.directory rc parameter #1479

Closed
wants to merge 2 commits into from

3 participants

@sandrotosi

The main reason is that in Debian we store sample_data in a directory outside
the Python modules location. This way we're able to specify that directory in a
more appropriate way, also to allow examples to work during package building (in
particular for the documentation part).

The code introduced is a partial revert of 6c5e961 (with very tiny changes).

See also: #1478

@sandrotosi sandrotosi Reintroduce examples.directory rc parameter
The main reason is that in Debian we store sample_data in a directory outside
the Python modules location.  This way we're able to specify that directory in a
more appropriate way, also to allow examples to work during package building (in
particular for the documentation part).

The code introduced is a partial revert of 6c5e9610 (with very tiny changes).
f5c67c3
@dmcdougall
Collaborator

It looks like examples.directory was removed in 6c5e961. This is just for reference, and also when I read this PR I remember there was some chatter on the mailing list about sample_data being removed.

@dmcdougall
Collaborator

Oh you already had the commit link in the original message -- I am apparently blind.

@dmcdougall
Collaborator

I think this is ok to merge, but I'm not a debian expert. Is there someone else more familiar with debian that can weigh in? I presume installed the sample_data in the same directory as the matplotlib module is not an acceptable solution?

@sandrotosi

It's not acceptable because python 2.x has different modules directory for any minor version: 2.6 and 2.7 uses 2 different dirs, so we will need to duplicate the directory, or symlink it; and then we have the py3k module dir, and we need to handle that too.

Debian policy specify to store data files in /usr/share (if binary independent) or /usr/lib/ , that's why the Debian package stores them in /usr/share/matplotlib .

@mdboom
Owner

Thanks. This looks fine. I had not realised that Debian was relying on the behavior when I made the change -- the real purpose of the commit was to remove the network accessing of sample data, which never worked for very long before breaking.

In the future, we should coordinate better about release candidates so we can catch these sorts of packaging issues before the final release.

Can you rebase against v1.2.x and resubmit the pull request? I think this really belongs on the maintenance branch.

@sandrotosi

Hi Michael,
Don't worry, I hadn't realized it either, until a user complained :) Additionally, I tested all the RCs that you released and still hadn't notice because during build-time the sample_data inside the module directory is used (so images are generated correctly) but then if you run an example with the debian package installed, it failed (and now we see that I don't run examples that much on my machine :)).

I've filed #1491 - let me know if it's ok.

@dmcdougall
Collaborator

Resolved by #1491.

@dmcdougall dmcdougall closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 10, 2012
  1. @sandrotosi

    Reintroduce examples.directory rc parameter

    sandrotosi authored
    The main reason is that in Debian we store sample_data in a directory outside
    the Python modules location.  This way we're able to specify that directory in a
    more appropriate way, also to allow examples to work during package building (in
    particular for the documentation part).
    
    The code introduced is a partial revert of 6c5e9610 (with very tiny changes).
Commits on Nov 12, 2012
  1. @sandrotosi
This page is out of date. Refresh to see the latest.
View
14 lib/matplotlib/__init__.py
@@ -823,6 +823,20 @@ def rc_params_from_file(fname, fail_on_error=False):
# this is the instance used by the matplotlib classes
rcParams = rc_params()
+if rcParams['examples.directory']:
+ # paths that are intended to be relative to matplotlib_fname()
+ # are allowed for the examples.directory parameter.
+ # However, we will need to fully qualify the path because
+ # Sphinx requires absolute paths.
+ if not os.path.isabs(rcParams['examples.directory']):
+ _basedir, _fname = os.path.split(matplotlib_fname())
+ # Sometimes matplotlib_fname() can return relative paths,
+ # Also, using realpath() guarentees that Sphinx will use
+ # the same path that matplotlib sees (in case of weird symlinks).
+ _basedir = os.path.realpath(_basedir)
+ _fullpath = os.path.join(_basedir, rcParams['examples.directory'])
+ rcParams['examples.directory'] = _fullpath
+
rcParamsOrig = rcParams.copy()
rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \
View
11 lib/matplotlib/cbook.py
@@ -21,6 +21,7 @@
import warnings
from weakref import ref, WeakKeyDictionary
+import matplotlib
import numpy as np
import numpy.ma as ma
@@ -570,9 +571,17 @@ def get_sample_data(fname, asfileobj=True):
`mpl-data/sample_data` directory. If *asfileobj* is `True`
return a file object, otherwise just a file path.
+ Set the rc parameter examples.directory to the directory where we should
+ look, if sample_data files are stored in a location different than
+ default (which is 'mpl-data/sample_data` at the same level of 'matplotlib`
+ Python module files).
+
If the filename ends in .gz, the file is implicitly ungzipped.
"""
- root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
+ if matplotlib.rcParams['examples.directory']:
+ root = matplotlib.rcParams['examples.directory']
+ else:
+ root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
path = os.path.join(root, fname)
if asfileobj:
View
3  lib/matplotlib/rcsetup.py
@@ -617,6 +617,9 @@ def __call__(self, s):
'keymap.xscale' : [['k', 'L'], validate_stringlist],
'keymap.all_axes' : ['a', validate_stringlist],
+ # sample data
+ 'examples.directory' : ['', str],
+
# Animation settings
'animation.writer' : ['ffmpeg', validate_movie_writer],
'animation.codec' : ['mpeg4', str],
View
3  matplotlibrc.template
@@ -423,6 +423,9 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
#keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
#keymap.all_axes : a # enable all axes
+# Control location of examples data files
+#examples.directory : '' # directory to look in for custom installation
+
###ANIMATION settings
#animation.writer : ffmpeg # MovieWriter 'backend' to use
#animation.codec : mp4 # Codec to use for writing movie
Something went wrong with that request. Please try again.