naeural-client 2.7.40__py3-none-any.whl → 2.7.42__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.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.7.40"
1
+ __VER__ = "2.7.42"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -23,6 +23,10 @@ class IPFSCt:
23
23
  R1FS_UPLOADS = "ipfs_uploads"
24
24
  TEMP_DOWNLOAD = os.path.join("./_local_cache/_output", R1FS_DOWNLOADS)
25
25
  TEMP_UPLOAD = os.path.join("./_local_cache/_output", R1FS_UPLOADS)
26
+
27
+ TIMEOUT = 90 # seconds
28
+ REPROVIDER = "1m"
29
+
26
30
 
27
31
  ERROR_TAG = "Unknown"
28
32
 
@@ -201,24 +205,38 @@ class R1FSEngine:
201
205
  def downloaded_files(self):
202
206
  return self.__downloaded_files
203
207
 
204
- def get_unique_name(self, prefix="r1fs", suffix=""):
208
+ def _get_unique_name(self, prefix="r1fs", suffix=""):
205
209
  str_id = str(uuid.uuid4()).replace("-", "")[:8]
206
210
  return f"{prefix}_{str_id}{suffix}"
207
211
 
208
- def get_unique_upload_name(self, prefix="r1fs", suffix=""):
209
- return os.path.join(self.__uploads_dir, self.get_unique_name(prefix, suffix))
212
+ def _get_unique_upload_name(self, prefix="r1fs", suffix=""):
213
+ return os.path.join(self.__uploads_dir, self._get_unique_name(prefix, suffix))
210
214
 
211
- def get_unique_or_complete_upload_name(self, fn=None, prefix="r1fs", suffix=""):
215
+ def _get_unique_or_complete_upload_name(self, fn=None, prefix="r1fs", suffix=""):
212
216
  if fn is not None and os.path.dirname(fn) == "":
213
217
  return os.path.join(self.__uploads_dir, fn)
214
- return self.get_unique_upload_name(prefix, suffix)
218
+ return self._get_unique_upload_name(prefix, suffix)
219
+
220
+ def __set_reprovider_interval(self):
221
+ # Command to set the Reprovider.Interval to 1 minute
222
+ cmd = ["ipfs", "config", "--json", "Reprovider.Interval", f'"{IPFSCt.REPROVIDER}"']
223
+ result = self.__run_command(cmd)
224
+ return
225
+
215
226
 
227
+ def __set_relay(self):
228
+ # Command to enable the IPFS relay
229
+ result = self.__run_command(
230
+ ["ipfs", "config", "--json", "Swarm.DisableRelay", "false"]
231
+ )
232
+ return
233
+
216
234
 
217
235
  def __run_command(
218
236
  self,
219
237
  cmd_list: list,
220
238
  raise_on_error=True,
221
- timeout=60,
239
+ timeout=IPFSCt.TIMEOUT,
222
240
  verbose=False,
223
241
  ):
224
242
  """
@@ -297,7 +315,7 @@ class R1FSEngine:
297
315
  f.write(json_data)
298
316
  fn = f.name
299
317
  else:
300
- fn = self.get_unique_or_complete_upload_name(fn=fn, suffix=".json")
318
+ fn = self._get_unique_or_complete_upload_name(fn=fn, suffix=".json")
301
319
  self.Pd(f"Using unique name for JSON: {fn}")
302
320
  with open(fn, "w") as f:
303
321
  f.write(json_data)
@@ -322,7 +340,7 @@ class R1FSEngine:
322
340
  f.write(yaml_data)
323
341
  fn = f.name
324
342
  else:
325
- fn = self.get_unique_or_complete_upload_name(fn=fn, suffix=".yaml")
343
+ fn = self._get_unique_or_complete_upload_name(fn=fn, suffix=".yaml")
326
344
  self.Pd(f"Using unique name for YAML: {fn}")
327
345
  with open(fn, "w") as f:
328
346
  f.write(yaml_data)
@@ -345,7 +363,7 @@ class R1FSEngine:
345
363
  pickle.dump(data, f)
346
364
  fn = f.name
347
365
  else:
348
- fn = self.get_unique_or_complete_upload_name(fn=fn, suffix=".pkl")
366
+ fn = self._get_unique_or_complete_upload_name(fn=fn, suffix=".pkl")
349
367
  self.Pd(f"Using unique name for pkl: {fn}")
350
368
  with open(fn, "wb") as f:
351
369
  pickle.dump(data, f)
@@ -415,14 +433,16 @@ class R1FSEngine:
415
433
  local_folder = os.path.join(local_folder, cid) # add the CID as a subfolder
416
434
 
417
435
  self.Pd(f"Downloading file {cid} to {local_folder}")
436
+ start_time = time.time()
418
437
  self.__run_command(["ipfs", "get", cid, "-o", local_folder])
438
+ elapsed_time = time.time() - start_time
419
439
  # now we need to get the file from the folder
420
440
  folder_contents = os.listdir(local_folder)
421
441
  if len(folder_contents) != 1:
422
442
  raise Exception(f"Expected one file in {local_folder}, found {folder_contents}")
423
443
  # get the full path of the file
424
444
  out_local_filename = os.path.join(local_folder, folder_contents[0])
425
- self.P(f"Downloaded <{cid}> to {out_local_filename}")
445
+ self.P(f"Downloaded in {elapsed_time:.1f}s <{cid}> to {out_local_filename}")
426
446
  self.__downloaded_files[cid] = out_local_filename
427
447
  return out_local_filename
428
448
 
@@ -528,8 +548,11 @@ class R1FSEngine:
528
548
  self.P("IPFS daemon running", color='g')
529
549
 
530
550
  except Exception:
551
+ self.Pd("ipfs id failed, starting daemon...")
531
552
  try:
532
- self.P("Starting IPFS daemon in background...")
553
+ self.__set_reprovider_interval()
554
+ self.__set_relay()
555
+ self.P("Starting IPFS daemon in background...")
533
556
  subprocess.Popen(["ipfs", "daemon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
534
557
  time.sleep(5)
535
558
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.7.40
3
+ Version: 2.7.42
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,5 +1,5 @@
1
1
  naeural_client/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- naeural_client/_ver.py,sha256=w-s-yz0eHjAKD9mUqSByv0yLn__Zw5dFOhJPHU7DI3w,331
2
+ naeural_client/_ver.py,sha256=Q93aXw2mji9yRTgEWkuF0JwuicbvBiHlVU3oFdsJmUs,331
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
@@ -61,7 +61,7 @@ naeural_client/io_formatter/default/a_dummy.py,sha256=qr9eUizQ-NN5jdXVzkaZKMaf9K
61
61
  naeural_client/io_formatter/default/aixp1.py,sha256=MX0TeUR4APA-qN3vUC6uzcz8Pssz5lgrQWo7td5Ri1A,3052
62
62
  naeural_client/io_formatter/default/default.py,sha256=gEy78cP2D5s0y8vQh4aHuxqz7D10gGfuiKF311QhrpE,494
63
63
  naeural_client/ipfs/__init__.py,sha256=vXEDLUNUO6lOTMGa8iQ9Zf7ajIQq9GZuvYraAHt3meE,38
64
- naeural_client/ipfs/r1fs.py,sha256=u_Dy05wH_Xt4GTvxjLwSoz5hzRz0Tc2Tr-0c2BxwXtg,16503
64
+ naeural_client/ipfs/r1fs.py,sha256=vqqSDulF1AlqrepCS8byGAv3JwNppMwbdS1KmuTvKw8,17213
65
65
  naeural_client/logging/__init__.py,sha256=b79X45VC6c37u32flKB2GAK9f-RR0ocwP0JDCy0t7QQ,33
66
66
  naeural_client/logging/base_logger.py,sha256=qqqMX30Vmh5Dz8YYaeL_ainQPTP5FsX1Y4QMbsIG5Rg,69599
67
67
  naeural_client/logging/small_logger.py,sha256=m12hCb_H4XifJYYfgCAOUDkcXm-h4pSODnFf277OFVI,2937
@@ -88,8 +88,8 @@ naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_L
88
88
  naeural_client/utils/config.py,sha256=lAbWe3UMi40BOdsAIZIb-fYtb4LwG3MIYg0EOA1ITr8,10340
89
89
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
90
90
  naeural_client/utils/oracle_sync/oracle_tester.py,sha256=X-923ccjkr6_kzbbiuAAcWSIhMtBDOH2VURjTh55apQ,27235
91
- naeural_client-2.7.40.dist-info/METADATA,sha256=cRiEi7AbNAdspHTFOmzlUxQwk6MzIoKtTYwudP65_fo,12354
92
- naeural_client-2.7.40.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- naeural_client-2.7.40.dist-info/entry_points.txt,sha256=CTua17GUrRa4aXeafezGC9TiWKGKQzwTjQmB2jyj22g,91
94
- naeural_client-2.7.40.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
95
- naeural_client-2.7.40.dist-info/RECORD,,
91
+ naeural_client-2.7.42.dist-info/METADATA,sha256=_MgS-DeFCJsXJlhrvjUxxo2bzlFgs494DCfztb8JrOM,12354
92
+ naeural_client-2.7.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
+ naeural_client-2.7.42.dist-info/entry_points.txt,sha256=CTua17GUrRa4aXeafezGC9TiWKGKQzwTjQmB2jyj22g,91
94
+ naeural_client-2.7.42.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
95
+ naeural_client-2.7.42.dist-info/RECORD,,