amalgam-lang 24.0.1__py3-none-macosx_12_0_x86_64.whl → 24.1.0__py3-none-macosx_12_0_x86_64.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,8 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from base64 import b64encode
3
4
  from ctypes import (
4
5
  _Pointer, Array, byref, c_bool, c_char, c_char_p, c_size_t, c_uint64, c_void_p,
5
- cast, cdll, POINTER, Structure
6
+ cast, cdll, POINTER, Structure, string_at
6
7
  )
7
8
  from datetime import datetime
8
9
  import gc
@@ -28,7 +29,9 @@ class _LoadEntityStatus(Structure):
28
29
  _fields_ = [
29
30
  ("loaded", c_bool),
30
31
  ("message", POINTER(c_char)),
31
- ("version", POINTER(c_char))
32
+ ("version", POINTER(c_char)),
33
+ ("entity_path", POINTER(POINTER(c_char))),
34
+ ("entity_path_len", c_size_t)
32
35
  ]
33
36
 
34
37
 
@@ -53,10 +56,14 @@ class LoadEntityStatus:
53
56
  self.loaded = True
54
57
  self.message = ""
55
58
  self.version = ""
59
+ self.entity_path = []
56
60
  else:
57
61
  self.loaded = bool(c_status.loaded)
58
62
  self.message = api.char_p_to_str(c_status.message)
59
63
  self.version = api.char_p_to_str(c_status.version)
64
+ self.entity_path = [api.char_p_to_str(c_status.entity_path[i]) for i in range(c_status.entity_path_len)]
65
+ api.amlg.DeleteString(cast(c_status.entity_path, c_char_p))
66
+
60
67
 
61
68
  def __str__(self) -> str:
62
69
  """
@@ -67,7 +74,11 @@ class LoadEntityStatus:
67
74
  str
68
75
  The human-readable string representation.
69
76
  """
70
- return f"{self.loaded},\"{self.message}\",\"{self.version}\""
77
+ ep = ""
78
+ if self.entity_path:
79
+ eps = (f'"{step}"' for step in self.entity_path)
80
+ ep = f",[{','.join(eps)}]"
81
+ return f"{self.loaded},\"{self.message}\",\"{self.version}\"{ep}"
71
82
 
72
83
 
73
84
  class _ResultWithLog(Structure):
@@ -803,7 +814,8 @@ class Amalgam:
803
814
  persist: bool = False,
804
815
  json_file_params: str = "",
805
816
  write_log: str = "",
806
- print_log: str = ""
817
+ print_log: str = "",
818
+ entity_path: list[str] | None = None,
807
819
  ) -> LoadEntityStatus:
808
820
  """
809
821
  Load an entity from an amalgam source file.
@@ -829,6 +841,9 @@ class Amalgam:
829
841
  print_log : str, default ""
830
842
  Path to the print log. If empty string, the print log is
831
843
  not generated.
844
+ entity_path: list[str], optional
845
+ If provided and non-empty, load the content into an entity
846
+ contained within `handle` at this path.
832
847
 
833
848
  Returns
834
849
  -------
@@ -836,7 +851,8 @@ class Amalgam:
836
851
  Status of LoadEntity call.
837
852
  """
838
853
  self.amlg.LoadEntity.argtypes = [
839
- c_char_p, c_char_p, c_char_p, c_bool, c_char_p, c_char_p, c_char_p]
854
+ c_char_p, c_char_p, c_char_p, c_bool, c_char_p, c_char_p, c_char_p, POINTER(c_char_p),
855
+ c_size_t]
840
856
  self.amlg.LoadEntity.restype = _LoadEntityStatus
841
857
  handle_buf = self.str_to_char_p(handle)
842
858
  file_path_buf = self.str_to_char_p(file_path)
@@ -844,18 +860,26 @@ class Amalgam:
844
860
  json_file_params_buf = self.str_to_char_p(json_file_params)
845
861
  write_log_buf = self.str_to_char_p(write_log)
846
862
  print_log_buf = self.str_to_char_p(print_log)
863
+ entity_path_p = None
864
+ entity_path_len = 0
865
+
866
+ if entity_path is not None and len(entity_path) > 0:
867
+ entity_path_len = len(entity_path)
868
+ entity_path_p = (c_char_p * entity_path_len)()
869
+ for i, entry in enumerate(entity_path):
870
+ entity_path_p[i] = cast(self.str_to_char_p(entry), c_char_p)
847
871
 
848
872
  self.load_command_log_entry = (
849
873
  f"LOAD_ENTITY \"{self.escape_double_quotes(handle)}\" "
850
874
  f"\"{self.escape_double_quotes(file_path)}\" "
851
875
  f"\"{self.escape_double_quotes(file_type)}\" {str(persist).lower()} "
852
876
  f"{json_lib.dumps(json_file_params)} "
853
- f"\"{write_log}\" \"{print_log}\""
877
+ f"\"{write_log}\" \"{print_log}\" \"\" \"{' '.join(entity_path or [])}\""
854
878
  ).encode()
855
879
  self._log_execution(self.load_command_log_entry)
856
880
  result = LoadEntityStatus(self, self.amlg.LoadEntity(
857
881
  handle_buf, file_path_buf, file_type_buf, persist,
858
- json_file_params_buf, write_log_buf, print_log_buf))
882
+ json_file_params_buf, write_log_buf, print_log_buf, entity_path_p, entity_path_len))
859
883
  self._log_reply(result)
860
884
 
861
885
  del handle_buf
@@ -864,6 +888,98 @@ class Amalgam:
864
888
  del json_file_params_buf
865
889
  del write_log_buf
866
890
  del print_log_buf
891
+ if entity_path_p is not None:
892
+ for i in range(entity_path_len):
893
+ entry_buf = entity_path_p[i]
894
+ del entry_buf
895
+ del entity_path_p
896
+ self.gc()
897
+
898
+ return result
899
+
900
+ def load_entity_from_memory(
901
+ self,
902
+ handle: str,
903
+ contents: bytes,
904
+ *,
905
+ file_type: str,
906
+ json_file_params: str = "",
907
+ write_log: str = "",
908
+ print_log: str = "",
909
+ entity_path: list[str] | None = None,
910
+ ) -> LoadEntityStatus:
911
+ """
912
+ Load an entity from an in-memory buffer.
913
+
914
+ Parameters
915
+ ----------
916
+ handle : str
917
+ The handle to assign the entity.
918
+ contents : bytes
919
+ The content to load.
920
+ file_type : str
921
+ The type of file to store, typically ``"amlg"`` for plain-text Amalgam or ``"caml"``
922
+ for binary compressed Amalgam.
923
+ json_file_params : str, default ""
924
+ Either empty string or a string of json specifying a set of key-value pairs
925
+ which are parameters specific to the file type. See Amalgam documentation
926
+ for details of allowed parameters.
927
+ write_log : str, default ""
928
+ Path to the write log. If empty string, the write log is
929
+ not generated.
930
+ print_log : str, default ""
931
+ Path to the print log. If empty string, the print log is
932
+ not generated.
933
+ entity_path: list[str], optional
934
+ If provided and non-empty, load the content into an entity
935
+ contained within `handle` at this path.
936
+
937
+ Returns
938
+ -------
939
+ LoadEntityStatus
940
+ Status of LoadEntity call.
941
+ """
942
+ self.amlg.LoadEntityFromMemory.argtypes = [
943
+ c_char_p, c_void_p, c_size_t, c_char_p, c_bool, c_char_p, c_char_p, c_char_p, POINTER(c_char_p),
944
+ c_size_t]
945
+ self.amlg.LoadEntityFromMemory.restype = _LoadEntityStatus
946
+ handle_buf = self.str_to_char_p(handle)
947
+ file_type_buf = self.str_to_char_p(file_type)
948
+ json_file_params_buf = self.str_to_char_p(json_file_params)
949
+ write_log_buf = self.str_to_char_p(write_log)
950
+ print_log_buf = self.str_to_char_p(print_log)
951
+ entity_path_p = None
952
+ entity_path_len = 0
953
+
954
+ if entity_path is not None and len(entity_path) > 0:
955
+ entity_path_len = len(entity_path)
956
+ entity_path_p = (c_char_p * entity_path_len)()
957
+ for i, entry in enumerate(entity_path):
958
+ entity_path_p[i] = cast(self.str_to_char_p(entry), c_char_p)
959
+
960
+ self.load_command_log_entry = (
961
+ f"LOAD_ENTITY_FROM_MEMORY \"{self.escape_double_quotes(handle)}\" "
962
+ f"\"{b64encode(contents).decode()}\" "
963
+ f"\"{self.escape_double_quotes(file_type)}\" false "
964
+ f"{json_lib.dumps(json_file_params)} "
965
+ f"\"{write_log}\" \"{print_log}\" \"\" \"{' '.join(entity_path or [])}\""
966
+ ).encode()
967
+ self._log_execution(self.load_command_log_entry)
968
+ result = LoadEntityStatus(self, self.amlg.LoadEntityFromMemory(
969
+ handle_buf, contents, len(contents), file_type_buf, False,
970
+ json_file_params_buf, write_log_buf, print_log_buf, entity_path_p, entity_path_len))
971
+ self._log_reply(result)
972
+
973
+ del handle_buf
974
+ del file_type_buf
975
+ del json_file_params_buf
976
+ del write_log_buf
977
+ del print_log_buf
978
+ if entity_path_p is not None:
979
+ for i in range(entity_path_len):
980
+ entry_buf = entity_path_p[i]
981
+ del entry_buf
982
+ del entity_path_p
867
983
  self.gc()
868
984
 
869
985
  return result
@@ -1050,6 +1166,7 @@ class Amalgam:
1050
1166
  file_type: str = "",
1051
1167
  persist: bool = False,
1052
1168
  json_file_params: str = "",
1169
+ entity_path: list[str] | None = None,
1053
1170
  ):
1054
1171
  """
1055
1172
  Store entity to the file type specified within file_path.
@@ -1069,26 +1186,116 @@ class Amalgam:
1069
1186
  Either empty string or a string of json specifying a set of key-value pairs
1070
1187
  which are parameters specific to the file type. See Amalgam documentation
1071
1188
  for details of allowed parameters.
1189
+ entity_path: list[str], optional
1190
+ If provided and non-empty, store the content from an entity
1191
+ contained within `handle` at this path.
1072
1192
  """
1073
1193
  self.amlg.StoreEntity.argtypes = [
1074
- c_char_p, c_char_p, c_char_p, c_bool, c_char_p]
1194
+ c_char_p, c_char_p, c_char_p, c_bool, c_char_p, POINTER(c_char_p), c_size_t]
1195
+ self.amlg.StoreEntity.restype = None
1075
1196
  handle_buf = self.str_to_char_p(handle)
1076
1197
  file_path_buf = self.str_to_char_p(file_path)
1077
1198
  file_type_buf = self.str_to_char_p(file_type)
1078
1199
  json_file_params_buf = self.str_to_char_p(json_file_params)
1200
+ entity_path_p = None
1201
+ entity_path_len = 0
1202
+
1203
+ if entity_path is not None and len(entity_path) > 0:
1204
+ entity_path_len = len(entity_path)
1205
+ entity_path_p = (c_char_p * entity_path_len)()
1206
+ for i, entry in enumerate(entity_path):
1207
+ entity_path_p[i] = self.str_to_char_p(entry)
1079
1208
 
1080
1209
  self._log_execution_std(b"STORE_ENTITY", handle, file_path, file_type,
1081
- suffix=f"{str(persist).lower()} {json_lib.dumps(json_file_params)}")
1210
+ suffix=f"{str(persist).lower()} {json_lib.dumps(json_file_params)} \"{' '.join(entity_path or [])}\"")
1082
1211
  self.amlg.StoreEntity(
1083
- handle_buf, file_path_buf, file_type_buf, persist, json_file_params_buf)
1212
+ handle_buf, file_path_buf, file_type_buf, persist, json_file_params_buf, entity_path_p, entity_path_len)
1084
1213
  self._log_reply(None)
1085
1214
 
1086
1215
  del handle_buf
1087
1216
  del file_path_buf
1088
1217
  del file_type_buf
1089
1218
  del json_file_params_buf
1219
+ if entity_path_p is not None:
1220
+ for i in range(entity_path_len):
1221
+ entry_buf = entity_path_p[i]
1222
+ del entry_buf
1223
+ del entity_path_p
1090
1224
  self.gc()
1091
1225
 
1226
+ def store_entity_to_memory(
1227
+ self,
1228
+ handle: str,
1229
+ *,
1230
+ file_type: str,
1231
+ json_file_params: str = "",
1232
+ entity_path: list[str] | None = None,
1233
+ ) -> bytes | None:
1234
+ """
1235
+ Store entity to memory as a bytes object.
1236
+
1237
+ Parameters
1238
+ ----------
1239
+ handle : str
1240
+ The handle of the amalgam entity.
1241
+ file_type : str
1242
+ The type of file to store, typically ``"amlg"`` for plain-text Amalgam or ``"caml"``
1243
+ for binary compressed Amalgam.
1244
+ json_file_params : str, default ""
1245
+ Either empty string or a string of json specifying a set of key-value pairs
1246
+ which are parameters specific to the file type. See Amalgam documentation
1247
+ for details of allowed parameters.
1248
+ entity_path: list[str], optional
1249
+ If provided and non-empty, store the content from an entity
1250
+ contained within `handle` at this path.
1251
+
1252
+ Returns
1253
+ -------
1254
+ bytes | None
1255
+ The serialized entity contents, or None on an error.
1256
+ """
1257
+ self.amlg.StoreEntityToMemory.argtypes = [
1258
+ c_char_p, POINTER(c_void_p), POINTER(c_size_t), c_char_p, c_bool, c_char_p, POINTER(c_char_p), c_size_t]
1259
+ self.amlg.StoreEntityToMemory.restype = None
1260
+ handle_buf = self.str_to_char_p(handle)
1261
+ data_p = c_void_p(None)
1262
+ data_len = c_size_t(0)
1263
+ file_type_buf = self.str_to_char_p(file_type)
1264
+ json_file_params_buf = self.str_to_char_p(json_file_params)
1265
+ entity_path_p = None
1266
+ entity_path_len = 0
1267
+
1268
+ if entity_path is not None and len(entity_path) > 0:
1269
+ entity_path_len = len(entity_path)
1270
+ entity_path_p = (c_char_p * entity_path_len)()
1271
+ for i, entry in enumerate(entity_path):
1272
+ entity_path_p[i] = self.str_to_char_p(entry)
1273
+
1274
+ self._log_execution(f"STORE_ENTITY_TO_MEMORY \"{self.escape_double_quotes(handle)}\" false {json_lib.dumps(json_file_params)} \"{' '.join(entity_path or [])}\"".encode())
1275
+ self.amlg.StoreEntityToMemory(
1276
+ handle_buf, byref(data_p), byref(data_len), file_type_buf, False, json_file_params_buf, entity_path_p, entity_path_len)
1277
+
1278
+ result = None
1279
+ if data_p.value is not None:
1280
+ result = string_at(data_p.value, data_len.value)
1281
+ self.amlg.DeleteString.argtypes = [c_char_p]
1282
+ self.amlg.DeleteString.restype = None
1283
+ self.amlg.DeleteString(cast(data_p, c_char_p))
1284
+ self._log_reply(b64encode(result).decode())
1285
+ else:
1286
+ self._log_reply(None)
1287
+
1288
+ del handle_buf
1289
+ del file_type_buf
1290
+ del json_file_params_buf
1291
+ if entity_path_p is not None:
1292
+ for i in range(entity_path_len):
1293
+ entry_buf = entity_path_p[i]
1294
+ del entry_buf
1295
+ del entity_path_p
1296
+ self.gc()
1297
+ return result
1298
+
1092
1299
  def destroy_entity(
1093
1300
  self,
1094
1301
  handle: str
Binary file
Binary file
Binary file
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "67.0.1"
2
+ "version": "68.0.0"
3
3
  }
amalgam/lib/version.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": {
3
- "amalgam": "67.0.1",
4
- "amalgam_sha": "8dedc013d760a8813f545b8930361083e84306be",
5
- "amalgam_url": "https://github.com/howsoai/amalgam/releases/tag/67.0.1",
3
+ "amalgam": "68.0.0",
4
+ "amalgam_sha": "981603e172380117d4c295b5039fc72e2419ec01",
5
+ "amalgam_url": "https://github.com/howsoai/amalgam/releases/tag/68.0.0",
6
6
  "amalgam_build_date": "",
7
7
  "amalgam_display_title": ""
8
8
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amalgam-lang
3
- Version: 24.0.1
3
+ Version: 24.1.0
4
4
  Summary: A direct interface with Amalgam compiled DLL, dylib, or so.
5
5
  Author: Howso Incorporated
6
6
  Author-email: support@howso.com
@@ -0,0 +1,13 @@
1
+ amalgam/__init__.py,sha256=oHu7Zr4eGDUqj93pLwz8t7gLa8lpAx6Q-xbGiJ3nJx0,18
2
+ amalgam/api.py,sha256=wD6vpApSFDmRgGl7u52tMXcEOc1I7ahP_AAT0i6YhQQ,53611
3
+ amalgam/lib/version.json,sha256=T9Kn3ovwZkQ9-kCj6bL5Fyx6vFp_h4eH_DNym2Urk7w,250
4
+ amalgam/lib/darwin/amd64/amalgam-mt-noavx.dylib,sha256=V6zkiRvwstZT26sc74hKMuJe2bhO0cE7W6j8H5NVVJ0,3856088
5
+ amalgam/lib/darwin/amd64/amalgam-mt.dylib,sha256=mWY0Bu9ndUgcgxdqoOXBus9HqaHe6TTIuRv2xpIZdJ8,4194424
6
+ amalgam/lib/darwin/amd64/amalgam-omp.dylib,sha256=qTIP7flGCwsoUYsRmDj4YTI-t6tK9m5E-tv_OgOA0EU,4476808
7
+ amalgam/lib/darwin/amd64/amalgam-st.dylib,sha256=zmufK4IklBskUpqira_YbWrX_G7fS43frdf-Y-a1fH4,3954024
8
+ amalgam/lib/darwin/amd64/docs/version.json,sha256=PGtpq_u6AFT_qdTtTKktxRn-1falnEbIk170uCHkIQ4,25
9
+ amalgam_lang-24.1.0.dist-info/licenses/LICENSE.txt,sha256=2xqHuoHohba7gpcZZKtOICRjzeKsQANXG8WoV9V35KM,33893
10
+ amalgam_lang-24.1.0.dist-info/METADATA,sha256=OPjfzYYeLhEqHqjl3xtVD8m323IDNGLI0Y4iEQ2ORWc,43832
11
+ amalgam_lang-24.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ amalgam_lang-24.1.0.dist-info/top_level.txt,sha256=rmPHU144SyaB25u5-FAQyECAQnJ39NvuJEcKXMRcdBo,8
13
+ amalgam_lang-24.1.0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- amalgam/__init__.py,sha256=oHu7Zr4eGDUqj93pLwz8t7gLa8lpAx6Q-xbGiJ3nJx0,18
2
- amalgam/api.py,sha256=ij3-PEP0iU-XdBMbyB-3f3h-mWH_y0P-B29BZRSkvK8,44966
3
- amalgam/lib/version.json,sha256=R5qkGgwZzBsjFDpHtz_mEjGP_pqShnG2nNUQsGtqcSs,250
4
- amalgam/lib/darwin/amd64/amalgam-mt-noavx.dylib,sha256=PixtKGMp-9geHGaI_zPleiWPk6a3nksDdNihABnF3ck,3621448
5
- amalgam/lib/darwin/amd64/amalgam-mt.dylib,sha256=iqJZUCr_iDvnqFxanU6UaLLcF3LZisWRKaYb_hXuHfg,3943400
6
- amalgam/lib/darwin/amd64/amalgam-omp.dylib,sha256=Y_ne33cVB0RsLpzZ4_3a3mJ4rXSaqZ9-rU3go6RtqaM,4249048
7
- amalgam/lib/darwin/amd64/amalgam-st.dylib,sha256=DWuYTb5VM_IG2QhAR-7M-vpIH0gT3n-xC_-Dr43W_4Q,3728240
8
- amalgam/lib/darwin/amd64/docs/version.json,sha256=vlK2MPZlC-krqSSSEAxuhHvGddMPbYK6wY5L5F_coEI,25
9
- amalgam_lang-24.0.1.dist-info/licenses/LICENSE.txt,sha256=2xqHuoHohba7gpcZZKtOICRjzeKsQANXG8WoV9V35KM,33893
10
- amalgam_lang-24.0.1.dist-info/METADATA,sha256=kINZujZyAcoqjCNEOXWp1Nw4fF-OveuVviNX2MLJ2RI,43832
11
- amalgam_lang-24.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- amalgam_lang-24.0.1.dist-info/top_level.txt,sha256=rmPHU144SyaB25u5-FAQyECAQnJ39NvuJEcKXMRcdBo,8
13
- amalgam_lang-24.0.1.dist-info/RECORD,,