Skip to content

Commit

Permalink
matplotlib data is installed in the matplotlib module like package_data
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=1915
  • Loading branch information
cmoad committed Dec 12, 2005
1 parent 3f03686 commit 2acdd18
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 53 deletions.
5 changes: 5 additions & 0 deletions API_CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Matplotlib data is installed into the matplotlib module.
This is similar to package_data. This should get rid of
having to check for many possibilties in _get_data_path().
The MATPLOTLIBDATA env key is still checked first to allow
for flexibility.

1) Separated the color table data from cm.py out into
a new file, _cm.py, to make it easier to find the actual
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2005-12-12 Matplotlib data is now installed as package_data in
the matplotlib module. This gets rid of checking the
many possibilities in matplotlib._get_data_path() - CM

2005-12-11 Support for setuptools/pkg_resources to build and use
matplotlib as an egg. Still allows matplotlib to exist
using a traditional distutils install. - ADS
Expand Down
98 changes: 53 additions & 45 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,55 +367,63 @@ def _get_configdir():

def _get_data_path():
'get the path to matplotlib data'

if _have_pkg_resources:
try:
dist = pkg_resources.get_distribution('matplotlib')
except pkg_resources.DistributionNotFound:
# pkg_resources is installed, but setuptools wasn't used into install matplotlib.
used_setuptools_to_install_MPL = False
else:
used_setuptools_to_install_MPL = True

if used_setuptools_to_install_MPL:
req = pkg_resources.Requirement.parse('matplotlib')
path = pkg_resources.resource_filename(req, 'share/matplotlib')
return path


if os.environ.has_key('MATPLOTLIBDATA'):
path = os.environ['MATPLOTLIBDATA']
if os.path.isdir(path): return path

else:
path = os.sep.join([os.path.dirname(__file__), 'mpl-data'])
if os.path.isdir(path): return path

path = os.path.join(distutils.sysconfig.PREFIX, 'share', 'matplotlib')
if os.path.isdir(path): return path

path = '/usr/local/share/matplotlib'
if os.path.isdir(path): return path

path = '/usr/share/matplotlib'
if os.path.isdir(path): return path

path = os.path.join(os.sep.join(__file__.split(os.sep)[:-1]),
'share','matplotlib')
if os.path.isdir(path): return path

path = os.path.join(os.sep.join(__file__.split(os.sep)[:-5]),
'share','matplotlib')
if os.path.isdir(path): return path

# CODE ADDED TO SUPPORT PY2EXE - you will need to copy
# C:\Python23\share\matplotlib into your dist dir. See
# http://starship.python.net/crew/theller/moin.cgi/MatPlotLib
# for more info

if sys.platform=='win32' and sys.frozen:
path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlibdata')
if os.path.isdir(path): return path
else:
# Try again assuming sys.path[0] is a dir not a exe
path = os.path.join(sys.path[0], 'matplotlibdata')
if os.path.isdir(path): return path

# if _have_pkg_resources:
# try:
# dist = pkg_resources.get_distribution('matplotlib')
# except pkg_resources.DistributionNotFound:
# # pkg_resources is installed, but setuptools wasn't used into install matplotlib.
# used_setuptools_to_install_MPL = False
# else:
# used_setuptools_to_install_MPL = True
#
# if used_setuptools_to_install_MPL:
# req = pkg_resources.Requirement.parse('matplotlib')
# path = pkg_resources.resource_filename(req, 'share/matplotlib')
# return path
#
# if os.environ.has_key('MATPLOTLIBDATA'):
# path = os.environ['MATPLOTLIBDATA']
# if os.path.isdir(path): return path
#
# path = os.path.join(distutils.sysconfig.PREFIX, 'share', 'matplotlib')
# if os.path.isdir(path): return path
#
# path = '/usr/local/share/matplotlib'
# if os.path.isdir(path): return path
#
# path = '/usr/share/matplotlib'
# if os.path.isdir(path): return path
#
# path = os.path.join(os.sep.join(__file__.split(os.sep)[:-1]),
# 'share','matplotlib')
# if os.path.isdir(path): return path
#
# path = os.path.join(os.sep.join(__file__.split(os.sep)[:-5]),
# 'share','matplotlib')
# if os.path.isdir(path): return path
#
# # CODE ADDED TO SUPPORT PY2EXE - you will need to copy
# # C:\Python23\share\matplotlib into your dist dir. See
# # http://starship.python.net/crew/theller/moin.cgi/MatPlotLib
# # for more info
#
# if sys.platform=='win32' and sys.frozen:
# path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlibdata')
# if os.path.isdir(path): return path
# else:
# # Try again assuming sys.path[0] is a dir not a exe
# path = os.path.join(sys.path[0], 'matplotlibdata')
# if os.path.isdir(path): return path
#
raise RuntimeError('Could not find the matplotlib data files')

get_data_path = verbose.wrap('matplotlib data path %s', _get_data_path, always=False)
Expand Down
32 changes: 24 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
import os
if os.path.exists('MANIFEST'): os.remove('MANIFEST')

from distutils.core import setup

try:
from setuptools import setup # use setuptools if possible
has_setuptools = True
except ImportError:
pass
from distutils.core import setup
has_setuptools = False

import sys,os
import glob
Expand All @@ -81,9 +81,25 @@
if line[:11] == '__version__':
exec(line)
break


# Find the plat-lib dir where mpl will be installed.
# This is where the mpl-data will be installed.
from distutils.command.install import INSTALL_SCHEMES

if has_setuptools: # EGG's make it simple
datapath = os.path.curdir
# logic from distutils.command.install.finalize_options
elif os.name == 'posix':
py_version_short = sys.version[0:3]
datapath = INSTALL_SCHEMES['unix_prefix']['platlib']
datapath = datapath.replace('$platbase/', '').replace('$py_version_short', py_version_short)
else:
datapath = INSTALL_SCHEMES[os.name]['platlib'].replace('$base/', '')

datapath = os.sep.join([datapath, 'matplotlib', 'mpl-data']) # This is where mpl data will be installed

# Specify all the required mpl data
data = []

data.extend(glob.glob('gui/*.glade'))
data.extend(glob.glob('fonts/afm/*.afm'))
data.extend(glob.glob('fonts/ttf/*.ttf'))
Expand All @@ -93,10 +109,10 @@
data.extend(glob.glob('images/*.ppm'))
data.append('matplotlibrc')

data_files=[('share/matplotlib', data),]
data_files=[(datapath, data),]

# Needed for CocoaAgg
data_files.append(('share/matplotlib/Matplotlib.nib',
data_files.append((os.sep.join([datapath, 'Matplotlib.nib']),
glob.glob('lib/matplotlib/backends/Matplotlib.nib/*.nib')))

# Figure out which array packages to provide binary support for
Expand Down Expand Up @@ -265,7 +281,7 @@ def add_dateutil():



setup(name="matplotlib",
distrib = setup(name="matplotlib",
version= __version__,
description = "Matlab(TM) style python plotting package",
author = "John D. Hunter",
Expand Down

0 comments on commit 2acdd18

Please sign in to comment.