Skip to content

Commit

Permalink
resource_dirs() includes appdata dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Dec 20, 2014
1 parent 8777e29 commit 3df1d7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion imageio/core/fetching.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def get_remote_file(fname, directory=None, force_download=False):
# Get dirs to look for the resource
directory = directory or appdata_dir('imageio')
dirs = resource_dirs()
dirs.insert(0, appdata_dir('imageio'))
dirs.insert(0, directory) # Given dir has preference
# Try to find the resource locally
for dir in dirs:
Expand Down
8 changes: 7 additions & 1 deletion imageio/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,19 @@ def resource_dirs():
Get a list of directories where imageio resources may be located.
The first directory in this list is the "resources" directory in
the package itself. The list further contains the application
the package itself. The second directory is the appdata directory
(~/.imageio on Linux). The list further contains the application
directory (for frozen apps), and may include additional directories
in the future.
"""
dirs = []
# Resource dir baked in the package
dirs.append(os.path.abspath(os.path.join(THIS_DIR, '..', 'resources')))
# Appdata directory
try:
dirs.append(appdata_dir('imageio'))
except Exception:
pass # The home dir may not be writable
# Directory where the app is located (mainly for frozen apps)
if sys.path and sys.path[0]:
# Get the path. If frozen, sys.path[0] is the name of the executable,
Expand Down
15 changes: 4 additions & 11 deletions imageio/plugins/_freeimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import threading
import numpy

from ..core import get_remote_file, load_lib, Dict, appdata_dir, resource_dirs
from ..core import get_remote_file, load_lib, Dict, resource_dirs
from ..core import string_types, binary_type, IS_PYPY, get_platform

TEST_NUMPY_NO_STRIDES = False # To test pypy fallback
Expand Down Expand Up @@ -417,26 +417,19 @@ def error_handler(fif, message):

def _load_freeimage(self):

# Get lib dirs
lib_dirs = []
lib_dirs.extend(resource_dirs())
try:
lib_dirs.append(appdata_dir('imageio'))
except Exception:
pass # The home dir may not be writable

# Define names
lib_names = ['freeimage', 'libfreeimage']
exact_lib_names = ['FreeImage', 'libfreeimage.dylib',
'libfreeimage.so', 'libfreeimage.so.3']
# Add names of libraries that we provide (that file may not exist)
fname = FNAME_PER_PLATFORM[get_platform()]
for dir in lib_dirs:
res_dirs = resource_dirs()
for dir in res_dirs:
exact_lib_names.insert(0, os.path.join(dir, 'freeimage', fname))

# Load
try:
lib, fname = load_lib(exact_lib_names, lib_names, lib_dirs)
lib, fname = load_lib(exact_lib_names, lib_names, res_dirs)
except OSError: # pragma: no cover
# Could not load. Get why
e_type, e_value, e_tb = sys.exc_info()
Expand Down

0 comments on commit 3df1d7a

Please sign in to comment.