From 8d771af16c59b852dc6f50903230f147a96922a7 Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Mon, 2 Oct 2023 11:01:36 +0200 Subject: [PATCH] Replace deprecated pkg_resources with new importlib See also https://importlib-resources.readthedocs.io/en/latest/migration.html --- vermouth/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vermouth/__init__.py b/vermouth/__init__.py index d6be8a0e3..d5df8c95e 100644 --- a/vermouth/__init__.py +++ b/vermouth/__init__.py @@ -33,14 +33,19 @@ # Find the data directory once. try: - import pkg_resources + from importlib.resources import files, as_file + import atexit + from contextlib import ExitStack except ImportError: import os DATA_PATH = os.path.join(os.path.dirname(__file__), 'data') del os else: - DATA_PATH = pkg_resources.resource_filename('vermouth', 'data') - del pkg_resources + ref = files('vermouth') / 'data' + file_manager = ExitStack() + atexit.register(file_manager.close) + DATA_PATH = file_manager.enter_context(as_file(ref)) + del files, as_file, atexit, ExitStack del pbr