From 69fb7986b6e7d529feb2106e0bc0dd7891dc7cd1 Mon Sep 17 00:00:00 2001
From: Daniel Harding <dharding@living180.net>
Date: Fri, 26 Sep 2025 12:46:26 +0300
Subject: [PATCH 1/3] Avoid deprecated pkg_resources when possible

When the importlib.resources.files API is available, use that in
preference to pkg_resources.
---
 upass/__init__.py | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/upass/__init__.py b/upass/__init__.py
index 032ccab..5b742ce 100755
--- a/upass/__init__.py
+++ b/upass/__init__.py
@@ -40,9 +40,16 @@ Console UI for pass.
 """
 
 import os
-import pkg_resources
 import configparser
 
+try:
+    import importlib.resources
+    importlib.resources.files
+except (ImportError, AttributeError):
+    import pkg_resources
+else:
+    pkg_resources = None
+
 __title__ = 'upass'
 __version__ = '0.3.0'
 __author__ = 'Chris Warrick'
@@ -68,15 +75,25 @@ if not os.path.exists(kwdir):
 if not os.path.exists(confdir):
     os.mkdir(confdir)
 
+if pkg_resources is None:
+    ini_skel = (
+        importlib.resources.files('upass')
+        .joinpath('data/upass.ini.skel')
+        .read_text(encoding='utf-8')
+    )
+else:
+    ini_skel = pkg_resources.resource_string(
+        'upass',
+        'data/upass.ini.skel',
+    ).decode('utf-8')
+
 if not os.path.exists(confpath):
     print("upass.ini does not exist, creating")
-    with open(confpath, 'wb') as fh:
-        fh.write(pkg_resources.resource_string(
-            'upass', 'data/upass.ini.skel'))
+    with open(confpath, 'w', encoding='utf-8') as fh:
+        fh.write(ini_skel)
     print("created " + confpath)
 
 # Configuration file support
 config = configparser.ConfigParser()
-config.read_string(pkg_resources.resource_string(
-            'upass', 'data/upass.ini.skel').decode('utf-8'))
+config.read_string(ini_skel)
 config.read([confpath], encoding='utf-8')
-- 
2.49.1

