From 9ac6bafffa404da93e4a671b4c7d79fff2049a79 Mon Sep 17 00:00:00 2001 From: stavarengo Date: Thu, 7 Mar 2024 16:47:07 +0100 Subject: [PATCH] Using importlib --- pyproject.toml | 2 +- src/mobt/Cache/FileSystemCache.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7ab0f6d..cc38d6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mob-tool" -version = "1.0.34" +version = "1.0.35" authors = [ { name = "rfst" }, ] diff --git a/src/mobt/Cache/FileSystemCache.py b/src/mobt/Cache/FileSystemCache.py index 3872ae1..ed7e2a8 100644 --- a/src/mobt/Cache/FileSystemCache.py +++ b/src/mobt/Cache/FileSystemCache.py @@ -4,8 +4,8 @@ from pathlib import Path from typing import Optional -import pkg_resources import platformdirs +from importlib.metadata import version, PackageNotFoundError from dataclasses_json import config, dataclass_json from injector import inject from marshmallow import fields @@ -33,9 +33,14 @@ def is_expired(self) -> bool: return datetime.now() > self.expires_at +try: + _cache_dir_version = version('mob-tool') +except PackageNotFoundError: + _cache_dir_version = 'unknown' + _cache_dir = platformdirs.user_cache_dir( appname='mob-tool', - version=pkg_resources.get_distribution('mob-tool').version, + version=_cache_dir_version, )