From 08db47790be0a7f2656e699fc5ff586b52a5b6d9 Mon Sep 17 00:00:00 2001 From: Benjamin Kiessling Date: Thu, 2 Jan 2025 12:23:23 +0100 Subject: [PATCH] no more need for backported importlib_resources --- kraken/blla.py | 5 +++-- kraken/ketos/repo.py | 4 ++-- kraken/kraken.py | 4 ++-- kraken/lib/dataset/utils.py | 4 ++-- setup.cfg | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kraken/blla.py b/kraken/blla.py index d78ee55af..9474df6a4 100644 --- a/kraken/blla.py +++ b/kraken/blla.py @@ -24,13 +24,14 @@ import uuid from typing import Any, Callable, Dict, List, Literal, Optional, Union -import importlib_resources import numpy as np import PIL import shapely.geometry as geom import torch import torch.nn.functional as F import torchvision.transforms as tf + +from importlib import resources from scipy.ndimage import gaussian_filter from skimage.filters import sobel @@ -295,7 +296,7 @@ def segment(im: PIL.Image.Image, """ if model is None: logger.info('No segmentation model given. Loading default model.') - model = vgsl.TorchVGSLModel.load_model(importlib_resources.files(__name__).joinpath('blla.mlmodel')) + model = vgsl.TorchVGSLModel.load_model(resources.files(__name__).joinpath('blla.mlmodel')) if isinstance(model, vgsl.TorchVGSLModel): model = [model] diff --git a/kraken/ketos/repo.py b/kraken/ketos/repo.py index 043a51087..fe67bf803 100644 --- a/kraken/ketos/repo.py +++ b/kraken/ketos/repo.py @@ -45,7 +45,7 @@ def publish(ctx, metadata, access_token, private, model): """ import json - import importlib_resources + from importlib import resources from jsonschema import validate from jsonschema.exceptions import ValidationError @@ -53,7 +53,7 @@ def publish(ctx, metadata, access_token, private, model): from kraken.lib import models from kraken.lib.progress import KrakenDownloadProgressBar - ref = importlib_resources.files('kraken').joinpath('metadata.schema.json') + ref = resources.files('kraken').joinpath('metadata.schema.json') with open(ref, 'rb') as fp: schema = json.load(fp) diff --git a/kraken/kraken.py b/kraken/kraken.py index 0b061d092..23a12daf9 100644 --- a/kraken/kraken.py +++ b/kraken/kraken.py @@ -29,8 +29,8 @@ from typing import IO, Any, Callable, Dict, List, Union, cast import click -import importlib_resources from PIL import Image +from importlib import resources from rich.traceback import install from kraken.lib import log @@ -44,7 +44,7 @@ install(suppress=[click]) APP_NAME = 'kraken' -SEGMENTATION_DEFAULT_MODEL = importlib_resources.files(APP_NAME).joinpath('blla.mlmodel') +SEGMENTATION_DEFAULT_MODEL = resources.files(APP_NAME).joinpath('blla.mlmodel') DEFAULT_MODEL = ['en_best.mlmodel'] # raise default max image size to 20k * 20k pixels diff --git a/kraken/lib/dataset/utils.py b/kraken/lib/dataset/utils.py index 879ac4592..3a95a3736 100644 --- a/kraken/lib/dataset/utils.py +++ b/kraken/lib/dataset/utils.py @@ -21,10 +21,10 @@ from functools import partial from typing import Any, Dict, List, Sequence, Tuple, Union -import importlib_resources import torch import torch.nn.functional as F from torchvision import transforms +from importlib import resources from kraken.lib import functional_im_transforms as F_t from kraken.lib.exceptions import KrakenInputException @@ -319,7 +319,7 @@ def compute_confusions(algn1: Sequence[str], algn2: Sequence[str]): script substitutions. """ counts: Dict[Tuple[str, str], int] = Counter() - ref = importlib_resources.files(__name__).joinpath('scripts.json') + ref = resources.files(__name__).joinpath('scripts.json') with ref.open('rb') as fp: script_map = json.load(fp) diff --git a/setup.cfg b/setup.cfg index 73cb67fe4..8e0e05b2e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,7 +61,6 @@ install_requires = lightning~=2.4.0 torchmetrics>=1.1.0 threadpoolctl~=3.5.0 - importlib-resources>=1.3.0 rich [options.extras_require]