machineconfig 6.29__py3-none-any.whl → 6.32__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.

Potentially problematic release.


This version of machineconfig might be problematic. Click here for more details.

@@ -7,7 +7,6 @@ from pathlib import Path
7
7
  def get_fire_command_and_artifact_files(func: FunctionType):
8
8
  from machineconfig.utils.meta import function_to_script
9
9
  py_script = function_to_script(func)
10
- from pathlib import Path
11
10
  from machineconfig.utils.accessories import randstr
12
11
  py_script_path = Path.home().joinpath("tmp_results", "tmp_py_scripts", f"tmp_{randstr(10)}.py")
13
12
  py_script_path.parent.mkdir(parents=True, exist_ok=True)
@@ -20,11 +19,13 @@ def get_fire_command_and_artifact_files(func: FunctionType):
20
19
  }
21
20
  return tab_config, py_script_path
22
21
  def get_fire_command_and_artifact_files_v2(func: FunctionType):
23
- import os
24
- command_to_run = f"""$HOME/.local/bin/fire {func.__module__.replace(".", os.sep)} {func.__name__} """
22
+ import inspect
23
+ path = Path(inspect.getfile(func))
24
+ path_relative = path.relative_to(Path.home())
25
+ command_to_run = f"""$HOME/.local/bin/fire {path_relative} {func.__name__} """
25
26
  tab_config: TabConfig = {
26
27
  "command": command_to_run,
27
- "startDir": str(Path(func.__module__).parent),
28
+ "startDir": "$HOME",
28
29
  "tabName": func.__name__
29
30
  }
30
31
  return tab_config
@@ -146,8 +146,6 @@ class Scheduler:
146
146
 
147
147
  # T = TypeVar("T")
148
148
  T2 = TypeVar("T2")
149
-
150
-
151
149
  def to_pickle(obj: Any, path: Path) -> None:
152
150
  import pickle
153
151
  path.parent.mkdir(parents=True, exist_ok=True)
@@ -156,11 +154,11 @@ def to_pickle(obj: Any, path: Path) -> None:
156
154
 
157
155
  class Cache[T](): # This class helps to accelrate access to latest data coming from expensive function. The class has two flavours, memory-based and disk-based variants."""
158
156
  def __init__(
159
- self, source_func: Callable[[], T], expire: timedelta, logger: LoggerTemplate, path: Optional[Path] = None, saver: Callable[[T, Path], Any] = to_pickle, reader: Callable[[Path], T] = from_pickle, name: Optional[str] = None
157
+ self, source_func: Callable[[], T], expire: timedelta, logger: LoggerTemplate, path: Path, saver: Callable[[T, Path], Any] = to_pickle, reader: Callable[[Path], T] = from_pickle, name: Optional[str] = None
160
158
  ) -> None:
161
159
  self.cache: T
162
160
  self.source_func = source_func # function which when called returns a fresh object to be frozen.
163
- self.path: Optional[PathExtended] = PathExtended(path) if path is not None else None # if path is passed, it will function as disk-based flavour.
161
+ self.path: PathExtended = PathExtended(path)
164
162
  self.time_produced = datetime.now() # if path is None else
165
163
  self.save = saver
166
164
  self.reader = reader
@@ -172,21 +170,11 @@ class Cache[T](): # This class helps to accelrate access to latest data coming
172
170
  @property
173
171
  def age(self):
174
172
  """Throws AttributeError if called before cache is populated and path doesn't exists"""
175
- if self.path is None: # memory-based cache.
176
- return datetime.now() - self.time_produced
177
- return datetime.now() - datetime.fromtimestamp(self.path.stat().st_mtime)
178
-
179
- # def __setstate__(self, state: dict[str, Any]) -> None:
180
- # self.__dict__.update(state)
181
- # self.path = P.home() / self.path if self.path is not None else self.path
182
- # def __getstate__(self) -> dict[str, Any]:
183
- # state = self.__dict__.copy()
184
- # state["path"] = self.path.rel2home() if self.path is not None else state["path"]
185
- # return state # With this implementation, instances can be pickled and loaded up in different machine and still works.
173
+ return datetime.now() - self.time_produced
186
174
  def __call__(self, fresh: bool = False) -> T:
187
175
  self.last_call_is_fresh = False
188
176
  if fresh or not hasattr(self, "cache"): # populate cache for the first time
189
- if not fresh and self.path is not None and self.path.exists():
177
+ if not fresh and self.path.exists():
190
178
  age = datetime.now() - datetime.fromtimestamp(self.path.stat().st_mtime)
191
179
  msg1 = f"""
192
180
  📦 ════════════════════ CACHE OPERATION ════════════════════
@@ -225,8 +213,7 @@ class Cache[T](): # This class helps to accelrate access to latest data coming
225
213
  self.cache = self.source_func() # fresh data.
226
214
  self.last_call_is_fresh = True
227
215
  self.time_produced = datetime.now()
228
- if self.path is not None:
229
- self.save(self.cache, self.path)
216
+ self.save(self.cache, self.path)
230
217
  else: # cache exists
231
218
  try:
232
219
  age = self.age
@@ -242,8 +229,7 @@ class Cache[T](): # This class helps to accelrate access to latest data coming
242
229
  self.cache = self.source_func()
243
230
  self.last_call_is_fresh = True
244
231
  self.time_produced = datetime.now()
245
- if self.path is not None:
246
- self.save(self.cache, self.path)
232
+ self.save(self.cache, self.path)
247
233
  else:
248
234
  if self.logger:
249
235
  self.logger.warning(f"""
@@ -255,7 +241,7 @@ class Cache[T](): # This class helps to accelrate access to latest data coming
255
241
 
256
242
  @staticmethod
257
243
  def as_decorator(
258
- expire: timedelta, logger: LoggerTemplate, path: Optional[Path] = None, saver: Callable[[T2, Path], Any] = to_pickle, reader: Callable[[Path], T2] = from_pickle, name: Optional[str] = None
244
+ expire: timedelta, logger: LoggerTemplate, path: Path, saver: Callable[[T2, Path], Any] = to_pickle, reader: Callable[[Path], T2] = from_pickle, name: Optional[str] = None
259
245
  ): # -> Callable[..., 'Cache[T2]']:
260
246
  def decorator(source_func: Callable[[], T2]) -> Cache["T2"]:
261
247
  res = Cache(source_func=source_func, expire=expire, logger=logger, path=path, name=name, reader=reader, saver=saver)
@@ -263,20 +249,20 @@ class Cache[T](): # This class helps to accelrate access to latest data coming
263
249
 
264
250
  return decorator
265
251
 
266
- def from_cloud(self, cloud: str, rel2home: bool = True, root: Optional[str] = None):
267
- assert self.path is not None
268
- exists = self.path.exists()
269
- exists_but_old = exists and ((datetime.now() - datetime.fromtimestamp(self.path.stat().st_mtime)) > self.expire)
270
- if not exists or exists_but_old:
271
- returned_path = self.path.from_cloud(cloud=cloud, rel2home=rel2home, root=root)
272
- if returned_path is None and not exists:
273
- raise FileNotFoundError(f"❌ Failed to get @ {self.path}. Build the cache first with signed API.")
274
- elif returned_path is None and exists:
275
- self.logger.warning(f"""
276
- ⚠️ ════════════════════ CLOUD FETCH WARNING ════════════════════
277
- 🔄 Failed to get fresh data from cloud
278
- 📦 Using old cache @ {self.path}
279
- ════════════════════════════════════════════════════════════════""")
280
- else:
281
- pass # maybe we don't need to fetch it from cloud, if its too hot
282
- return self.reader(self.path)
252
+ # def from_cloud(self, cloud: str, rel2home: bool = True, root: Optional[str] = None):
253
+ # assert self.path is not None
254
+ # exists = self.path.exists()
255
+ # exists_but_old = exists and ((datetime.now() - datetime.fromtimestamp(self.path.stat().st_mtime)) > self.expire)
256
+ # if not exists or exists_but_old:
257
+ # returned_path = self.path.from_cloud(cloud=cloud, rel2home=rel2home, root=root)
258
+ # if returned_path is None and not exists:
259
+ # raise FileNotFoundError(f"❌ Failed to get @ {self.path}. Build the cache first with signed API.")
260
+ # elif returned_path is None and exists:
261
+ # self.logger.warning(f"""
262
+ # ⚠️ ════════════════════ CLOUD FETCH WARNING ════════════════════
263
+ # 🔄 Failed to get fresh data from cloud
264
+ # 📦 Using old cache @ {self.path}
265
+ # ════════════════════════════════════════════════════════════════""")
266
+ # else:
267
+ # pass # maybe we don't need to fetch it from cloud, if its too hot
268
+ # return self.reader(self.path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machineconfig
3
- Version: 6.29
3
+ Version: 6.32
4
4
  Summary: Dotfiles management package
5
5
  Author-email: Alex Al-Saffar <programmer@usa.com>
6
6
  License: Apache 2.0
@@ -25,7 +25,7 @@ machineconfig/cluster/sessions_managers/zellij_remote_manager.py,sha256=xzih0y8_
25
25
  machineconfig/cluster/sessions_managers/helpers/enhanced_command_runner.py,sha256=3vcQVg-HHa_WTxBGPtKMAdoSqJVa2EO5KAtrY8a6I3c,5264
26
26
  machineconfig/cluster/sessions_managers/helpers/load_balancer_helper.py,sha256=i5TRittC1IWTgMZNyG8AR5qq-3WrGp3xgIx2m5ktT7g,7526
27
27
  machineconfig/cluster/sessions_managers/utils/load_balancer.py,sha256=Y4RQmhROY6o7JXSJXRrBTkoAuEmu1gvmvN_7JKPw5sc,3178
28
- machineconfig/cluster/sessions_managers/utils/maker.py,sha256=5_1uD-kcZC_SNEB-uryobVk81GULGhhpSXeDZt3UZfU,2094
28
+ machineconfig/cluster/sessions_managers/utils/maker.py,sha256=CeV9XrF5OhgNZe-qa916hNuy7mD9w-9TLOL3nLPXENs,2110
29
29
  machineconfig/cluster/sessions_managers/wt_utils/layout_generator.py,sha256=OA50j16uUS9ZTjL38TLuR3jufIOln_EszMZpbWyejTo,6972
30
30
  machineconfig/cluster/sessions_managers/wt_utils/process_monitor.py,sha256=Mitm7mKiKl5lT0OiEUHAqVg2Q21RjsKO1-hpJTHJ5lM,15196
31
31
  machineconfig/cluster/sessions_managers/wt_utils/remote_executor.py,sha256=lApUy67_WhfaBXqt0meZSx_QvwiXjN0YLdyE3c7kP_s,6744
@@ -394,7 +394,7 @@ machineconfig/utils/options.py,sha256=vUO4Kej-vDOv64wHr2HNDyu6PATURpjd7xp6N8OOoJ
394
394
  machineconfig/utils/path_extended.py,sha256=WyJwoHnXdvSQQJ-yrxTX78FpqYmgVeKDYpNEB9UsRck,53223
395
395
  machineconfig/utils/path_helper.py,sha256=0e3Xh3BAEv27oqcezNeVLHJllGmLEgLH4T1l90m-650,8014
396
396
  machineconfig/utils/procs.py,sha256=rw8LR8MjGgvtrpcgxb3hudq2B9fkkpYUXe9x5-FgHuc,10694
397
- machineconfig/utils/scheduler.py,sha256=jZ_1yghqA3-aINPRmE_76gboqJc0UElroR7urNOfXKs,14940
397
+ machineconfig/utils/scheduler.py,sha256=u56Y0UOIq-0WcwzScwjoiKFzBV47Lx--4lR52UD3y0M,14089
398
398
  machineconfig/utils/scheduling.py,sha256=RF1iXJpqf4Dg18jdZWtBixz97KAHC6VKYqTFSpdLWuc,11188
399
399
  machineconfig/utils/source_of_truth.py,sha256=ZAnCRltiM07ig--P6g9_6nEAvNFC4X4ERFTVcvpIYsE,764
400
400
  machineconfig/utils/ssh.py,sha256=dO-FereJBh5mB4zmL_fDIfQ6VVCWpJ3Y8IoAJ5SA4zQ,39079
@@ -422,8 +422,8 @@ machineconfig/utils/schemas/installer/installer_types.py,sha256=QClRY61QaduBPJoS
422
422
  machineconfig/utils/schemas/layouts/layout_types.py,sha256=TcqlZdGVoH8htG5fHn1KWXhRdPueAcoyApppZsPAPto,2020
423
423
  machineconfig/utils/schemas/repos/repos_types.py,sha256=ECVr-3IVIo8yjmYmVXX2mnDDN1SLSwvQIhx4KDDQHBQ,405
424
424
  machineconfig/utils/ssh_utils/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
425
- machineconfig-6.29.dist-info/METADATA,sha256=z2p2bK9wcSiMkD-Z2YLRh7AtQlEZcTz7tnf90bM9l6s,3012
426
- machineconfig-6.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
427
- machineconfig-6.29.dist-info/entry_points.txt,sha256=M0jwN_brZdXWhmNVeXLvdKxfkv8WhhXFZYcuKBA9qnk,418
428
- machineconfig-6.29.dist-info/top_level.txt,sha256=porRtB8qms8fOIUJgK-tO83_FeH6Bpe12oUVC670teA,14
429
- machineconfig-6.29.dist-info/RECORD,,
425
+ machineconfig-6.32.dist-info/METADATA,sha256=vVj42KcByWj_yUt6oAbD7f23iUI4tnUbWvnyX2RsIQM,3012
426
+ machineconfig-6.32.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
427
+ machineconfig-6.32.dist-info/entry_points.txt,sha256=M0jwN_brZdXWhmNVeXLvdKxfkv8WhhXFZYcuKBA9qnk,418
428
+ machineconfig-6.32.dist-info/top_level.txt,sha256=porRtB8qms8fOIUJgK-tO83_FeH6Bpe12oUVC670teA,14
429
+ machineconfig-6.32.dist-info/RECORD,,