diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ee58d1d..ea2c00c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ - Work with more matplotlib palettes ([#760](../../pull/760)) ### Changes -- Use importlib rather than pkg_resources internally ([#747](../../pull/747)) +- Use importlib rather than pkg_resources internally ([#747](../../pull/747), [#778](../../pull/778)) ### Bug Fixes - Fix expanding a style palette with a single named color ([#754](../../pull/754)) diff --git a/girder/girder_large_image/__init__.py b/girder/girder_large_image/__init__.py index 13e831170..3aa488e1f 100644 --- a/girder/girder_large_image/__init__.py +++ b/girder/girder_large_image/__init__.py @@ -20,7 +20,6 @@ from girder_jobs.constants import JobStatus from girder_jobs.models.job import Job -from pkg_resources import DistributionNotFound, get_distribution import girder import large_image @@ -44,8 +43,14 @@ from .rest.tiles import TilesItemResource try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/girder/setup.py b/girder/setup.py index 18cb86855..de9df2144 100644 --- a/girder/setup.py +++ b/girder/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'girder>=3.0.4', 'girder-jobs>=3.0.3', 'large_image>=1.0.0', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'tasks': [ diff --git a/girder_annotation/girder_large_image_annotation/__init__.py b/girder_annotation/girder_large_image_annotation/__init__.py index ace3b00f6..ca8331f30 100644 --- a/girder_annotation/girder_large_image_annotation/__init__.py +++ b/girder_annotation/girder_large_image_annotation/__init__.py @@ -24,8 +24,20 @@ from .models.annotation import Annotation from .rest.annotation import AnnotationResource -# Validators +try: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: + # package is not installed + pass + +# Validators @setting_utilities.validator({ constants.PluginSettings.LARGE_IMAGE_ANNOTATION_HISTORY, diff --git a/girder_annotation/setup.py b/girder_annotation/setup.py index ea16bda6d..bc55f639a 100644 --- a/girder_annotation/setup.py +++ b/girder_annotation/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'jsonschema>=2.5.1', 'girder-large-image', 'ujson>=1.35', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'tasks': [ diff --git a/large_image/__init__.py b/large_image/__init__.py index 9e582b17f..23d3f6ded 100644 --- a/large_image/__init__.py +++ b/large_image/__init__.py @@ -14,13 +14,17 @@ # limitations under the License. ############################################################################# -from pkg_resources import DistributionNotFound, get_distribution - from . import tilesource # noqa from .tilesource import canRead, getTileSource, open # noqa try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/bioformats/large_image_source_bioformats/__init__.py b/sources/bioformats/large_image_source_bioformats/__init__.py index 7db64148f..d30f38f5b 100644 --- a/sources/bioformats/large_image_source_bioformats/__init__.py +++ b/sources/bioformats/large_image_source_bioformats/__init__.py @@ -29,7 +29,6 @@ import types import numpy -from pkg_resources import DistributionNotFound, get_distribution import large_image.tilesource.base from large_image import config @@ -39,8 +38,14 @@ from large_image.tilesource import FileTileSource, nearPowerOfTwo try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/bioformats/setup.py b/sources/bioformats/setup.py index ac78ecf25..6df6a13c1 100644 --- a/sources/bioformats/setup.py +++ b/sources/bioformats/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'python-bioformats>=1.5.2', 'scikit-image', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/dummy/large_image_source_dummy/__init__.py b/sources/dummy/large_image_source_dummy/__init__.py index 14f374a63..4a72dae94 100644 --- a/sources/dummy/large_image_source_dummy/__init__.py +++ b/sources/dummy/large_image_source_dummy/__init__.py @@ -14,14 +14,18 @@ # limitations under the License. ############################################################################## -from pkg_resources import DistributionNotFound, get_distribution - from large_image.constants import SourcePriority from large_image.tilesource import TileSource try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/dummy/setup.py b/sources/dummy/setup.py index 47a914f26..600c0f50f 100644 --- a/sources/dummy/setup.py +++ b/sources/dummy/setup.py @@ -44,6 +44,7 @@ def prerelease_local_scheme(version): ], install_requires=[ 'large-image', + 'importlib-metadata ; python_version < "3.8"', ], keywords='large_image, tile source', packages=find_packages(exclude=['test', 'test.*']), diff --git a/sources/gdal/large_image_source_gdal/__init__.py b/sources/gdal/large_image_source_gdal/__init__.py index 5f5ca19ec..f1d861c16 100644 --- a/sources/gdal/large_image_source_gdal/__init__.py +++ b/sources/gdal/large_image_source_gdal/__init__.py @@ -28,7 +28,6 @@ # if on those older versions of python if it is imported before gdal, there can # be a database version conflect; importing after gdal avoids this. import pyproj # noqa I001 -from pkg_resources import DistributionNotFound, get_distribution import large_image from large_image.cache_util import CacheProperties, LruCacheMetaclass, methodcache @@ -40,12 +39,17 @@ from large_image.tilesource.utilities import getPaletteColors try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass - TileInputUnits['projection'] = 'projection' TileInputUnits['proj'] = 'projection' TileInputUnits['wgs84'] = 'proj4:EPSG:4326' diff --git a/sources/gdal/setup.py b/sources/gdal/setup.py index edd6aee34..bc072560c 100644 --- a/sources/gdal/setup.py +++ b/sources/gdal/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'gdal', 'pyproj>=2.2.0', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/mapnik/large_image_source_mapnik/__init__.py b/sources/mapnik/large_image_source_mapnik/__init__.py index df40b0a2a..42f90dfe9 100644 --- a/sources/mapnik/large_image_source_mapnik/__init__.py +++ b/sources/mapnik/large_image_source_mapnik/__init__.py @@ -20,15 +20,20 @@ import PIL.Image from large_image_source_gdal import GDALFileTileSource, InitPrefix from osgeo import gdal, gdalconst -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache from large_image.constants import TILE_FORMAT_PIL, SourcePriority from large_image.exceptions import TileSourceError try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/mapnik/setup.py b/sources/mapnik/setup.py index 761a5e850..9e1ba808a 100644 --- a/sources/mapnik/setup.py +++ b/sources/mapnik/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'large-image-source-gdal', 'mapnik', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/multi/large_image_source_multi/__init__.py b/sources/multi/large_image_source_multi/__init__.py index 3dd094607..92f133426 100644 --- a/sources/multi/large_image_source_multi/__init__.py +++ b/sources/multi/large_image_source_multi/__init__.py @@ -11,7 +11,6 @@ import jsonschema import numpy import yaml -from pkg_resources import DistributionNotFound, get_distribution import large_image from large_image.cache_util import LruCacheMetaclass, methodcache @@ -21,8 +20,14 @@ from large_image.tilesource.utilities import _makeSameChannelDepth try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/multi/setup.py b/sources/multi/setup.py index 9ce58718e..865e9ffad 100644 --- a/sources/multi/setup.py +++ b/sources/multi/setup.py @@ -47,6 +47,7 @@ def prerelease_local_scheme(version): 'large-image>=1.0.0', 'pyyaml', 'scipy', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image>=1.0.0', diff --git a/sources/nd2/large_image_source_nd2/__init__.py b/sources/nd2/large_image_source_nd2/__init__.py index 7331c9b49..8fe4d2eac 100644 --- a/sources/nd2/large_image_source_nd2/__init__.py +++ b/sources/nd2/large_image_source_nd2/__init__.py @@ -23,7 +23,6 @@ import cachetools import numpy -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache from large_image.constants import TILE_FORMAT_NUMPY, SourcePriority @@ -33,8 +32,14 @@ nd2reader = None try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/ometiff/large_image_source_ometiff/__init__.py b/sources/ometiff/large_image_source_ometiff/__init__.py index 51d34d0db..3b18b0c66 100644 --- a/sources/ometiff/large_image_source_ometiff/__init__.py +++ b/sources/ometiff/large_image_source_ometiff/__init__.py @@ -26,15 +26,20 @@ IOTiffException, TiffException, TiledTiffDirectory) -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache from large_image.constants import TILE_FORMAT_NUMPY, TILE_FORMAT_PIL, SourcePriority from large_image.exceptions import TileSourceError, TileSourceFileNotFoundError try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/ometiff/setup.py b/sources/ometiff/setup.py index f62944e17..4e20d31fe 100644 --- a/sources/ometiff/setup.py +++ b/sources/ometiff/setup.py @@ -44,7 +44,8 @@ def prerelease_local_scheme(version): ], install_requires=[ 'large-image', - 'large-image-source-tiff>=1.0.0', + 'large-image-source-tiff', + 'importlib-metadata ; python_version < "3.8"' ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/openjpeg/large_image_source_openjpeg/__init__.py b/sources/openjpeg/large_image_source_openjpeg/__init__.py index 590ae91ad..c97a76638 100644 --- a/sources/openjpeg/large_image_source_openjpeg/__init__.py +++ b/sources/openjpeg/large_image_source_openjpeg/__init__.py @@ -26,7 +26,6 @@ import glymur import PIL.Image -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache from large_image.constants import TILE_FORMAT_NUMPY, SourcePriority @@ -34,8 +33,14 @@ from large_image.tilesource import FileTileSource, etreeToDict try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/openjpeg/setup.py b/sources/openjpeg/setup.py index 426e5a484..2153acc6e 100644 --- a/sources/openjpeg/setup.py +++ b/sources/openjpeg/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'glymur>=0.8.18 ; python_version >= "3.7"', 'glymur>=0.8.18,<0.9.4 ; python_version < "3.7"', + 'importlib-metadata ; python_version < "3.8"' ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/openslide/large_image_source_openslide/__init__.py b/sources/openslide/large_image_source_openslide/__init__.py index 7a5e36932..749b1b871 100644 --- a/sources/openslide/large_image_source_openslide/__init__.py +++ b/sources/openslide/large_image_source_openslide/__init__.py @@ -20,7 +20,6 @@ import openslide import PIL import tifftools -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache from large_image.constants import TILE_FORMAT_PIL, SourcePriority @@ -34,8 +33,14 @@ try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/openslide/setup.py b/sources/openslide/setup.py index 5d8daf5a9..5e49bb860 100644 --- a/sources/openslide/setup.py +++ b/sources/openslide/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'openslide-python>=1.1.0', 'tifftools>=1.2.0', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/pil/large_image_source_pil/__init__.py b/sources/pil/large_image_source_pil/__init__.py index a4f486c5e..552396b8f 100644 --- a/sources/pil/large_image_source_pil/__init__.py +++ b/sources/pil/large_image_source_pil/__init__.py @@ -20,7 +20,6 @@ import numpy import PIL.Image -from pkg_resources import DistributionNotFound, get_distribution from large_image import config from large_image.cache_util import LruCacheMetaclass, methodcache, strhash @@ -29,8 +28,14 @@ from large_image.tilesource import FileTileSource try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/pil/setup.py b/sources/pil/setup.py index d19bacaf7..a1b000b7c 100644 --- a/sources/pil/setup.py +++ b/sources/pil/setup.py @@ -44,6 +44,7 @@ def prerelease_local_scheme(version): ], install_requires=[ 'large-image', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/sources/test/large_image_source_test/__init__.py b/sources/test/large_image_source_test/__init__.py index b11f6b34a..907b98cb6 100644 --- a/sources/test/large_image_source_test/__init__.py +++ b/sources/test/large_image_source_test/__init__.py @@ -19,7 +19,6 @@ import math from PIL import Image, ImageDraw, ImageFont -from pkg_resources import DistributionNotFound, get_distribution from large_image.cache_util import LruCacheMetaclass, methodcache, strhash from large_image.constants import TILE_FORMAT_PIL, SourcePriority @@ -27,8 +26,14 @@ from large_image.tilesource import TileSource try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/test/setup.py b/sources/test/setup.py index 9f06b6f87..680ca8f92 100644 --- a/sources/test/setup.py +++ b/sources/test/setup.py @@ -44,6 +44,7 @@ def prerelease_local_scheme(version): ], install_requires=[ 'large-image', + 'importlib-metadata ; python_version < "3.8"', ], keywords='large_image, tile source', packages=find_packages(exclude=['test', 'test.*']), diff --git a/sources/tiff/large_image_source_tiff/__init__.py b/sources/tiff/large_image_source_tiff/__init__.py index 6f8db61ec..18db284bc 100644 --- a/sources/tiff/large_image_source_tiff/__init__.py +++ b/sources/tiff/large_image_source_tiff/__init__.py @@ -24,7 +24,6 @@ import numpy import PIL.Image import tifftools -from pkg_resources import DistributionNotFound, get_distribution from large_image import config from large_image.cache_util import LruCacheMetaclass, methodcache @@ -37,8 +36,14 @@ ValidationTiffException) try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/sources/tiff/setup.py b/sources/tiff/setup.py index 6b41efc43..7a9454d8a 100644 --- a/sources/tiff/setup.py +++ b/sources/tiff/setup.py @@ -46,6 +46,7 @@ def prerelease_local_scheme(version): 'large-image', 'libtiff>=0.4.1', 'tifftools>=1.2.0', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': 'girder-large-image', diff --git a/utilities/converter/large_image_converter/__init__.py b/utilities/converter/large_image_converter/__init__.py index 11f7109c8..860a2e775 100644 --- a/utilities/converter/large_image_converter/__init__.py +++ b/utilities/converter/large_image_converter/__init__.py @@ -14,7 +14,6 @@ import numpy import psutil import tifftools -from pkg_resources import DistributionNotFound, get_distribution import large_image @@ -23,8 +22,14 @@ pyvips = None try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/utilities/converter/setup.py b/utilities/converter/setup.py index 50b857c1c..319b63e1d 100644 --- a/utilities/converter/setup.py +++ b/utilities/converter/setup.py @@ -54,6 +54,7 @@ def prerelease_local_scheme(version): 'psutil', 'pyvips', 'tifftools', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'jp2k': [ diff --git a/utilities/tasks/large_image_tasks/__init__.py b/utilities/tasks/large_image_tasks/__init__.py index b3962adae..0b7fb5eb5 100644 --- a/utilities/tasks/large_image_tasks/__init__.py +++ b/utilities/tasks/large_image_tasks/__init__.py @@ -5,11 +5,16 @@ from girder_worker import GirderWorkerPluginABC -from pkg_resources import DistributionNotFound, get_distribution try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import PackageNotFoundError + from importlib.metadata import version as _importlib_version +except ImportError: + from importlib_metadata import PackageNotFoundError + from importlib_metadata import version as _importlib_version +try: + __version__ = _importlib_version(__name__) +except PackageNotFoundError: # package is not installed pass diff --git a/utilities/tasks/setup.py b/utilities/tasks/setup.py index ecd232f1d..7c9aa4602 100644 --- a/utilities/tasks/setup.py +++ b/utilities/tasks/setup.py @@ -50,6 +50,7 @@ def prerelease_local_scheme(version): install_requires=[ # Packages required by both producer and consumer side installations 'girder-worker-utils>=0.8.5', + 'importlib-metadata ; python_version < "3.8"', ], extras_require={ 'girder': [