purem 2.1.6__py3-none-any.whl → 3.0.1__py3-none-any.whl

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.
purem/core.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
@@ -34,46 +34,48 @@ from purem.utils import _compute_shifted_jit
34
34
 
35
35
  class Purem:
36
36
  """
37
- Summary of what the class does.
37
+ Represents the functionality of the Purem system, including initialization, configuration,
38
+ and operations using a shared library binary. The class provides methods for setting up
39
+ license keys, managing binary paths, loading configurations from a Content Delivery Network (CDN),
40
+ and executing specific computations such as the softmax function. It handles both high-level
41
+ configuration details and low-level interactions with binary libraries.
38
42
 
39
- The Purem class is used to manage and handle the initialization, configuration, and
40
- operation of the Purem environment and its associated runtime, including license management,
41
- binary handling, and API configuration. It centralizes the setup of the Purem runtime,
42
- ensuring that all necessary binaries, license checks, and configurations are in place.
43
-
44
- The class supports downloading and extracting binaries, setting up runtime libraries, and providing utility
45
- methods such as softmax computation, license validation, and URL construction to interact with remote
46
- and local systems.
47
-
48
- :ivar _license_key: The license key used for Purem initialization and validation.
43
+ :ivar _license_key: The license key used to initialize the system.
49
44
  :type _license_key: Optional[str]
50
- :ivar _lib: The dynamically loaded library object for the Purem binary.
51
- :type _lib: ctypes.CDLL
52
- :ivar _download_binary_url: The URL for downloading the Purem binary.
45
+ :ivar _lib: Represents the dynamically loaded shared library for performing operations.
46
+ :type _lib: Optional[ctypes.CDLL]
47
+ :ivar _download_binary_url: URL for downloading the binary configuration.
53
48
  :type _download_binary_url: Optional[str]
54
- :ivar _ctx: SSL context used for secure connections, initialized using the system's certificates.
49
+ :ivar _ctx: SSL context for establishing secure connections.
55
50
  :type _ctx: ssl.SSLContext
56
- :ivar _file_structure: Manages file paths and structures related to Purem binary and runtime.
51
+ :ivar _file_structure: The handler for managing binary-related paths and file structure.
57
52
  :type _file_structure: FileStructure
58
- :ivar _binary_path: The path to the main Purem binary.
59
- :type _binary_path: pathlib.Path
60
- :ivar _binary_project_root_path: The path to the project root Purem binary.
61
- :type _binary_project_root_path: pathlib.Path
62
- :ivar _binary_archive_path: The path where the binary archive is stored.
63
- :type _binary_archive_path: pathlib.Path
64
- :ivar _binary_archive_path_tmp: The temporary path for binary archive operations.
65
- :type _binary_archive_path_tmp: pathlib.Path
66
- :ivar _env: Environment configuration used in Purem operations, including URLs.
53
+ :ivar _binary_path: Absolute path of the binary file used for execution.
54
+ :type _binary_path: str
55
+ :ivar _binary_project_root_path: Path to the binary located in the project root.
56
+ :type _binary_project_root_path: str
57
+ :ivar _binary_archive_path: Path where binary archives are stored.
58
+ :type _binary_archive_path: str
59
+ :ivar _binary_archive_path_tmp: Temporary path for binary archive operations.
60
+ :type _binary_archive_path_tmp: str
61
+ :ivar _env: Object holding environment configurations and variables.
67
62
  :type _env: Any
68
- :ivar _config_url: URL for retrieving Purem configuration, either from an environment variable or a default.
63
+ :ivar _config_url: URL for retrieving Purem's configuration from a remote server.
69
64
  :type _config_url: str
70
- :ivar _loader: Loader utility for displaying loading messages during lengthy operations.
65
+ :ivar _loader: Loader instance for displaying runtime messages during setup and initialization.
71
66
  :type _loader: Loader
72
- :ivar _log: Logger utility for tracking and managing logging in the Purem operations.
67
+ :ivar _log: Logger instance for recording system messages and error details.
73
68
  :type _log: Logger
74
69
  """
75
70
 
76
71
  def __init__(self, licenced_key: Optional[str] = None):
72
+ """
73
+ Represents the initialization and configuration of an environment, license key,
74
+ and file structure required for the system's binary operations.
75
+
76
+ :param licenced_key: Optional license key string for initializing the system.
77
+ :type licenced_key: Optional[str]
78
+ """
77
79
  self._license_key = licenced_key or None
78
80
  self._lib = None
79
81
  self._download_binary_url = None
@@ -89,13 +91,27 @@ class Purem:
89
91
  )
90
92
  self._env = load_env_config()
91
93
  self._config_url = (
92
- self._env.PUREM_CONFIG_URL
93
- or "https://api.worktif.com/v2/portal/products/purem/config"
94
+ self._env.PUREM_CONFIG_URL
95
+ or "https://api.worktif.com/v2/portal/products/purem/config"
94
96
  )
95
97
  self._loader = Loader()
96
98
  self._log = Logger()
97
99
 
98
100
  def configure(self, license_key: Optional[str] = None) -> None:
101
+ """
102
+ Configures the system with a given license key.
103
+
104
+ This method sets up the license key required for initializing the system. If no
105
+ license key is provided during configuration, the method checks if it was
106
+ already initialized. If the license key remains unset, it raises a ValueError
107
+ to indicate that a valid license key is mandatory for the setup.
108
+
109
+ :raises ValueError: Raised when no valid license key is provided during
110
+ configuration.
111
+
112
+ :param license_key: An optional string representing the license key.
113
+ :return: None
114
+ """
99
115
  if self._license_key is None and license_key is not None:
100
116
  self._license_key = license_key
101
117
  if self._license_key is None:
@@ -109,30 +125,41 @@ class Purem:
109
125
  self._set_binary()
110
126
 
111
127
  def softmax(self, array: ndarray) -> ndarray:
112
- shifted_arr = np.empty(array.size, dtype=np.float32)
113
- _compute_shifted_jit(array, shifted_arr)
114
- ptr = shifted_arr.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
128
+ ptr = array.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
115
129
  self._lib.purem(ptr, array.size)
116
- return shifted_arr
130
+ return array
117
131
 
118
- def softmax_pure(self, arr, size) -> List[any]:
132
+ def softmax_pure(self, ptr, size) -> None:
119
133
  """
120
- Compute the softmax of an array using a pure implementation.
134
+ Computes the softmax function on the provided array using pure library implementation.
121
135
 
122
- The softmax function is used to normalize an input array into a probability
123
- distribution. It is often used in machine learning for classification tasks
124
- where the output represents probabilities of different classes. This method
125
- employs a pure implementation by calling a pre-defined library function.
136
+ This function applies the softmax transformation to the data pointed to by the
137
+ pointer and modifies it in-place. The underlying implementation is handled
138
+ by a pure library function call.
126
139
 
127
- :param arr: The input array containing numeric values to be transformed
128
- into a probability distribution.
129
- :param size: The size of the input array `arr`.
130
- :return: A list representing the normalized probability distribution obtained
131
- by applying the softmax function.
140
+ :param ptr: Pointer to the data array that the softmax is to be applied on.
141
+ :type ptr: Any
142
+ :param size: The number of elements in the data array to be processed.
143
+ :type size: int
144
+ :return: None
132
145
  """
133
- return self._lib.purem(arr, size)
146
+ self._lib.purem(ptr, size)
134
147
 
135
148
  def _build_url(self, config: dict) -> Optional[str]:
149
+ """
150
+ Constructs a URL based on the provided configuration dictionary. The method
151
+ combines protocol, base URL, path, and appends a license key to generate
152
+ a complete binary URL. If the provided configuration is None, the method
153
+ returns None immediately.
154
+
155
+ :param config: A dictionary containing the parts needed to construct the
156
+ URL. The keys usually include:
157
+ - `base_url`: The base of the URL (e.g., domain).
158
+ - `protocol`: The URL protocol (e.g., "http" or "https").
159
+ - `pathname`: The path to append to the base URL.
160
+ :return: Returns the complete binary URL as a string if the configuration
161
+ is valid. If the given configuration is None, it returns None.
162
+ """
136
163
  if config is None:
137
164
  return None
138
165
  base = config.get("base_url", "").rstrip("/")
@@ -142,16 +169,51 @@ class Purem:
142
169
  return binary_url
143
170
 
144
171
  def _tune_binary(self):
172
+ """
173
+ Tunes the binary by loading the specified binary file as a shared library
174
+ and setting up its function signatures for further use.
175
+
176
+ This method initializes the shared library from the specified `_binary_path`
177
+ and configures the expected argument types and return type for the `purem` function
178
+ provided by the library.
179
+
180
+ :raises OSError: If the library at `_binary_path` cannot be loaded by `ctypes.CDLL`.
181
+
182
+ :rtype: None
183
+ """
145
184
  self._lib = ctypes.CDLL(str(self._binary_path))
146
185
  self._lib.purem.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.c_size_t]
147
186
  self._lib.purem.restype = None
148
187
 
149
188
  def _tune_project_root_binary(self):
189
+ """
190
+ Tuning the project root binary configuration.
191
+
192
+ This private method initializes a connection to the binary library
193
+ located at the project's root path. It achieves this by loading the
194
+ binary through the use of the `ctypes.CDLL` method. The method also
195
+ sets expected argument types and a return type for a specific function
196
+ available in the shared library.
197
+
198
+ :return: None
199
+ """
150
200
  self._lib = ctypes.CDLL(str(self._binary_project_root_path))
151
201
  self._lib.purem.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.c_size_t]
152
202
  self._lib.purem.restype = None
153
203
 
154
204
  def _load_from_latest_cdn_index(self) -> Optional[Dict]:
205
+ """
206
+ Attempts to load the latest configuration from a CDN index, if a config URL is provided.
207
+ The method sends a request to the configured URL, reads its response, and parses it into
208
+ a dictionary. If there is no configured URL or an exception occurs during the process, it
209
+ returns None.
210
+
211
+ :raises Exception: If an error occurs during the request or while reading the response.
212
+
213
+ :return: A dictionary containing the parsed configuration data if the operation is
214
+ successful, or None if no config URL is provided or an error occurs.
215
+ :rtype: Optional[Dict]
216
+ """
155
217
  try:
156
218
  if self._config_url is not None:
157
219
  req = urllib.request.Request(
@@ -167,6 +229,21 @@ class Purem:
167
229
  return None
168
230
 
169
231
  def _set_binary(self):
232
+ """
233
+ Sets and initializes the binary for the Purem runtime environment. The method ensures that a valid binary
234
+ is available and properly configured. If a valid license key or binary is not found, the method will attempt
235
+ to download, validate, and extract the required binary files. If initialization fails at any stage,
236
+ appropriate errors are raised with detailed logging for debugging and support purposes.
237
+
238
+ :param self: Represents the instance of the class.
239
+ :type self: PuremRuntime
240
+
241
+ :raises ValueError: Raised if a valid license key is missing and cannot proceed with initialization.
242
+ :raises RuntimeError: Raised if the purem binary fails to load or cannot be initialized due to local issues,
243
+ license mismatch, or any other unexpected errors.
244
+
245
+ :return: None
246
+ """
170
247
  if os.path.exists(self._binary_path):
171
248
  self._tune_binary()
172
249
  elif os.path.exists(self._binary_project_root_path):
@@ -185,8 +262,8 @@ class Purem:
185
262
  )
186
263
  self._loader.start()
187
264
  self._download_binary_url = (
188
- self._build_url(self._load_from_latest_cdn_index())
189
- or f"{self._env.PUREM_DOWNLOAD_BINARY_URL}{self._license_key}"
265
+ self._build_url(self._load_from_latest_cdn_index())
266
+ or f"{self._env.PUREM_DOWNLOAD_BINARY_URL}{self._license_key}"
190
267
  )
191
268
  self._download_and_extract_binary()
192
269
  self._loader.stop()
@@ -212,9 +289,19 @@ class Purem:
212
289
  )
213
290
 
214
291
  def _download_and_extract_binary(self):
292
+ """
293
+ Downloads a binary file from a given URL, saves it temporarily, and extracts its
294
+ contents to a specific directory. Handles errors related to incomplete or
295
+ corrupted downloads and archives.
296
+
297
+ Raises runtime errors with detailed context if an issue occurs during download
298
+ or extraction. Ensures successful extraction and logs the output location.
299
+
300
+ :raises RuntimeError: If the download or extraction process fails due to
301
+ corrupted archive or any other unexpected issue.
302
+ """
215
303
  req = urllib.request.Request(
216
- self._download_binary_url,
217
- headers={"User-Agent": "Mozilla/5.0"}
304
+ self._download_binary_url, headers={"User-Agent": "Mozilla/5.0"}
218
305
  )
219
306
 
220
307
  try:
purem/env_config.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
purem/file_structure.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
purem/loader.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
@@ -18,21 +18,80 @@ import time
18
18
 
19
19
  class Loader:
20
20
  def __init__(self, message="Downloading"):
21
+ """
22
+ Represents a CLI-based animation that indicates a background task.
23
+
24
+ This class is designed to show a simple animation in the terminal
25
+ to convey the progress of an ongoing background task. The animation
26
+ runs in a separate thread to ensure that it does not block the main
27
+ thread's operations.
28
+
29
+ Attributes
30
+ ----------
31
+ _message : str
32
+ The text message displayed along with the animation.
33
+ _thread : threading.Thread
34
+ The thread responsible for running the animation in the background.
35
+ done : bool
36
+ A control flag to stop the animation when set to True.
37
+
38
+ :param message: The message to display alongside the animation. Defaults to
39
+ "Downloading".
40
+ """
21
41
  self._message = message
22
42
  self._thread = threading.Thread(target=self._animate, daemon=True)
23
43
  self.done = False
24
44
 
25
45
  def set_message(self, message: str):
46
+ """
47
+ Sets the message attribute of the instance.
48
+
49
+ :param message: A string representing the message to be assigned.
50
+ :type message: str
51
+ """
26
52
  self._message = message
27
53
 
28
54
  def start(self):
55
+ """
56
+ Starts the thread associated with this instance.
57
+
58
+ This method initiates the thread's execution by invoking the `start`
59
+ method on the `self._thread` object. It assumes that the `self._thread`
60
+ attribute has been properly initialized and is a valid thread instance.
61
+
62
+ :return: None
63
+ """
29
64
  self._thread.start()
30
65
 
31
66
  def stop(self):
67
+ """
68
+ Represents a mechanism to stop a thread execution gracefully.
69
+
70
+ This class or function provides a controlled way to stop a running thread
71
+ by marking it as done and waiting for the thread to conclude its execution.
72
+ It ensures the thread completes its ongoing tasks correctly before stopping.
73
+
74
+ :attributes:
75
+ done: Indicates whether the thread execution is flagged to stop.
76
+ _thread: The thread instance being managed.
77
+
78
+ :return: None
79
+ """
32
80
  self.done = True
33
81
  self._thread.join()
34
82
 
35
83
  def _animate(self):
84
+ """
85
+ Handles the animation of a loading spinner for a CLI-based task. The animation
86
+ displays a series of symbols in rotation while the task is ongoing. It
87
+ continues until the flag `self.done` is set to True. Once the task is complete,
88
+ a "done" message is displayed.
89
+
90
+ This method is designed to provide a simple user feedback mechanism during
91
+ long-running or background operations in command-line applications.
92
+
93
+ :return: None
94
+ """
36
95
  symbols = ["|", "/", "-", "\\"]
37
96
  i = 0
38
97
  while not self.done:
purem/logger.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
purem/utils.py CHANGED
@@ -2,7 +2,7 @@
2
2
  Business Source License 1.1
3
3
 
4
4
  Copyright (C) 2025 Raman Marozau, raman@worktif.com
5
- Use of this software is governed by the Business Source License included in the LICENSE.TXT file and at www.mariadb.com/bsl11.
5
+ Use of this software is governed by the Business Source License included in the LICENSE file and at www.mariadb.com/bsl11.
6
6
 
7
7
  Change Date: Never
8
8
  On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: purem
3
- Version: 2.1.6
3
+ Version: 3.0.1
4
4
  Summary: The official high-performance mapping function for mixed-type arrays powered by Work TIF Ltd.
5
5
  Author-email: Raman Marozau <raman@worktif.com>
6
6
  License-Expression: BUSL-1.1
@@ -0,0 +1,12 @@
1
+ purem/__init__.py,sha256=zF_hOKYn8X3jeoBxQ9X1irDi6HCPQ-HRcMP5fcocaNw,141
2
+ purem/core.py,sha256=fAWRKSzPp4x0YNKm_HrHWV9j38gISl2fLU6XyYIK33U,14772
3
+ purem/env_config.py,sha256=o1VujOYEH0XXVHbM0j84BEbO2FqlWVQ088DxlSfsvRU,2663
4
+ purem/file_structure.py,sha256=nYTSj74gDsnVAYAwkb5NGE1QHXvlkaYuaafB_FIAMaI,3337
5
+ purem/loader.py,sha256=GDeuiqZcKvZQEDaUg2TO5rC-WwVcjIgKqNEpF602mmg,3610
6
+ purem/logger.py,sha256=56pSIjyQal4IvaFzRpKBaQ8oMAdt-u638QK6uex-cRQ,1239
7
+ purem/utils.py,sha256=wjLHukHROX3GKJoEwXCR9X6CfqT70M1Mj6FcLtFUxJ8,923
8
+ purem-3.0.1.dist-info/licenses/LICENSE,sha256=5WFXHK6Xc_wj2EtvzVtd9TIC4cWEZJS8ECNTuvutsiE,1636
9
+ purem-3.0.1.dist-info/METADATA,sha256=qe1GhJoHEKQyjhJH7NR4c4XVhNlPhifKA-H_bY8HITg,5644
10
+ purem-3.0.1.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
11
+ purem-3.0.1.dist-info/top_level.txt,sha256=EjS75KEpZUEKSV2TFGW6w5aLqY9nUyO6Gq2ATz-KeZM,6
12
+ purem-3.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.0.0)
2
+ Generator: setuptools (80.3.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- purem/__init__.py,sha256=zF_hOKYn8X3jeoBxQ9X1irDi6HCPQ-HRcMP5fcocaNw,141
2
- purem/core.py,sha256=urg3JSdg2A-iVjYHJYPLnvNDPwUP5PElECAtSK1HRQY,10677
3
- purem/env_config.py,sha256=q1zOaiQLgqACfpU9d21kh004RSLjomORC8ZIvqFdnZE,2667
4
- purem/file_structure.py,sha256=8PRP9uk6PApOHwKF5Pfyg7CbZfgqTVwzV4NrYLJkTjY,3341
5
- purem/loader.py,sha256=F-4dFzBtmxnB8r4Y620WJhJ6-yAiBjmvZYCi8Z1ykkU,1274
6
- purem/logger.py,sha256=bs7jtx1cHmyuM6Irdcq60gTMURCai2pi5MIUB3TQcSQ,1243
7
- purem/utils.py,sha256=Kv0DPvt8SpSfKp4ar03ZP26Aj60dxW5Gf8B9FKKUrDc,927
8
- purem-2.1.6.dist-info/licenses/LICENSE,sha256=5WFXHK6Xc_wj2EtvzVtd9TIC4cWEZJS8ECNTuvutsiE,1636
9
- purem-2.1.6.dist-info/METADATA,sha256=wLqdwfxAnJi0FLLocMn7zFf4ayKwUpvA2OMjN6E1Y78,5644
10
- purem-2.1.6.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
11
- purem-2.1.6.dist-info/top_level.txt,sha256=EjS75KEpZUEKSV2TFGW6w5aLqY9nUyO6Gq2ATz-KeZM,6
12
- purem-2.1.6.dist-info/RECORD,,