Skip to content

Commit

Permalink
switch from local _shared/lazy.py to lazy_loader package
Browse files Browse the repository at this point in the history
use .pyi type stubs
  • Loading branch information
grlee77 committed Jun 19, 2023
1 parent 6616ba1 commit 9b3362c
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 212 deletions.
2 changes: 2 additions & 0 deletions python/cucim/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ include tox.ini .travis.yml .appveyor.yml .readthedocs.yml
include versioneer.py
include src/cucim/clara/*.so*

recursive-include src/cucim *.pyx *.pxd *.pxi *.py *.pyi *.h *.ini *.npy *.txt *.in *.md

global-exclude *.py[cod] __pycache__/*
1 change: 1 addition & 0 deletions python/cucim/ci/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ virtualenv>=16.6.0
pip>=19.1.1
setuptools>=18.0.1
six>=1.14.0
lazy_loader>=0.1
6 changes: 3 additions & 3 deletions python/cucim/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def read(*names, **kwargs):
url='https://developer.nvidia.com/multidimensional-image-processing',
packages=find_packages('src'),
package_dir={'cucim': 'src/cucim'},
package_data={"": ["*.pyi"]}, # distribute
include_package_data=True,
zip_safe=False,
classifiers=[
Expand All @@ -56,11 +57,10 @@ def read(*names, **kwargs):
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
# 'Operating System :: OS Independent',
# 'Operating System :: Unix',
# 'Operating System :: POSIX',
Expand All @@ -87,7 +87,7 @@ def read(*names, **kwargs):
setup_requires=SETUP_REQUIRES,
install_requires=[
# TODO: Check cupy dependency based on cuda version
'click', 'numpy', # 'scipy', 'scikit-image'
'click', 'numpy', "lazy_loader>=0.1", # 'scipy', 'scikit-image'
# eg: 'aspectlib==1.1.1', 'six>=1.7',
],
extras_require={
Expand Down
8 changes: 2 additions & 6 deletions python/cucim/src/cucim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@
del _version


from .skimage._shared import lazy
import lazy_loader as lazy

__getattr__, __lazy_dir__, _ = lazy.attach(
__name__,
submodules,
submod_attrs,
)
__getattr__, __lazy_dir__, _ = lazy.attach_stub(__name__, __file__)


def __dir__():
Expand Down
35 changes: 35 additions & 0 deletions python/cucim/src/cucim/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

submodules = []

try:
import cupy
_is_cupy_available = True
submodules += ['core', 'skimage']
except ImportError:
pass

try:
from .clara import CuImage, __version__, cli
_is_clara_available = True
submodules += ['clara']
except ImportError:
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
del _version

__all__ = submodules + ['__version__', 'is_available']
36 changes: 9 additions & 27 deletions python/cucim/src/cucim/skimage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,17 @@
"""

from ._shared import lazy
import lazy_loader as lazy

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


__getattr__, __lazy_dir__, _ = lazy.attach(
__name__,
submodules,
{'util.dtype': ['dtype_limits', 'img_as_bool', 'img_as_float',
'img_as_float32', 'img_as_float64', 'img_as_int',
'img_as_ubyte', 'img_as_uint'],
'util.lookfor': ['lookfor'],
}
)
__getattr__, __lazy_dir__, _ = lazy.attach_stub(__name__, __file__)


def __dir__():
return __lazy_dir__()


# Legacy imports into the root namespace; not advertised in __all__
from .util.dtype import (dtype_limits, img_as_bool, img_as_float,
img_as_float32, img_as_float64, img_as_int,
img_as_ubyte, img_as_uint)
from .util.lookfor import lookfor
23 changes: 23 additions & 0 deletions python/cucim/src/cucim/skimage/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import lazy_loader as lazy

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

__all__ = submodules

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

This file was deleted.

10 changes: 2 additions & 8 deletions python/cucim/src/cucim/skimage/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from .._shared import lazy
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules={},
submod_attrs={
'_binary_blobs': ['binary_blobs'],
}
)
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
5 changes: 5 additions & 0 deletions python/cucim/src/cucim/skimage/data/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__all__ = [
'binary_blobs',
]

from ._binary_blobs import binary_blobs
31 changes: 2 additions & 29 deletions python/cucim/src/cucim/skimage/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
from .._shared import lazy
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
# submodules={'rank'},
submod_attrs={
'lpi_filter': ['filter_inverse', 'wiener', 'LPIFilter2D'],
'_gaussian': ['gaussian', 'difference_of_gaussians'],
'edges': ['sobel', 'sobel_h', 'sobel_v',
'scharr', 'scharr_h', 'scharr_v',
'prewitt', 'prewitt_h', 'prewitt_v',
'roberts', 'roberts_pos_diag', 'roberts_neg_diag',
'laplace',
'farid', 'farid_h', 'farid_v'],
'_rank_order': ['rank_order'],
'_gabor': ['gabor_kernel', 'gabor'],
'thresholding': ['threshold_local', 'threshold_otsu', 'threshold_yen',
'threshold_isodata', 'threshold_li', 'threshold_minimum',
'threshold_mean', 'threshold_triangle',
'threshold_niblack', 'threshold_sauvola',
'threshold_multiotsu', 'try_all_threshold',
'apply_hysteresis_threshold'],
'ridges': ['meijering', 'sato', 'frangi', 'hessian'],
'_median': ['median'],
'_sparse': ['correlate_sparse'],
'_unsharp_mask': ['unsharp_mask'],
'_window': ['window'],
'_fft_based': ['butterworth']
}
)
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
Loading

0 comments on commit 9b3362c

Please sign in to comment.