amalgam-lang 6.2.0__py3-none-win_amd64.whl → 7.0.1__py3-none-win_amd64.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 amalgam-lang might be problematic. Click here for more details.

amalgam/api.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from ctypes import (
2
2
  byref, cast, c_bool, c_char, c_char_p, c_double, c_size_t, c_uint64, c_void_p,
3
- cdll, POINTER
3
+ cdll, POINTER, Structure
4
4
  )
5
5
  from datetime import datetime
6
6
  import gc
@@ -15,12 +15,45 @@ import warnings
15
15
  _logger = logging.getLogger('amalgam')
16
16
 
17
17
 
18
+ class _LoadEntityStatus(Structure):
19
+ """
20
+ A private status returned from Amalgam binary LoadEntity C API.
21
+
22
+ This is implemented with ctypes for accessing binary Amalgam builds.
23
+ """
24
+ _fields_ = [
25
+ ("loaded", c_bool),
26
+ ("message", POINTER(c_char)),
27
+ ("version", POINTER(c_char))
28
+ ]
29
+
30
+
31
+ class LoadEntityStatus:
32
+ """
33
+ Status returned by :func:`~api.Amalgam.load_entity`.
34
+
35
+ This is implemented with python types and is meant to wrap _LoadEntityStatus
36
+ which uses ctypes and directly interacts with the Amalgam binaries.
37
+ """
38
+ def __init__(self, api, c_status: _LoadEntityStatus = None):
39
+ if c_status is None:
40
+ self.loaded = True
41
+ self.message = ""
42
+ self.version = ""
43
+ else:
44
+ self.loaded = bool(c_status.loaded)
45
+ self.message = api.char_p_to_bytes(c_status.message).decode("utf-8")
46
+ self.version = api.char_p_to_bytes(c_status.version).decode("utf-8")
47
+
48
+ def __str__(self):
49
+ return f"{self.loaded},\"{self.message}\",\"{self.version}\""
50
+
51
+
18
52
  class Amalgam:
19
53
  """
20
54
  A general python direct interface to the Amalgam library.
21
55
 
22
- This is implemented with ctypes for accessing binary amalgam builds in
23
- Linux, MacOS and Windows.
56
+ This is implemented with ctypes for accessing binary Amalgam builds.
24
57
 
25
58
  Parameters
26
59
  ----------
@@ -479,16 +512,6 @@ class Amalgam:
479
512
  self.trace.write(execution_string + "\n")
480
513
  self.trace.flush()
481
514
 
482
- def _copy_to_bytes(self, p) -> bytes:
483
- """Copies a native C char* to bytes, cleaning up native memory correctly."""
484
- bytes = cast(p, c_char_p).value
485
-
486
- self.amlg.DeleteString.argtypes = c_char_p,
487
- self.amlg.DeleteString.restype = None
488
- self.amlg.DeleteString(p)
489
-
490
- return bytes
491
-
492
515
  def gc(self) -> None:
493
516
  """Force garbage collection when called if self.force_gc is set."""
494
517
  if (
@@ -506,7 +529,9 @@ class Amalgam:
506
529
  size: Optional[int] = None
507
530
  ) -> c_char:
508
531
  """
509
- Convert a string to a c++ char pointer.
532
+ Convert a string to a C char pointer.
533
+
534
+ User must call `del` on returned buffer
510
535
 
511
536
  Parameters
512
537
  ----------
@@ -519,7 +544,7 @@ class Amalgam:
519
544
  Returns
520
545
  -------
521
546
  c_char
522
- A c++ char point for the string.
547
+ A C char pointer for the string.
523
548
  """
524
549
  if isinstance(value, str):
525
550
  value = value.encode('utf-8')
@@ -528,6 +553,28 @@ class Amalgam:
528
553
  buf.value = value
529
554
  return buf
530
555
 
556
+ def char_p_to_bytes(self, p: POINTER(c_char)) -> bytes:
557
+ """
558
+ Copies a native C char pointer to bytes, cleaning up native memory correctly.
559
+
560
+ Parameters
561
+ ----------
562
+ p : LP_char_p
563
+ C pointer to string to convert
564
+
565
+ Returns
566
+ -------
567
+ bytes
568
+ The byte-encoded string from C pointer
569
+ """
570
+ bytes = cast(p, c_char_p).value
571
+
572
+ self.amlg.DeleteString.argtypes = c_char_p,
573
+ self.amlg.DeleteString.restype = None
574
+ self.amlg.DeleteString(p)
575
+
576
+ return bytes
577
+
531
578
  def get_json_from_label(self, handle: str, label: str) -> bytes:
532
579
  """
533
580
  Get a label from amalgam and returns it in json format.
@@ -544,15 +591,19 @@ class Amalgam:
544
591
  bytes
545
592
  The byte-encoded json representation of the amalgam label.
546
593
  """
547
- self.amlg.GetJSONPtrFromLabel.restype = c_char_p
594
+ self.amlg.GetJSONPtrFromLabel.restype = POINTER(c_char)
548
595
  self.amlg.GetJSONPtrFromLabel.argtype = [c_char_p, c_char_p]
549
596
  handle_buf = self.str_to_char_p(handle)
550
597
  label_buf = self.str_to_char_p(label)
551
- result = self.amlg.GetJSONPtrFromLabel(handle_buf, label_buf)
552
- self._log_execution(f"GET_JSON_FROM_LABEL {handle} {label}")
598
+
599
+ self._log_execution(f"GET_JSON_FROM_LABEL \"{handle}\" \"{label}\"")
600
+ result = self.char_p_to_bytes(self.amlg.GetJSONPtrFromLabel(handle_buf, label_buf))
601
+ self._log_reply(result)
602
+
553
603
  del handle_buf
554
604
  del label_buf
555
605
  self.gc()
606
+
556
607
  return result
557
608
 
558
609
  def set_json_to_label(
@@ -578,8 +629,11 @@ class Amalgam:
578
629
  handle_buf = self.str_to_char_p(handle)
579
630
  label_buf = self.str_to_char_p(label)
580
631
  json_buf = self.str_to_char_p(json)
581
- self._log_execution(f"SET_JSON_TO_LABEL {handle} {label} {json}")
632
+
633
+ self._log_execution(f"SET_JSON_TO_LABEL \"{handle}\" \"{label}\" {json}")
582
634
  self.amlg.SetJSONToLabel(handle_buf, label_buf, json_buf)
635
+ self._log_reply(None)
636
+
583
637
  del handle_buf
584
638
  del label_buf
585
639
  del json_buf
@@ -593,7 +647,7 @@ class Amalgam:
593
647
  load_contained: bool = False,
594
648
  write_log: str = "",
595
649
  print_log: str = ""
596
- ) -> bool:
650
+ ) -> LoadEntityStatus:
597
651
  """
598
652
  Load an entity from an amalgam source file.
599
653
 
@@ -617,33 +671,126 @@ class Amalgam:
617
671
 
618
672
  Returns
619
673
  -------
620
- bool
621
- True if the entity was successfully loaded.
674
+ LoadEntityStatus
675
+ Status of LoadEntity call.
622
676
  """
623
677
  self.amlg.LoadEntity.argtype = [
624
678
  c_char_p, c_char_p, c_bool, c_bool, c_char_p, c_char_p]
625
- self.amlg.LoadEntity.restype = c_bool
679
+ self.amlg.LoadEntity.restype = _LoadEntityStatus
626
680
  handle_buf = self.str_to_char_p(handle)
627
681
  amlg_path_buf = self.str_to_char_p(amlg_path)
628
682
  write_log_buf = self.str_to_char_p(write_log)
629
683
  print_log_buf = self.str_to_char_p(print_log)
630
684
 
631
- self.load_command_log_entry = (
632
- f"LOAD_ENTITY {handle} \"{amlg_path}\" {str(persist).lower()} "
633
- f"{str(load_contained).lower()} {write_log} {print_log}"
685
+ load_command_log_entry = (
686
+ f"LOAD_ENTITY \"{handle}\" \"{amlg_path}\" {str(persist).lower()} "
687
+ f"{str(load_contained).lower()} \"{write_log}\" \"{print_log}\""
634
688
  )
635
- self._log_execution(self.load_command_log_entry)
636
- result = self.amlg.LoadEntity(
689
+ self._log_execution(load_command_log_entry)
690
+ result = LoadEntityStatus(self, self.amlg.LoadEntity(
637
691
  handle_buf, amlg_path_buf, persist, load_contained,
638
- write_log_buf, print_log_buf)
692
+ write_log_buf, print_log_buf))
639
693
  self._log_reply(result)
694
+
640
695
  del handle_buf
641
696
  del amlg_path_buf
642
697
  del write_log_buf
643
698
  del print_log_buf
644
699
  self.gc()
700
+
645
701
  return result
646
702
 
703
+ def verify_entity(
704
+ self,
705
+ amlg_path: str
706
+ ) -> LoadEntityStatus:
707
+ """
708
+ Verify an entity from an amalgam source file.
709
+
710
+ Parameters
711
+ ----------
712
+ amlg_path : str
713
+ The path to the filename.amlg/caml file.
714
+
715
+ Returns
716
+ -------
717
+ LoadEntityStatus
718
+ Status of VerifyEntity call.
719
+ """
720
+ self.amlg.VerifyEntity.argtype = [c_char_p]
721
+ self.amlg.VerifyEntity.restype = _LoadEntityStatus
722
+ amlg_path_buf = self.str_to_char_p(amlg_path)
723
+
724
+ self._log_execution(f"VERIFY_ENTITY \"{amlg_path}\"")
725
+ result = LoadEntityStatus(self, self.amlg.VerifyEntity(amlg_path_buf))
726
+ self._log_reply(result)
727
+
728
+ del amlg_path_buf
729
+ self.gc()
730
+
731
+ return result
732
+
733
+ def store_entity(
734
+ self,
735
+ handle: str,
736
+ amlg_path: str,
737
+ update_persistence_location: bool = False,
738
+ store_contained: bool = False
739
+ ) -> None:
740
+ """
741
+ Stores an entity to the file type specified within amlg_path.
742
+
743
+ Parameters
744
+ ----------
745
+ handle : str
746
+ The handle of the amalgam entity.
747
+ amlg_path : str
748
+ The path to the filename.amlg/caml file.
749
+ update_persistence_location : bool
750
+ If set to true, updates location entity is persisted to.
751
+ store_contained : bool
752
+ If set to true, contained entities will be stored.
753
+ """
754
+ self.amlg.StoreEntity.argtype = [
755
+ c_char_p, c_char_p, c_bool, c_bool]
756
+ handle_buf = self.str_to_char_p(handle)
757
+ amlg_path_buf = self.str_to_char_p(amlg_path)
758
+
759
+ store_command_log_entry = (
760
+ f"STORE_ENTITY \"{handle}\" \"{amlg_path}\" {str(update_persistence_location).lower()} "
761
+ f"{str(store_contained).lower()}"
762
+ )
763
+ self._log_execution(store_command_log_entry)
764
+ self.amlg.StoreEntity(
765
+ handle_buf, amlg_path_buf, update_persistence_location, store_contained)
766
+ self._log_reply(None)
767
+
768
+ del handle_buf
769
+ del amlg_path_buf
770
+ self.gc()
771
+
772
+ def destroy_entity(
773
+ self,
774
+ handle: str
775
+ ) -> None:
776
+ """
777
+ Destroys an entity.
778
+
779
+ Parameters
780
+ ----------
781
+ handle : str
782
+ The handle of the amalgam entity.
783
+ """
784
+ self.amlg.DestroyEntity.argtype = [c_char_p]
785
+ handle_buf = self.str_to_char_p(handle)
786
+
787
+ self._log_execution(f"DESTROY_ENTITY \"{handle}\"")
788
+ self.amlg.DestroyEntity(handle_buf)
789
+ self._log_reply(None)
790
+
791
+ del handle_buf
792
+ self.gc()
793
+
647
794
  def get_entities(self) -> List[str]:
648
795
  """
649
796
  Get loaded top level entities.
@@ -658,9 +805,11 @@ class Amalgam:
658
805
  num_entities = c_uint64()
659
806
  entities = self.amlg.GetEntities(byref(num_entities))
660
807
  result = [entities[i].decode() for i in range(num_entities.value)]
808
+
661
809
  del entities
662
810
  del num_entities
663
811
  self.gc()
812
+
664
813
  return result
665
814
 
666
815
  def execute_entity_json(
@@ -692,15 +841,18 @@ class Amalgam:
692
841
  handle_buf = self.str_to_char_p(handle)
693
842
  label_buf = self.str_to_char_p(label)
694
843
  json_buf = self.str_to_char_p(json)
844
+
695
845
  self._log_time("EXECUTION START")
696
- self._log_execution(f"EXECUTE_ENTITY_JSON {handle} {label} {json}")
697
- result = self._copy_to_bytes(self.amlg.ExecuteEntityJsonPtr(
846
+ self._log_execution(f"EXECUTE_ENTITY_JSON \"{handle}\" \"{label}\" {json}")
847
+ result = self.char_p_to_bytes(self.amlg.ExecuteEntityJsonPtr(
698
848
  handle_buf, label_buf, json_buf))
699
849
  self._log_time("EXECUTION STOP")
700
850
  self._log_reply(result)
851
+
701
852
  del handle_buf
702
853
  del label_buf
703
854
  del json_buf
855
+
704
856
  return result
705
857
 
706
858
  def set_number_value(self, handle: str, label: str, value: float) -> None:
@@ -721,7 +873,9 @@ class Amalgam:
721
873
  handle_buf = self.str_to_char_p(handle)
722
874
  label_buf = self.str_to_char_p(label)
723
875
  val = c_double(value)
876
+
724
877
  self.amlg.SetNumberValue(handle_buf, label_buf, val)
878
+
725
879
  del handle_buf
726
880
  del label_buf
727
881
  del val
@@ -747,9 +901,12 @@ class Amalgam:
747
901
  self.amlg.GetNumberValue.argtype = [c_char_p, c_char_p]
748
902
  handle_buf = self.str_to_char_p(handle)
749
903
  label_buf = self.str_to_char_p(label)
904
+
750
905
  result = self.amlg.GetNumberValue(handle_buf, label_buf)
906
+
751
907
  del handle_buf
752
908
  del label_buf
909
+
753
910
  return result
754
911
 
755
912
  def set_string_value(
@@ -775,7 +932,9 @@ class Amalgam:
775
932
  handle_buf = self.str_to_char_p(handle)
776
933
  label_buf = self.str_to_char_p(label)
777
934
  val_buf = self.str_to_char_p(value)
935
+
778
936
  self.amlg.SetStringValue(handle_buf, label_buf, val_buf)
937
+
779
938
  del handle_buf
780
939
  del label_buf
781
940
  del val_buf
@@ -801,15 +960,18 @@ class Amalgam:
801
960
  self.amlg.GetStringListPtr.argtype = [c_char_p, c_char_p]
802
961
  handle_buf = self.str_to_char_p(handle)
803
962
  label_buf = self.str_to_char_p(label)
963
+
804
964
  size = self.amlg.GetStringListLength(handle_buf, label_buf)
805
965
  value_buf = self.amlg.GetStringListPtr(handle_buf, label_buf)
806
966
  result = None
807
967
  if value_buf is not None and size > 0:
808
968
  result = value_buf[0]
969
+
809
970
  del handle_buf
810
971
  del label_buf
811
972
  del value_buf
812
973
  self.gc()
974
+
813
975
  return result
814
976
 
815
977
  def set_string_list(
@@ -845,6 +1007,7 @@ class Amalgam:
845
1007
  handle_buf = self.str_to_char_p(handle)
846
1008
  label_buf = self.str_to_char_p(label)
847
1009
  self.amlg.SetStringList(handle_buf, label_buf, value_buf, size)
1010
+
848
1011
  del handle_buf
849
1012
  del label_buf
850
1013
  del value_buf
@@ -873,13 +1036,16 @@ class Amalgam:
873
1036
  self.amlg.GetStringListPtr.argtype = [c_char_p, c_char_p]
874
1037
  handle_buf = self.str_to_char_p(handle)
875
1038
  label_buf = self.str_to_char_p(label)
1039
+
876
1040
  size = self.amlg.GetStringListLength(handle_buf, label_buf)
877
1041
  value_buf = self.amlg.GetStringListPtr(handle_buf, label_buf)
878
1042
  value = [value_buf[i] for i in range(size)]
1043
+
879
1044
  del handle_buf
880
1045
  del label_buf
881
1046
  del value_buf
882
1047
  self.gc()
1048
+
883
1049
  return value
884
1050
 
885
1051
  def get_version_string(self) -> bytes:
@@ -892,7 +1058,7 @@ class Amalgam:
892
1058
  A version byte-encoded string with semver.
893
1059
  """
894
1060
  self.amlg.GetVersionString.restype = POINTER(c_char)
895
- amlg_version = self._copy_to_bytes(self.amlg.GetVersionString())
1061
+ amlg_version = self.char_p_to_bytes(self.amlg.GetVersionString())
896
1062
  self._log_comment(f"call to amlg.GetVersionString() - returned: "
897
1063
  f"{amlg_version}\n")
898
1064
  return amlg_version
@@ -908,7 +1074,7 @@ class Amalgam:
908
1074
  Ex. b'MultiThreaded'
909
1075
  """
910
1076
  self.amlg.GetConcurrencyTypeString.restype = POINTER(c_char)
911
- amlg_concurrency_type = self._copy_to_bytes(self.amlg.GetConcurrencyTypeString())
1077
+ amlg_concurrency_type = self.char_p_to_bytes(self.amlg.GetConcurrencyTypeString())
912
1078
  self._log_comment(
913
1079
  f"call to amlg.GetConcurrencyTypeString() - returned: "
914
1080
  f"{amlg_concurrency_type}\n")
amalgam/lib/version.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": {
3
- "amalgam": "47.2.0",
4
- "amalgam_sha": "d1968606d09241764f2e844a48688278d707c083",
5
- "amalgam_url": "https://github.com/howsoai/amalgam/releases/tag/47.2.0",
3
+ "amalgam": "48.0.1",
4
+ "amalgam_sha": "008194bd86d1f24388e232ff7e8e578933a31fec",
5
+ "amalgam_url": "https://github.com/howsoai/amalgam/releases/tag/48.0.1",
6
6
  "amalgam_build_date": "",
7
7
  "amalgam_display_title": ""
8
8
  }
Binary file
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: amalgam-lang
3
- Version: 6.2.0
3
+ Version: 7.0.1
4
4
  Summary: A direct interface with Amalgam compiled DLL or so.
5
5
  Author: Howso Incorporated
6
6
  Author-email: support@howso.com
@@ -0,0 +1,12 @@
1
+ amalgam/__init__.py,sha256=oHu7Zr4eGDUqj93pLwz8t7gLa8lpAx6Q-xbGiJ3nJx0,18
2
+ amalgam/api.py,sha256=8DnZnEa9_qYg-zCz6_myus516bgpTwZHMhG5BFiyuBA,36170
3
+ amalgam/lib/version.json,sha256=YrX16Djp-07dXr0CJtXvMBbjTO3fhVuOsacQh16mtc8,250
4
+ amalgam/lib/windows/amd64/amalgam-mt-noavx.dll,sha256=l9__7Kc2tV1vFX0MmqhPTwK59dNCgKdFv8qZcg6YKOs,2550272
5
+ amalgam/lib/windows/amd64/amalgam-mt.dll,sha256=BftlGBVZzlXoDcV9XQLDou7GAxUhezMfpt0S6o0Dipo,2494976
6
+ amalgam/lib/windows/amd64/amalgam-omp.dll,sha256=2DDByhAy0Zp-8BJf8n-eqD-PneQNf4kM1O50-sI4voM,2406400
7
+ amalgam/lib/windows/amd64/amalgam-st.dll,sha256=8ocsn3Ljyhj63yZqt51aeL15RheEFDNF6vo8wNwCSTI,2406400
8
+ amalgam_lang-7.0.1.dist-info/LICENSE.txt,sha256=2xqHuoHohba7gpcZZKtOICRjzeKsQANXG8WoV9V35KM,33893
9
+ amalgam_lang-7.0.1.dist-info/METADATA,sha256=l-dUJWd_i1JmcngEhCCZKJwZDEbsDk-rCQIzVroywxg,43351
10
+ amalgam_lang-7.0.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
11
+ amalgam_lang-7.0.1.dist-info/top_level.txt,sha256=rmPHU144SyaB25u5-FAQyECAQnJ39NvuJEcKXMRcdBo,8
12
+ amalgam_lang-7.0.1.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- amalgam/__init__.py,sha256=oHu7Zr4eGDUqj93pLwz8t7gLa8lpAx6Q-xbGiJ3nJx0,18
2
- amalgam/api.py,sha256=VtmOoM4WONON-i0Xduvju8EWsmZxdNzRhU0h7_RVTps,32013
3
- amalgam/lib/version.json,sha256=fEXN-hxsd7Bd844ljlnA1UuwTrssX8BQvElf0FaZWis,250
4
- amalgam/lib/windows/amd64/amalgam-mt-noavx.dll,sha256=qyraGJnczoBrCsGREcM1eo4t6T2a_osyx9NTejxhOyk,2524160
5
- amalgam/lib/windows/amd64/amalgam-mt.dll,sha256=V-dzeBX4TjIIjFAo3hx90Nt8A5EWfAaJCVGfnrOjpZU,2466304
6
- amalgam/lib/windows/amd64/amalgam-omp.dll,sha256=zgBpH0amK2Rz6P29q0UaoWPHKwYZrx6t85e4b8xonPg,2381824
7
- amalgam/lib/windows/amd64/amalgam-st.dll,sha256=joxEEQrsW_CssuHAKK1_9v4nRXsS4mS-j8VmTD0F2QU,2380800
8
- amalgam_lang-6.2.0.dist-info/LICENSE.txt,sha256=2xqHuoHohba7gpcZZKtOICRjzeKsQANXG8WoV9V35KM,33893
9
- amalgam_lang-6.2.0.dist-info/METADATA,sha256=XIZcrGaYYZ-m2lPL1ZNF2GIg8TemPPPOzZEfkdDF7-8,43351
10
- amalgam_lang-6.2.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
11
- amalgam_lang-6.2.0.dist-info/top_level.txt,sha256=rmPHU144SyaB25u5-FAQyECAQnJ39NvuJEcKXMRcdBo,8
12
- amalgam_lang-6.2.0.dist-info/RECORD,,