purem 3.0.1__py3-none-any.whl → 3.0.3__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/__init__.py CHANGED
@@ -2,5 +2,4 @@ from purem.env_config import load_env_config
2
2
 
3
3
  from purem.core import Purem
4
4
 
5
-
6
- purem = Purem(licenced_key=load_env_config().PUREM_LICENSE_KEY)
5
+ purem = Purem()
purem/core.py CHANGED
@@ -11,7 +11,6 @@ Additional Use Grant: Free for personal and non-commercial research use only.
11
11
  SPDX-License-Identifier: BUSL-1.1
12
12
  """
13
13
 
14
- import base64
15
14
  import ctypes
16
15
  import json
17
16
  import os
@@ -19,17 +18,16 @@ import shutil
19
18
  import ssl
20
19
  import urllib.request
21
20
  import zipfile
22
- from typing import List, Optional, Dict
21
+ from pathlib import Path
22
+ from typing import Optional, Dict
23
23
 
24
24
  import certifi as certifi
25
- import numpy as np
26
25
  from numpy import ndarray
27
26
 
28
- from purem.env_config import load_env_config
27
+ from purem.env_config import load_env_config, EnvConfig
29
28
  from purem.file_structure import FileStructure
30
29
  from purem.loader import Loader
31
30
  from purem.logger import Logger
32
- from purem.utils import _compute_shifted_jit
33
31
 
34
32
 
35
33
  class Purem:
@@ -68,7 +66,7 @@ class Purem:
68
66
  :type _log: Logger
69
67
  """
70
68
 
71
- def __init__(self, licenced_key: Optional[str] = None):
69
+ def __init__(self):
72
70
  """
73
71
  Represents the initialization and configuration of an environment, license key,
74
72
  and file structure required for the system's binary operations.
@@ -76,26 +74,28 @@ class Purem:
76
74
  :param licenced_key: Optional license key string for initializing the system.
77
75
  :type licenced_key: Optional[str]
78
76
  """
79
- self._license_key = licenced_key or None
80
- self._lib = None
81
- self._download_binary_url = None
77
+ self._lib: Optional[ctypes.CDLL] = None
78
+ self._download_binary_url: Optional[str] = None
82
79
  self._ctx = ssl.create_default_context(cafile=certifi.where())
83
80
  self._file_structure = FileStructure()
84
- self._binary_path = self._file_structure.get_binary_path()
85
- self._binary_project_root_path = (
81
+ self._binary_path: Path = self._file_structure.get_binary_path()
82
+ self._binary_project_root_path: Path = (
86
83
  self._file_structure.get_binary_project_root_path()
87
84
  )
88
- self._binary_archive_path = self._file_structure.get_binary_archive_path()
89
- self._binary_archive_path_tmp = (
85
+ self._binary_archive_path: Path = self._file_structure.get_binary_archive_path()
86
+ self._binary_archive_path_tmp: Path = (
90
87
  self._file_structure.get_binary_archive_path_tmp()
91
88
  )
92
- self._env = load_env_config()
93
- self._config_url = (
94
- self._env.PUREM_CONFIG_URL
95
- or "https://api.worktif.com/v2/portal/products/purem/config"
89
+ self._env: EnvConfig = load_env_config()
90
+ self._license_key: Optional[str] = self._env.PUREM_LICENSE_KEY or None
91
+ self._config_url: str = (
92
+ self._env.PUREM_CONFIG_URL
93
+ or "https://api.worktif.com/v2/portal/products/purem/config"
96
94
  )
97
- self._loader = Loader()
98
- self._log = Logger()
95
+ self._loader: Loader = Loader()
96
+ self._log: Logger = Logger()
97
+ if self._license_key is not None:
98
+ self.configure(license_key=self._license_key)
99
99
 
100
100
  def configure(self, license_key: Optional[str] = None) -> None:
101
101
  """
@@ -125,9 +125,18 @@ class Purem:
125
125
  self._set_binary()
126
126
 
127
127
  def softmax(self, array: ndarray) -> ndarray:
128
- ptr = array.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
129
- self._lib.purem(ptr, array.size)
130
- return array
128
+ try:
129
+ ptr = array.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
130
+ self._lib.purem(ptr, array.size)
131
+ return array
132
+ except Exception as e:
133
+ raise ValueError(
134
+ self._log.info(
135
+ "Purem requires a valid license key to initialize.\n"
136
+ "You can obtain your key at https://worktif.com or through your enterprise deployment.",
137
+ verbose=True
138
+ )
139
+ )
131
140
 
132
141
  def softmax_pure(self, ptr, size) -> None:
133
142
  """
@@ -168,7 +177,7 @@ class Purem:
168
177
  binary_url = f"{protocol}://{base}/{path}{self._license_key}"
169
178
  return binary_url
170
179
 
171
- def _tune_binary(self):
180
+ def _tune_binary(self) -> None:
172
181
  """
173
182
  Tunes the binary by loading the specified binary file as a shared library
174
183
  and setting up its function signatures for further use.
@@ -185,7 +194,7 @@ class Purem:
185
194
  self._lib.purem.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.c_size_t]
186
195
  self._lib.purem.restype = None
187
196
 
188
- def _tune_project_root_binary(self):
197
+ def _tune_project_root_binary(self) -> None:
189
198
  """
190
199
  Tuning the project root binary configuration.
191
200
 
@@ -228,7 +237,7 @@ class Purem:
228
237
  except Exception:
229
238
  return None
230
239
 
231
- def _set_binary(self):
240
+ def _set_binary(self) -> None:
232
241
  """
233
242
  Sets and initializes the binary for the Purem runtime environment. The method ensures that a valid binary
234
243
  is available and properly configured. If a valid license key or binary is not found, the method will attempt
@@ -262,8 +271,8 @@ class Purem:
262
271
  )
263
272
  self._loader.start()
264
273
  self._download_binary_url = (
265
- self._build_url(self._load_from_latest_cdn_index())
266
- or f"{self._env.PUREM_DOWNLOAD_BINARY_URL}{self._license_key}"
274
+ self._build_url(self._load_from_latest_cdn_index())
275
+ or f"{self._env.PUREM_DOWNLOAD_BINARY_URL}{self._license_key}"
267
276
  )
268
277
  self._download_and_extract_binary()
269
278
  self._loader.stop()
@@ -288,7 +297,7 @@ class Purem:
288
297
  )
289
298
  )
290
299
 
291
- def _download_and_extract_binary(self):
300
+ def _download_and_extract_binary(self) -> None:
292
301
  """
293
302
  Downloads a binary file from a given URL, saves it temporarily, and extracts its
294
303
  contents to a specific directory. Handles errors related to incomplete or
@@ -337,3 +346,16 @@ class Purem:
337
346
  )
338
347
 
339
348
  self._binary_archive_path.unlink()
349
+
350
+ def has_license_key(self) -> bool:
351
+ """
352
+ Checks if an object has a valid license key.
353
+
354
+ This method evaluates whether the `_license_key` attribute of
355
+ the object is not `None`, implying the presence of a license key.
356
+
357
+ :return: Returns `True` if the `_license_key` attribute is not
358
+ `None`, otherwise returns `False`.
359
+ :rtype: bool
360
+ """
361
+ return self._license_key is not None
purem/logger.py CHANGED
@@ -19,8 +19,8 @@ class Logger:
19
19
  self._env = load_env_config()
20
20
  self._default_info_message = f"Something went wrong"
21
21
 
22
- def info(self, message: str) -> str:
23
- if self._env.PUREM_VERBOSE is True:
22
+ def info(self, message: str, verbose: bool = False) -> str:
23
+ if self._env.PUREM_VERBOSE is True or verbose is True:
24
24
  return f"[purem]: {message}\n"
25
25
  else:
26
26
  return f"[purem]: {self._default_info_message}\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: purem
3
- Version: 3.0.1
3
+ Version: 3.0.3
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
@@ -25,7 +25,6 @@ Requires-Python: >=3.11
25
25
  Description-Content-Type: text/x-rst
26
26
  License-File: LICENSE
27
27
  Requires-Dist: numpy~=2.1.3
28
- Requires-Dist: pytest~=8.3.5
29
28
  Requires-Dist: numba~=0.61.0
30
29
  Requires-Dist: certifi~=2025.1.31
31
30
  Requires-Dist: pydantic~=2.10.6
@@ -33,6 +32,8 @@ Requires-Dist: dotenv~=0.9.9
33
32
  Requires-Dist: python-dotenv~=1.1.0
34
33
  Requires-Dist: setuptools~=65.5.1
35
34
  Requires-Dist: requests~=2.32.3
35
+ Requires-Dist: pytest~=8.3.5
36
+ Requires-Dist: pytest-env~=1.1.5
36
37
  Provides-Extra: dev
37
38
  Requires-Dist: pytest; extra == "dev"
38
39
  Requires-Dist: flake8; extra == "dev"
@@ -0,0 +1,12 @@
1
+ purem/__init__.py,sha256=of-z4lRvk7cmLLsCbiXHIPXVjP0FHBCByndtPgINfT0,92
2
+ purem/core.py,sha256=d5EQKN-UkrB2nnwm1LLUin6oPwjCHAUFUnfFyXgDaiM,15773
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=vZHUGwL-MXJPNBoHIxqLf26KOF9qk4xj2qdgUhRas8c,1281
7
+ purem/utils.py,sha256=wjLHukHROX3GKJoEwXCR9X6CfqT70M1Mj6FcLtFUxJ8,923
8
+ purem-3.0.3.dist-info/licenses/LICENSE,sha256=5WFXHK6Xc_wj2EtvzVtd9TIC4cWEZJS8ECNTuvutsiE,1636
9
+ purem-3.0.3.dist-info/METADATA,sha256=h-AbmXTkdrfUSF2UOCYkZ5zDf2YH_uqcxhh9sDPuAsw,5677
10
+ purem-3.0.3.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
11
+ purem-3.0.3.dist-info/top_level.txt,sha256=EjS75KEpZUEKSV2TFGW6w5aLqY9nUyO6Gq2ATz-KeZM,6
12
+ purem-3.0.3.dist-info/RECORD,,
@@ -1,12 +0,0 @@
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,,
File without changes