Python matplotlib.get_cachedir() Examples

The following are 9 code examples of matplotlib.get_cachedir(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib , or try the search function .
Example #1
Source File: tools.py    From mplhep with MIT License 6 votes vote down vote up
def hardcopy_fonts():
    path = os.path.abspath(__file__)
    pkg_dir = "/" + "/".join(path.split("/")[:-1])
    os.system(
        "cp -r {}/fonts/firasans/* ".format(pkg_dir)
        + os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
    )
    os.system(
        "cp -r {}/fonts/firamath/* ".format(pkg_dir)
        + os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
    )
    os.system(
        "cp -r {}/fonts/texgyreheros/* ".format(pkg_dir)
        + os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
    )
    os.system("rm " + os.path.join(mpl.get_cachedir() + "/font*")) 
Example #2
Source File: compare.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def get_cache_dir():
    cachedir = matplotlib.get_cachedir()
    if cachedir is None:
        raise RuntimeError('Could not find a suitable configuration directory')
    cache_dir = os.path.join(cachedir, 'test_cache')
    try:
        Path(cache_dir).mkdir(parents=True, exist_ok=True)
    except IOError:
        return None
    if not os.access(cache_dir, os.W_OK):
        return None
    return cache_dir 
Example #3
Source File: compare.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_cache_dir():
    cachedir = matplotlib.get_cachedir()
    if cachedir is None:
        raise RuntimeError('Could not find a suitable configuration directory')
    cache_dir = os.path.join(cachedir, 'test_cache')
    try:
        Path(cache_dir).mkdir(parents=True, exist_ok=True)
    except IOError:
        return None
    if not os.access(cache_dir, os.W_OK):
        return None
    return cache_dir 
Example #4
Source File: compare.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def get_cache_dir():
    cachedir = matplotlib.get_cachedir()
    if cachedir is None:
        raise RuntimeError('Could not find a suitable configuration directory')
    cache_dir = os.path.join(cachedir, 'test_cache')
    try:
        Path(cache_dir).mkdir(parents=True, exist_ok=True)
    except IOError:
        return None
    if not os.access(cache_dir, os.W_OK):
        return None
    return cache_dir 
Example #5
Source File: compare.py    From CogAlg with MIT License 5 votes vote down vote up
def get_cache_dir():
    cachedir = mpl.get_cachedir()
    if cachedir is None:
        raise RuntimeError('Could not find a suitable configuration directory')
    cache_dir = os.path.join(cachedir, 'test_cache')
    try:
        Path(cache_dir).mkdir(parents=True, exist_ok=True)
    except IOError:
        return None
    if not os.access(cache_dir, os.W_OK):
        return None
    return cache_dir 
Example #6
Source File: compare.py    From GraphicDesignPatternByPython with MIT License 4 votes vote down vote up
def convert(filename, cache):
    """
    Convert the named file to png; return the name of the created file.

    If *cache* is True, the result of the conversion is cached in
    `matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
    hash of the exact contents of the input file.  There is no limit on the
    size of the cache, so it may need to be manually cleared periodically.
    """
    base, extension = filename.rsplit('.', 1)
    if extension not in converter:
        reason = "Don't know how to convert %s files to png" % extension
        from . import is_called_from_pytest
        if is_called_from_pytest():
            import pytest
            pytest.skip(reason)
        else:
            from nose import SkipTest
            raise SkipTest(reason)
    newname = base + '_' + extension + '.png'
    if not os.path.exists(filename):
        raise IOError("'%s' does not exist" % filename)

    # Only convert the file if the destination doesn't already exist or
    # is out of date.
    if (not os.path.exists(newname) or
            os.stat(newname).st_mtime < os.stat(filename).st_mtime):
        if cache:
            cache_dir = get_cache_dir()
        else:
            cache_dir = None

        if cache_dir is not None:
            hash_value = get_file_hash(filename)
            new_ext = os.path.splitext(newname)[1]
            cached_file = os.path.join(cache_dir, hash_value + new_ext)
            if os.path.exists(cached_file):
                shutil.copyfile(cached_file, newname)
                return newname

        converter[extension](filename, newname)

        if cache_dir is not None:
            shutil.copyfile(newname, cached_file)

    return newname 
Example #7
Source File: compare.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def convert(filename, cache):
    """
    Convert the named file to png; return the name of the created file.

    If *cache* is True, the result of the conversion is cached in
    `matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
    hash of the exact contents of the input file.  There is no limit on the
    size of the cache, so it may need to be manually cleared periodically.
    """
    base, extension = filename.rsplit('.', 1)
    if extension not in converter:
        reason = "Don't know how to convert %s files to png" % extension
        from . import is_called_from_pytest
        if is_called_from_pytest():
            import pytest
            pytest.skip(reason)
        else:
            from nose import SkipTest
            raise SkipTest(reason)
    newname = base + '_' + extension + '.png'
    if not os.path.exists(filename):
        raise IOError("'%s' does not exist" % filename)

    # Only convert the file if the destination doesn't already exist or
    # is out of date.
    if (not os.path.exists(newname) or
            os.stat(newname).st_mtime < os.stat(filename).st_mtime):
        if cache:
            cache_dir = get_cache_dir()
        else:
            cache_dir = None

        if cache_dir is not None:
            hash_value = get_file_hash(filename)
            new_ext = os.path.splitext(newname)[1]
            cached_file = os.path.join(cache_dir, hash_value + new_ext)
            if os.path.exists(cached_file):
                shutil.copyfile(cached_file, newname)
                return newname

        converter[extension](filename, newname)

        if cache_dir is not None:
            shutil.copyfile(newname, cached_file)

    return newname 
Example #8
Source File: compare.py    From coffeegrindsize with MIT License 4 votes vote down vote up
def convert(filename, cache):
    """
    Convert the named file to png; return the name of the created file.

    If *cache* is True, the result of the conversion is cached in
    `matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
    hash of the exact contents of the input file.  There is no limit on the
    size of the cache, so it may need to be manually cleared periodically.
    """
    base, extension = filename.rsplit('.', 1)
    if extension not in converter:
        reason = "Don't know how to convert %s files to png" % extension
        from . import is_called_from_pytest
        if is_called_from_pytest():
            import pytest
            pytest.skip(reason)
        else:
            from nose import SkipTest
            raise SkipTest(reason)
    newname = base + '_' + extension + '.png'
    if not os.path.exists(filename):
        raise IOError("'%s' does not exist" % filename)

    # Only convert the file if the destination doesn't already exist or
    # is out of date.
    if (not os.path.exists(newname) or
            os.stat(newname).st_mtime < os.stat(filename).st_mtime):
        if cache:
            cache_dir = get_cache_dir()
        else:
            cache_dir = None

        if cache_dir is not None:
            hash_value = get_file_hash(filename)
            new_ext = os.path.splitext(newname)[1]
            cached_file = os.path.join(cache_dir, hash_value + new_ext)
            if os.path.exists(cached_file):
                shutil.copyfile(cached_file, newname)
                return newname

        converter[extension](filename, newname)

        if cache_dir is not None:
            shutil.copyfile(newname, cached_file)

    return newname 
Example #9
Source File: compare.py    From CogAlg with MIT License 4 votes vote down vote up
def convert(filename, cache):
    """
    Convert the named file to png; return the name of the created file.

    If *cache* is True, the result of the conversion is cached in
    `matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
    hash of the exact contents of the input file.  There is no limit on the
    size of the cache, so it may need to be manually cleared periodically.
    """
    base, extension = filename.rsplit('.', 1)
    if extension not in converter:
        reason = "Don't know how to convert %s files to png" % extension
        from . import is_called_from_pytest
        if is_called_from_pytest():
            import pytest
            pytest.skip(reason)
        else:
            from nose import SkipTest
            raise SkipTest(reason)
    newname = base + '_' + extension + '.png'
    if not os.path.exists(filename):
        raise IOError("'%s' does not exist" % filename)

    # Only convert the file if the destination doesn't already exist or
    # is out of date.
    if (not os.path.exists(newname) or
            os.stat(newname).st_mtime < os.stat(filename).st_mtime):
        if cache:
            cache_dir = get_cache_dir()
        else:
            cache_dir = None

        if cache_dir is not None:
            hash_value = get_file_hash(filename)
            new_ext = os.path.splitext(newname)[1]
            cached_file = os.path.join(cache_dir, hash_value + new_ext)
            if os.path.exists(cached_file):
                shutil.copyfile(cached_file, newname)
                return newname

        converter[extension](filename, newname)

        if cache_dir is not None:
            shutil.copyfile(newname, cached_file)

    return newname