File: drop-pkg-resources.patch

package info (click to toggle)
depthcharge-tools 0.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 760 kB
  • sloc: python: 6,286; sh: 650; makefile: 12
file content (127 lines) | stat: -rw-r--r-- 4,077 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From: Colin Watson <cjwatson@debian.org>
Date: Thu, 29 Jan 2026 14:55:35 +0000
Subject: Port away from pkg_resources

Forwarded: https://github.com/alpernebbi/depthcharge-tools/pull/13
Bug-Debian: https://bugs.debian.org/1083356
Last-Update: 2026-01-29
---
 README.rst                    |  3 +--
 depthcharge_tools/__init__.py | 50 ++++++++++++++++++++++++-------------------
 setup.py                      |  3 ++-
 3 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/README.rst b/README.rst
index 3df6785..51972fb 100644
--- a/README.rst
+++ b/README.rst
@@ -73,8 +73,7 @@ the work::
 
 Installation
 ============
-This depends on the ``pkg_resources`` Python package which is usually
-distributed with ``setuptools``. The tools can run a number of programs
+The tools can run a number of programs
 when necessary, which should be considered dependencies:
 
 - ``futility`` (``vbutil_kernel``), ``cgpt``, ``crossystem``
diff --git a/depthcharge_tools/__init__.py b/depthcharge_tools/__init__.py
index 960da0a..1a809cd 100644
--- a/depthcharge_tools/__init__.py
+++ b/depthcharge_tools/__init__.py
@@ -8,9 +8,11 @@
 import glob
 import logging
 import pathlib
-import pkg_resources
 import re
 import subprocess
+from importlib import metadata, resources
+
+from packaging.version import InvalidVersion, Version
 
 logger = logging.getLogger(__name__)
 logger.addHandler(logging.NullHandler())
@@ -18,22 +20,24 @@ logger.addHandler(logging.NullHandler())
 
 def get_version():
     version = None
-    pkg_path = pkg_resources.resource_filename(__name__, '')
-    pkg_path = pathlib.Path(pkg_path).resolve()
+    pkg_path = resources.files(__name__)
 
     try:
-        self = pkg_resources.require(__name__)[0]
-        version = self.version
-
-    except pkg_resources.DistributionNotFound:
-        setup_py = pkg_path.parent / "setup.py"
-        if setup_py.exists():
-            version = re.findall(
-                'version=(\'.+\'|".+"),',
-                setup_py.read_text(),
-            )[0].strip('"\'')
-
-    if (pkg_path.parent / ".git").exists():
+        version = metadata.version(__name__)
+
+    except metadata.PackageNotFoundError:
+        if isinstance(pkg_path, pathlib.Path):
+            setup_py = pkg_path.parent / "setup.py"
+            if setup_py.exists():
+                version = re.findall(
+                    'version=(\'.+\'|".+"),',
+                    setup_py.read_text(),
+                )[0].strip('"\'')
+
+    if (
+        isinstance(pkg_path, pathlib.Path)
+        and (pkg_path.parent / ".git").exists()
+    ):
         proc = subprocess.run(
             ["git", "-C", pkg_path, "describe"],
             stdout=subprocess.PIPE,
@@ -44,20 +48,22 @@ def get_version():
             tag, *local = proc.stdout.split("-")
 
             if local:
-                version = "{}+{}".format(tag, ".".join(local))
+                git_version = "{}+{}".format(tag, ".".join(local))
             else:
-                version = tag
+                git_version = tag
+            try:
+                return Version(git_version)
+            except InvalidVersion:
+                pass
 
     if version is not None:
-        return pkg_resources.parse_version(version)
+        return Version(version)
 
 __version__ = get_version()
 
-config_ini = pkg_resources.resource_string(__name__, "config.ini")
-config_ini = config_ini.decode("utf-8")
+config_ini = resources.files(__name__).joinpath("config.ini").read_text()
 
-boards_ini = pkg_resources.resource_string(__name__, "boards.ini")
-boards_ini = boards_ini.decode("utf-8")
+boards_ini = resources.files(__name__).joinpath("boards.ini").read_text()
 
 config_files = [
     *glob.glob("/etc/depthcharge-tools/config"),
diff --git a/setup.py b/setup.py
index 1be4589..a27ea59 100644
--- a/setup.py
+++ b/setup.py
@@ -43,7 +43,8 @@ setuptools.setup(
     package_data={
         "depthcharge_tools": ["config.ini", "boards.ini"],
     },
+    python_requires=">=3.9",
     install_requires=[
-        'setuptools',
+        'packaging',
     ],
 )