Skip to content

Commit

Permalink
Fix Appveyor build.
Browse files Browse the repository at this point in the history
Recent condas prefer (by default) packages in higher priority channels
to packages in lower priority channels regardless of their versions.
conda-forge sometimes serves older condas than the official repos, so we
need to put it at the end to avoid accidentally downgrading conda.

Do not depend on the user name to construct a temporary cache directory
when needed, as e.g. conda-build hides the required environment variable
(`%USERNAME%`) on Windows.

Simplify implementation of `matplotlib_fname`.
  • Loading branch information
anntzer committed Mar 19, 2017
1 parent 9d802a9 commit 0140c84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
4 changes: 3 additions & 1 deletion appveyor.yml
Expand Up @@ -68,7 +68,9 @@ install:
# for obvci_appveyor_python_build_env.cmd
- cmd: conda install -c pelson/channel/development --yes --quiet obvious-ci
# for msinttypes and newer stuff
- cmd: conda config --add channels conda-forge
# conda-forge may serve outdated versions of certain packages (e.g. conda
# itself), so append it to the end of the list.
- cmd: conda config --append channels conda-forge
- cmd: conda config --set show_channel_urls yes
- cmd: conda config --set always_yes true
# For building conda packages
Expand Down
61 changes: 20 additions & 41 deletions lib/matplotlib/__init__.py
Expand Up @@ -575,26 +575,15 @@ def _create_tmp_config_dir():
Returns None if a writable temporary directory could not be created.
"""
import getpass
import tempfile
from matplotlib.cbook import mkdirs

try:
tempdir = tempfile.gettempdir()
except NotImplementedError:
# Some restricted platforms (such as Google App Engine) do not provide
# gettempdir.
return None
try:
username = getpass.getuser()
except KeyError:
username = str(os.getuid())

tempdir = tempfile.mkdtemp(prefix='matplotlib-%s-' % username, dir=tempdir)

os.environ['MPLCONFIGDIR'] = tempdir

return tempdir
configdir = os.environ['MPLCONFIGDIR'] = (
tempfile.mkdtemp(prefix='matplotlib-', dir=tempdir))
return configdir


get_home = verbose.wrap('$HOME=%s', _get_home, always=False)
Expand Down Expand Up @@ -805,34 +794,24 @@ def matplotlib_fname():
- Lastly, it looks in `$MATPLOTLIBDATA/matplotlibrc` for a
system-defined copy.
"""
if six.PY2:
cwd = os.getcwdu()
else:
cwd = os.getcwd()
fname = os.path.join(cwd, 'matplotlibrc')
if os.path.exists(fname):
return fname

if 'MATPLOTLIBRC' in os.environ:
path = os.environ['MATPLOTLIBRC']
if os.path.exists(path):
if os.path.isfile(path):
return path
fname = os.path.join(path, 'matplotlibrc')
if os.path.exists(fname):
return fname

configdir = _get_configdir()
if os.path.exists(configdir):
fname = os.path.join(configdir, 'matplotlibrc')
if os.path.exists(fname):
return fname

path = get_data_path() # guaranteed to exist or raise
fname = os.path.join(path, 'matplotlibrc')
if not os.path.exists(fname):
warnings.warn('Could not find matplotlibrc; using defaults')

def gen_candidates():
yield os.path.join(six.moves.getcwd(), 'matplotlibrc')
try:
matplotlibrc = os.environ['MATPLOTLIBRC']
except KeyError:
pass
else:
yield matplotlibrc
yield os.path.join(matplotlibrc, 'matplotlibrc')
yield os.path.join(_get_configdir(), 'matplotlibrc')
yield os.path.join(get_data_path(), 'matplotlibrc')

for fname in gen_candidates():
if os.path.isfile(fname):
break
# Return first candidate that is a file, or last candidate if none is
# valid (in that case, a warning is raised at startup by `rc_params`).
return fname


Expand Down

0 comments on commit 0140c84

Please sign in to comment.