Skip to content

Commit

Permalink
Replace deprecated pkg_resources with new importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
pckroon committed Oct 2, 2023
1 parent 72766a2 commit 8d771af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions vermouth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8d771af

Please sign in to comment.