From 0140c8427db0fab273b00b03233e05d68c4f4ffb Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 18 Mar 2017 15:03:32 -0700 Subject: [PATCH] Fix Appveyor build. 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`. --- appveyor.yml | 4 ++- lib/matplotlib/__init__.py | 61 +++++++++++++------------------------- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 510208ab98d1..04187566e873 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 84d98a2daea8..db96e64f1b9b 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -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) @@ -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