8000 Refactor lazy loading to use stubs & lazy_loader package by stefanv · Pull Request #6577 · scikit-image/scikit-image · GitHub
[go: up one dir, main page]

Skip to content

Refactor lazy loading to use stubs & lazy_loader package #6577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ recursive-include requirements *.txt
include requirements/README.md
include Makefile
include skimage/restoration/unwrap_*_ljmu.c
recursive-include skimage *.pyx *.pxd *.pxi *.py *.h *.ini *.npy *.txt *.in *.md
recursive-include skimage *.pyx *.pxd *.pxi *.py *.pyi *.h *.ini *.npy *.txt *.in *.md
recursive-include skimage/data *
recursive-include skimage/*/tests/data *

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ requires = [
"packaging",
"Cython>=0.29.24,<3.0",
"pythran",
"lazy_loader>=0.1",

# We follow scipy for much of these pinnings
# https://github.com/scipy/scipy/blob/master/pyproject.toml
Expand Down
1 change: 1 addition & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ imageio>=2.4.1
tifffile>=2019.7.26
PyWavelets>=1.1.1
packaging>=20.0
lazy_loader>=0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def configuration(parent_package='', top_path=None):
exclude=['doc', 'doc.*', 'benchmarks']),
package_data={
# distribute Cython source files in the wheel
"": ["*.pyx", "*.pxd", "*.pxi", ""],
"": ["*.pyx", "*.pxd", "*.pxi", "*.pyi", ""],
# tests dirs have an __init__.py so are automatically included
},
include_package_data=False,
Expand Down
53 changes: 17 additions & 36 deletions skimage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,11 @@

__version__ = '0.20.0.dev0'

submodules = [
'color',
'data',
'draw',
'exposure',
'feature',
'filters',
'future',
'graph',
'io',
'measure',
'metrics',
'morphology',
'registration',
'restoration',
'segmentation',
'transform',
'util',
]

from ._shared.version_requirements import ensure_python_version
ensure_python_version((3, 7))

from ._shared import lazy
__getattr__, __lazy_dir__, _ = lazy.attach(
__name__,
submodules,
submod_attrs={'data': ['data_dir']}
)

import lazy_loader as lazy
__getattr__, __lazy_dir__, _ = lazy.attach_stub(__name__, __file__)

def __dir__():
return __lazy_dir__() + ['__version__']
Expand Down Expand Up @@ -149,17 +124,23 @@ def _raise_build_error(e):
except ImportError as e:
_raise_build_error(e)

# All skimage root imports go here
from .util.dtype import (img_as_float32,
img_as_float64,
img_as_float,
img_as_int,
img_as_uint,
img_as_ubyte,
img_as_bool,
dtype_limits)
# Legacy imports into the root namespace; not advertised in __all__
from .util.dtype import (
dtype_limits,
img_as_float32,
img_as_float64,
img_as_float,
img_as_int,
img_as_uint,
img_as_ubyte,
img_as_bool
)

from .util.lookfor import lookfor

from .data import data_dir


if 'dev' in __version__:
# Append last commit date and hash to dev version information, if available

Expand Down
41 changes: 41 additions & 0 deletions skimage/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
submodules = [
'color',
'data',
'draw',
'exposure',
'feature',
'filters',
'future',
'graph',
'io',
'measure',
'metrics',
'morphology',
'registration',
'restoration',
'segmentation',
'transform',
'util',
]

__all__ = submodules + ['__version__']

from . import (
color,
data,
draw,
exposure,
feature,
filters,
future,
graph,
io,
measure,
metrics,
morphology,
registration,
restoration,
segmentation,
transform,
util,
)
139 changes: 0 additions & 139 deletions skimage/_shared/lazy.py

This file was deleted.

22 changes: 2 additions & 20 deletions skimage/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
from .._shared import lazy
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules={},
submod_attrs={
'_binary_blobs': ['binary_blobs'],
'_fetchers': ['create_image_fetcher', 'data_dir', 'download_all',
'file_hash', 'image_fetcher', 'astronaut',
'binary_blobs', 'brain', 'brick', 'camera', 'cat',
'cell', 'cells3d', 'checkerboard', 'chelsea', 'clock',
'coffee', 'coins', 'colorwheel', 'eagle', 'grass',
'gravel', 'horse', 'hubble_deep_field', 'human_mitosis',
'immunohistochemistry', 'kidney',
'lbp_frontal_face_cascade_filename', 'lfw_subset',
'lily', 'logo', 'microaneurysms', 'moon',
'nickel_solidification', 'page', 'protein_transport',
'retina', 'rocket', 'shepp_logan_phantom',
'skin', 'stereo_motorcycle', 'text', 'vortex']
}
)
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
Loading
0