Skip to content

Commit

Permalink
Resolve conflicts following PR scikit-image#6886
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpquinn authored and mkcor committed May 22, 2023
1 parent ff3b7bf commit 0408c1d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
1 change: 0 additions & 1 deletion doc/source/release_notes/release_dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Improvements
API Changes
-----------

- ``data.create_image_fetcher`` is now private (gh-6854)


Bugfixes
Expand Down
2 changes: 0 additions & 2 deletions skimage/data/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ __all__ = [
'horse',
'hubble_deep_field',
'human_mitosis',
'image_fetcher',
'immunohistochemistry',
'kidney',
'lbp_frontal_face_cascade_filename',
Expand Down Expand Up @@ -67,7 +66,6 @@ from ._fetchers import (
horse,
hubble_deep_field,
human_mitosis,
image_fetcher,
immunohistochemistry,
kidney,
lbp_frontal_face_cascade_filename,
Expand Down
26 changes: 13 additions & 13 deletions skimage/data/_fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _create_image_fetcher():
return image_fetcher, data_dir


image_fetcher, data_dir = _create_image_fetcher()
_image_fetcher, data_dir = _create_image_fetcher()


def _skip_pytest_case_requiring_pooch(data_filename):
Expand Down Expand Up @@ -195,10 +195,10 @@ def _fetch(data_filename):
dataset has not been downloaded yet.
"""
expected_hash = registry[data_filename]
if image_fetcher is None:
if _image_fetcher is None:
cache_dir = osp.dirname(data_dir)
else:
cache_dir = str(image_fetcher.abspath)
cache_dir = str(_image_fetcher.abspath)

# Case 1: the file is already cached in `data_cache_dir`
cached_file_path = osp.join(cache_dir, data_filename)
Expand All @@ -212,7 +212,7 @@ def _fetch(data_filename):
return legacy_file_path

# Case 3: file is not present locally
if image_fetcher is None:
if _image_fetcher is None:
_skip_pytest_case_requiring_pooch(data_filename)
raise ModuleNotFoundError(
"The requested file is part of the scikit-image distribution, "
Expand All @@ -224,7 +224,7 @@ def _fetch(data_filename):
# Download the data with pooch which caches it automatically
_ensure_cache_dir(target_dir=cache_dir)
try:
cached_file_path = image_fetcher.fetch(data_filename)
cached_file_path = _image_fetcher.fetch(data_filename)
return cached_file_path
except ConnectionError as err:
_skip_pytest_case_requiring_pooch(data_filename)
Expand Down Expand Up @@ -271,31 +271,31 @@ def download_all(directory=None):
data directory by inspecting the variable `skimage.data.data_dir`.
"""

if image_fetcher is None:
if _image_fetcher is None:
raise ModuleNotFoundError(
"To download all package data, scikit-image needs an optional "
"dependency, pooch."
"To install pooch, follow our installation instructions found at "
"https://scikit-image.org/docs/stable/install.html"
)
# Consider moving this kind of logic to Pooch
old_dir = image_fetcher.path
old_dir = _image_fetcher.path
try:
if directory is not None:
directory = osp.expanduser(directory)
image_fetcher.path = directory
_ensure_cache_dir(target_dir=image_fetcher.path)
_image_fetcher.path = directory
_ensure_cache_dir(target_dir=_image_fetcher.path)

for data_filename in image_fetcher.registry:
for data_filename in _image_fetcher.registry:
file_path = _fetch(data_filename)

# Copy to `directory` or implicit cache if it is not already there
if not file_path.startswith(str(image_fetcher.path)):
dest_path = osp.join(image_fetcher.path, data_filename)
if not file_path.startswith(str(_image_fetcher.path)):
dest_path = osp.join(_image_fetcher.path, data_filename)
os.makedirs(osp.dirname(dest_path), exist_ok=True)
shutil.copy2(file_path, dest_path)
finally:
image_fetcher.path = old_dir
_image_fetcher.path = old_dir


def lbp_frontal_face_cascade_filename():
Expand Down
6 changes: 3 additions & 3 deletions skimage/data/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import skimage.data as data
from skimage.data._fetchers import image_fetcher
from skimage.data._fetchers import _image_fetcher
from skimage import io
from skimage._shared.testing import assert_equal, assert_almost_equal, fetch
import os
Expand All @@ -21,7 +21,7 @@ def test_download_all_with_pooch():
# lower speed connections.
# https://github.com/scikit-image/scikit-image/pull/4666/files/26d5138b25b958da6e97ebf979e9bc36f32c3568#r422604863
data_dir = data.data_dir
if image_fetcher is not None:
if _image_fetcher is not None:
data.download_all()
assert 'astronaut.png' in os.listdir(data_dir)
assert len(os.listdir(data_dir)) > 50
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_vortex():


@pytest.mark.parametrize(
'function_name', ['file_hash', 'image_fetcher']
'function_name', ['file_hash',]
)
def test_fetchers_are_public(function_name):
# Check that the following functions that are only used indirectly in the
Expand Down

0 comments on commit 0408c1d

Please sign in to comment.