tgzr.package_management 0.0.1__tar.gz → 0.100__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ uv.lock
2
+
1
3
  # hatch vcs generated:
2
4
  _version.py
3
5
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tgzr.package_management
3
- Version: 0.0.1
3
+ Version: 0.100
4
4
  Summary: tgzr package_management engine
5
5
  Project-URL: Documentation, https://github.com/open-tgzr/tgzr.package_management#readme
6
6
  Project-URL: Issues, https://github.com/open-tgzr/tgzr.package_management/issues
@@ -17,7 +17,9 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Requires-Python: >=3.9
20
21
  Requires-Dist: hatch
22
+ Requires-Dist: importlib-metadata
21
23
  Requires-Dist: uv
22
24
  Description-Content-Type: text/markdown
23
25
 
@@ -7,6 +7,7 @@ name = "tgzr.package_management"
7
7
  dynamic = ["version"]
8
8
  description = 'tgzr package_management engine'
9
9
  readme = "README.md"
10
+ requires-python = ">=3.9"
10
11
  license = "GPL-3.0-or-later"
11
12
  keywords = []
12
13
  authors = [
@@ -27,6 +28,7 @@ classifiers = [
27
28
  dependencies = [
28
29
  "uv",
29
30
  "hatch",
31
+ "importlib-metadata", # needed to support modern Distribution api with py3.9
30
32
  ]
31
33
 
32
34
 
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.1'
32
- __version_tuple__ = version_tuple = (0, 0, 1)
31
+ __version__ = version = '0.100'
32
+ __version_tuple__ = version_tuple = (0, 100)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import os
2
4
  import platform
3
5
  from pathlib import Path
@@ -1,10 +1,22 @@
1
1
  from __future__ import annotations
2
- from typing import TYPE_CHECKING, get_args, Type, TypeVar, Callable, Any, Iterable
3
-
4
- import importlib.metadata
2
+ from typing import (
3
+ TYPE_CHECKING,
4
+ get_args,
5
+ Type,
6
+ TypeVar,
7
+ Callable,
8
+ Any,
9
+ Iterable,
10
+ Generic,
11
+ )
12
+
13
+ import sys
14
+ import importlib_metadata
5
15
  import inspect
6
16
  import logging
7
17
 
18
+ import rich
19
+
8
20
  T = TypeVar("T", bound="Plugin")
9
21
 
10
22
  logger = logging.getLogger(__name__)
@@ -31,7 +43,7 @@ class Plugin:
31
43
  def plugin_id(cls) -> str:
32
44
  return f"{cls.plugin_type_name()}@{cls.plugin_name()}"
33
45
 
34
- def __init__(self, ep: importlib.metadata.EntryPoint):
46
+ def __init__(self, ep: importlib_metadata.EntryPoint):
35
47
  super().__init__()
36
48
  self._entry_point = ep
37
49
 
@@ -44,7 +56,10 @@ class Plugin:
44
56
  )
45
57
 
46
58
 
47
- class PluginManager[PluginType: Plugin]:
59
+ PluginType = TypeVar("PluginType", bound=Plugin)
60
+
61
+
62
+ class PluginManager(Generic[PluginType]):
48
63
  EP_GROUP = "your_plugin_entry_point_group"
49
64
 
50
65
  @classmethod
@@ -52,12 +67,12 @@ class PluginManager[PluginType: Plugin]:
52
67
  return get_args(cls.__orig_bases__[0])[0] # type: ignore __orig_bases__ trust me bro.
53
68
 
54
69
  def __init__(self):
55
- self._broken: list[tuple[importlib.metadata.EntryPoint, Exception]] = []
70
+ self._broken: list[tuple[importlib_metadata.EntryPoint, Exception]] = []
56
71
  self._loaded: list[PluginType] = []
57
72
  self._needs_loading: bool = True
58
73
 
59
74
  def _instantiate_plugin_type(
60
- self, PluginType: Type[PluginType], entry_point: importlib.metadata.EntryPoint
75
+ self, PluginType: Type[PluginType], entry_point: importlib_metadata.EntryPoint
61
76
  ) -> PluginType:
62
77
  """
63
78
  Subclasses will want to override this if the managed plugin type needs
@@ -73,7 +88,7 @@ class PluginManager[PluginType: Plugin]:
73
88
  | Callable[[], PluginType | list[PluginType]]
74
89
  | Iterable[PluginType]
75
90
  ),
76
- entry_point: importlib.metadata.EntryPoint,
91
+ entry_point: importlib_metadata.EntryPoint,
77
92
  ) -> list[PluginType]:
78
93
  # print("Resolving shell app plugins:", loaded)
79
94
  ManagedPluginType = self.__class__.managed_plugin_type()
@@ -91,7 +106,7 @@ class PluginManager[PluginType: Plugin]:
91
106
  try:
92
107
  plugin_or_list_of_plugins = loaded() # type: ignore
93
108
  except Exception as err:
94
- ValueError(
109
+ raise ValueError(
95
110
  f"Error while executing callable entry point value (ep={entry_point}): {err}"
96
111
  )
97
112
  return self._resolve_plugins(
@@ -109,7 +124,7 @@ class PluginManager[PluginType: Plugin]:
109
124
  )
110
125
 
111
126
  def _load_plugins(self):
112
- all_entry_points = importlib.metadata.entry_points(group=self.EP_GROUP)
127
+ all_entry_points = importlib_metadata.entry_points(group=self.EP_GROUP)
113
128
 
114
129
  self._broken.clear()
115
130
  self._loaded.clear()
@@ -119,11 +134,13 @@ class PluginManager[PluginType: Plugin]:
119
134
  try:
120
135
  loaded = ep.load()
121
136
  except Exception as err:
137
+ raise # TMP DEE
122
138
  self._broken.append((ep, err))
123
139
  else:
124
140
  try:
125
141
  plugins = self._resolve_plugins(loaded, ep)
126
142
  except Exception as err:
143
+ raise # TMP DEE
127
144
  self._broken.append((ep, err))
128
145
  else:
129
146
  for plugin in plugins:
@@ -133,7 +150,7 @@ class PluginManager[PluginType: Plugin]:
133
150
 
134
151
  def get_broken_plugins(
135
152
  self, force_reload: bool = False
136
- ) -> list[tuple[importlib.metadata.EntryPoint, Exception]]:
153
+ ) -> list[tuple[importlib_metadata.EntryPoint, Exception]]:
137
154
  if force_reload or self._needs_loading:
138
155
  self._load_plugins()
139
156
  return self._broken
@@ -1,5 +1,7 @@
1
+ from __future__ import annotations
2
+
1
3
  from pathlib import Path
2
- import importlib.metadata
4
+ import importlib_metadata
3
5
  import platform
4
6
  import json
5
7
  import os
@@ -156,11 +158,11 @@ class Venv:
156
158
  def get_cmd_names(self) -> list[str]:
157
159
  raise NotImplementedError()
158
160
 
159
- def get_package(self, package_name: str) -> importlib.metadata.Distribution | None:
161
+ def get_package(self, package_name: str) -> importlib_metadata.Distribution | None:
160
162
  if self.site_packages_path is None:
161
163
  return None
162
164
  distributions = list(
163
- importlib.metadata.distributions(
165
+ importlib_metadata.distributions(
164
166
  name=package_name, path=[str(self.site_packages_path)]
165
167
  )
166
168
  )
@@ -173,10 +175,10 @@ class Venv:
173
175
 
174
176
  def get_packages(
175
177
  self, name_filters: list[str] | None = None
176
- ) -> list[importlib.metadata.Distribution]:
178
+ ) -> list[importlib_metadata.Distribution]:
177
179
  if self.site_packages_path is None:
178
180
  return []
179
- distributions = importlib.metadata.distributions(
181
+ distributions = importlib_metadata.distributions(
180
182
  path=[str(self.site_packages_path)]
181
183
  )
182
184
  ret = []
@@ -215,10 +217,10 @@ class Venv:
215
217
 
216
218
  def get_plugins(
217
219
  self, group_filter: str | None
218
- ) -> list[tuple[importlib.metadata.EntryPoint, importlib.metadata.Distribution]]:
220
+ ) -> list[tuple[importlib_metadata.EntryPoint, importlib_metadata.Distribution]]:
219
221
  if self.site_packages_path is None:
220
222
  return []
221
- distributions = importlib.metadata.distributions(
223
+ distributions = importlib_metadata.distributions(
222
224
  path=[str(self.site_packages_path)]
223
225
  )
224
226
  plugins = []
@@ -230,7 +232,7 @@ class Venv:
230
232
 
231
233
  def get_plugins_slow(
232
234
  self, group_filter: str | None
233
- ) -> list[importlib.metadata.EntryPoint]:
235
+ ) -> list[importlib_metadata.EntryPoint]:
234
236
  cmd_args = ["studio", "plugins-here", "--format", "json"]
235
237
  if group_filter:
236
238
  cmd_args.extend(["--group-filter", group_filter])
@@ -243,7 +245,7 @@ class Venv:
243
245
  ret = []
244
246
  for entry in data:
245
247
  # print(entry)
246
- ep = importlib.metadata.EntryPoint(
248
+ ep = importlib_metadata.EntryPoint(
247
249
  entry["name"], entry["value"], entry["group"]
248
250
  )
249
251
  ret.append(ep)