streamlit-octostar-utils 0.4.2.dev2__tar.gz → 0.4.2.dev4__tar.gz

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.
Files changed (45) hide show
  1. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/PKG-INFO +1 -1
  2. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/pyproject.toml +1 -1
  3. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/nifi.py +138 -79
  4. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/LICENSE +0 -0
  5. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/README.md +0 -0
  6. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/__init__.py +0 -0
  7. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/__init__.py +0 -0
  8. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/celery.py +0 -0
  9. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/contents.py +0 -0
  10. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/fastapi.py +0 -0
  11. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parallelism.py +0 -0
  12. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/__init__.py +0 -0
  13. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/combine_fields.py +0 -0
  14. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/entities_parser.py +0 -0
  15. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/generics.py +0 -0
  16. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/info.py +0 -0
  17. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/linkchart_functions.py +0 -0
  18. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/matches.py +0 -0
  19. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/parameters.py +0 -0
  20. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/rules.py +0 -0
  21. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/api_crafter/parser/signals.py +0 -0
  22. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/__init__.py +0 -0
  23. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/dict.py +0 -0
  24. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/filetypes.py +0 -0
  25. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/threading/__init__.py +0 -0
  26. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/threading/key_queue.py +0 -0
  27. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/core/timestamp.py +0 -0
  28. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/nlp/__init__.py +0 -0
  29. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/nlp/custom_recognizers.py +0 -0
  30. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/nlp/language.py +0 -0
  31. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/nlp/ner.py +0 -0
  32. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/octostar/__init__.py +0 -0
  33. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/octostar/client.py +0 -0
  34. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/octostar/context.py +0 -0
  35. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/octostar/permissions.py +0 -0
  36. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/ontology/__init__.py +0 -0
  37. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/ontology/inheritance.py +0 -0
  38. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/ontology/relationships.py +0 -0
  39. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/ontology/validation.py +0 -0
  40. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/style/__init__.py +0 -0
  41. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/style/common.py +0 -0
  42. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/threading/__init__.py +0 -0
  43. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/threading/async_task_manager.py +0 -0
  44. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/threading/session_callback_manager.py +0 -0
  45. {streamlit_octostar_utils-0.4.2.dev2 → streamlit_octostar_utils-0.4.2.dev4}/streamlit_octostar_utils/threading/session_state_hot_swapper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streamlit-octostar-utils
3
- Version: 0.4.2.dev2
3
+ Version: 0.4.2.dev4
4
4
  Summary:
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -5,7 +5,7 @@ include = '\.pyi?$'
5
5
 
6
6
  [tool.poetry]
7
7
  name = "streamlit-octostar-utils"
8
- version = "0.4.2-dev.2"
8
+ version = "0.4.2-dev.4"
9
9
  description = ""
10
10
  license = "MIT"
11
11
  authors = ["Octostar"]
@@ -5,18 +5,16 @@ from contextlib import contextmanager
5
5
  import json
6
6
  import jwt
7
7
  from typing import List, Union, Optional, Callable
8
- import base64
9
8
  from pydantic import BaseModel, ConfigDict, Field
10
9
  import itertools
11
- import asyncio
12
10
  from enum import Enum
13
- from typing import Dict, Any
11
+ from typing import Dict, Any, Literal
14
12
  from datetime import datetime, timezone, timedelta
15
13
  from fastapi import Request
16
14
  from fastapi.responses import JSONResponse
17
15
  from starlette.exceptions import HTTPException as StarletteHTTPException
18
16
 
19
- from octostar.utils.workspace import read_file, upsert_entities, write_file
17
+ from octostar.utils.workspace import upsert_entities, write_file
20
18
  from octostar.utils.ontology import fetch_ontology_data
21
19
  from octostar.utils.workspace.permissions import get_permissions, PermissionLevel
22
20
  from octostar.client import make_client
@@ -26,26 +24,25 @@ from ..core.dict import recursive_update_dict, travel_dict, jsondict_hash
26
24
  from ..core.timestamp import now, string_to_datetime
27
25
  from .fastapi import DefaultErrorRoute, Route
28
26
  from ..ontology.inheritance import is_child_concept as is_child_concept_fn, get_label_keys
29
- from .contents import Contents, MemoryContents, WorkspaceAttachmentContents, TemporaryAttachmentContents, ContentsLocation
27
+ from .contents import Contents, WorkspaceAttachmentContents, TemporaryAttachmentContents, ContentsLocation
28
+
29
+
30
+ class RelationshipName(BaseModel):
31
+ name: str
32
+ type: Literal["mtm", "otm"]
33
+
30
34
 
31
35
  RELATIONSHIP_ENTITY_NAME = "os_relationship"
32
36
  LOCAL_RELATIONSHIP_ENTITY_NAME = "os_workspace_relationship"
33
37
  FILE_ENTITY_NAME = "os_file"
34
- GENERIC_RELATIONSHIP_NAME = "related_to"
35
- FILE_RELATIONSHIP_NAME = "generator_of"
36
- TAG_RELATIONSHIP_NAME = "has_tag"
37
38
  TAG_ENTITY_NAME = "os_tag"
38
-
39
-
40
- def safe_async_run(coro):
41
- try:
42
- loop = asyncio.get_event_loop()
43
- if loop.is_running():
44
- return asyncio.ensure_future(coro)
45
- else:
46
- return asyncio.run(coro)
47
- except RuntimeError:
48
- return asyncio.run(coro)
39
+ FRAGMENT_ENTITY_NAME = "os_fragment"
40
+ GENERIC_RELATIONSHIP = RelationshipName(name="related_to", type="mtm")
41
+ FILE_RELATIONSHIP = RelationshipName(name="generator_of", type="mtm")
42
+ TAG_RELATIONSHIP = RelationshipName(name="has_tag", type="mtm")
43
+ FRAGMENT_RELATIONSHIP = RelationshipName(name="is_fragment_of", type="otm")
44
+ PREVIOUS_FRAGMENT_RELATIONSHIP = RelationshipName(name="has_previous_fragment", type="otm")
45
+ NEXT_FRAGMENT_RELATIONSHIP = RelationshipName(name="has_next_fragment", type="otm")
49
46
 
50
47
 
51
48
  class NifiProxyEntityModel(BaseModel):
@@ -397,10 +394,6 @@ class NifiContextManager(object):
397
394
 
398
395
  @contextmanager
399
396
  def reindex_lock(self, entities: List[Union[dict, "NifiEntity"]], timeout: int = 7200):
400
- """Lock entities to prevent reindexing during processing.
401
-
402
- Sets do_not_reindex_at to a future time on entry, resets on exit.
403
- """
404
397
  if not entities:
405
398
  yield
406
399
  return
@@ -579,8 +572,7 @@ class NifiContextManager(object):
579
572
  target["os_workspace"],
580
573
  target["os_concept"],
581
574
  target,
582
- os_relationship_name=rel["os_relationship_name"],
583
- os_relationship_type=rel_type,
575
+ relationship=RelationshipName(name=rel["os_relationship_name"], type=rel_type),
584
576
  )
585
577
  child_entity.record = {**child_entity.record, **target}
586
578
  child_entity.record["entity_id"] = child_entity.record[
@@ -961,6 +953,47 @@ class NifiEntity(object):
961
953
  self.children.append(child_entity_proxy)
962
954
  return child_entity_proxy
963
955
 
956
+ def _add_child_attachable(
957
+ self,
958
+ os_workspace,
959
+ filename,
960
+ filetype,
961
+ file: Union[Contents, bytes],
962
+ fields={},
963
+ relationship: RelationshipName = FILE_RELATIONSHIP,
964
+ os_entity_uid=None,
965
+ os_relationship_uid=None,
966
+ os_entity_type=FILE_ENTITY_NAME,
967
+ ):
968
+ child_entity, child_rel = self.add_child_entity(
969
+ os_workspace,
970
+ os_entity_type,
971
+ {
972
+ **fields,
973
+ "os_item_name": filename,
974
+ "os_item_content_type": filetype,
975
+ "os_has_attachment": True,
976
+ },
977
+ relationship,
978
+ os_entity_uid,
979
+ os_relationship_uid,
980
+ )
981
+ if isinstance(file, Contents):
982
+ child_entity._contents = file
983
+ else:
984
+ temp_filename = f"tmp_{child_entity.record['os_entity_uid']}"
985
+ temp_contents = TemporaryAttachmentContents(
986
+ entity_type=os_entity_type,
987
+ filetype=filetype,
988
+ filename=temp_filename,
989
+ client=self.context.client,
990
+ initial_data=file,
991
+ )
992
+ temp_contents.flush()
993
+ child_entity._contents = temp_contents
994
+ child_entity.request["contents_pointer"] = child_entity._contents.to_locator()
995
+ return child_entity, child_rel
996
+
964
997
  def add_mtm_relationship(
965
998
  self,
966
999
  os_entity_uid_from,
@@ -974,7 +1007,7 @@ class NifiEntity(object):
974
1007
  ):
975
1008
  return self._add_entity(
976
1009
  os_relationship_workspace,
977
- (LOCAL_RELATIONSHIP_ENTITY_NAME if os_relationship_workspace else RELATIONSHIP_ENTITY_NAME),
1010
+ LOCAL_RELATIONSHIP_ENTITY_NAME,
978
1011
  {
979
1012
  **relationship_fields,
980
1013
  "os_entity_uid_from": os_entity_uid_from,
@@ -1009,33 +1042,22 @@ class NifiEntity(object):
1009
1042
  os_workspace,
1010
1043
  entity_type,
1011
1044
  fields,
1012
- os_relationship_name=GENERIC_RELATIONSHIP_NAME,
1013
- os_relationship_type="mtm",
1045
+ relationship: RelationshipName = GENERIC_RELATIONSHIP,
1014
1046
  os_entity_uid=None,
1015
1047
  os_relationship_uid=None,
1048
+ relationship_fields={},
1016
1049
  ):
1017
1050
  child_entity = self._add_entity(os_workspace, entity_type, fields, os_entity_uid)
1018
- if os_relationship_type == "mtm":
1019
- child_rel = self.add_mtm_relationship(
1020
- self.record["os_entity_uid"],
1021
- self.record["os_concept"],
1022
- child_entity.record["os_entity_uid"],
1023
- child_entity.record["os_concept"],
1024
- os_relationship_name,
1025
- os_workspace,
1026
- {},
1027
- os_relationship_uid,
1028
- )
1029
- elif os_relationship_type == "otm":
1030
- child_rel = self.add_otm_relationship(
1031
- self.record["os_entity_uid"],
1032
- self.record["os_concept"],
1033
- child_entity.record["os_entity_uid"],
1034
- child_entity.record["os_concept"],
1035
- os_relationship_name,
1036
- )
1037
- else:
1038
- raise ValueError(f"os_relationship_type is invalid! {os_relationship_type}")
1051
+ child_rel = self._add_relationship(
1052
+ os_workspace,
1053
+ self.record["os_entity_uid"],
1054
+ self.record["os_concept"],
1055
+ child_entity.record["os_entity_uid"],
1056
+ child_entity.record["os_concept"],
1057
+ relationship,
1058
+ relationship_fields,
1059
+ os_relationship_uid,
1060
+ )
1039
1061
  return child_entity, child_rel
1040
1062
 
1041
1063
  def add_child_file(
@@ -1046,49 +1068,86 @@ class NifiEntity(object):
1046
1068
  filetype,
1047
1069
  file: Union[Contents, bytes],
1048
1070
  fields={},
1049
- os_relationship_name=FILE_RELATIONSHIP_NAME,
1050
- os_relationship_type="mtm",
1071
+ relationship: RelationshipName = FILE_RELATIONSHIP,
1051
1072
  os_entity_uid=None,
1052
1073
  os_relationship_uid=None,
1074
+ os_entity_type=FILE_ENTITY_NAME,
1053
1075
  ):
1054
- child_entity, child_rel = self.add_child_entity(
1076
+ return self._add_child_attachable(
1055
1077
  os_workspace,
1056
- FILE_ENTITY_NAME,
1057
- {
1058
- **fields,
1059
- "os_item_name": filename,
1060
- "os_item_content_type": filetype,
1061
- "os_has_attachment": True,
1062
- "os_parent_folder": os_parent_folder,
1063
- },
1064
- os_relationship_name,
1065
- os_relationship_type,
1078
+ filename,
1079
+ filetype,
1080
+ file,
1081
+ {**fields, "os_parent_folder": os_parent_folder},
1082
+ relationship,
1066
1083
  os_entity_uid,
1067
1084
  os_relationship_uid,
1085
+ os_entity_type
1068
1086
  )
1069
- if isinstance(file, Contents):
1070
- child_entity._contents = file
1087
+
1088
+ def _add_relationship(self, os_workspace, from_uid, from_type, to_uid, to_type, rel, relationship_fields={}, rel_uid=None):
1089
+ if rel.type == "mtm":
1090
+ return self.add_mtm_relationship(from_uid, from_type, to_uid, to_type, rel.name, os_workspace, relationship_fields, rel_uid)
1091
+ elif rel.type == "otm":
1092
+ return self.add_otm_relationship(from_uid, from_type, to_uid, to_type, rel.name)
1071
1093
  else:
1072
- temp_filename = f"tmp_{child_entity.record['os_entity_uid']}"
1073
- temp_contents = TemporaryAttachmentContents(
1074
- entity_type=FILE_ENTITY_NAME,
1075
- filetype=filetype,
1076
- filename=temp_filename,
1077
- client=self.context.client,
1078
- initial_data=file,
1094
+ raise ValueError(f"relationship.type is invalid! {rel.type}")
1095
+
1096
+ def add_child_fragment(
1097
+ self,
1098
+ os_workspace,
1099
+ source_entity_uid,
1100
+ filename,
1101
+ filetype,
1102
+ file: Union[Contents, bytes],
1103
+ fields={},
1104
+ relationship: RelationshipName = FRAGMENT_RELATIONSHIP,
1105
+ os_entity_uid=None,
1106
+ os_relationship_uid=None,
1107
+ os_entity_type=FRAGMENT_ENTITY_NAME,
1108
+ previous_fragment_uid=None,
1109
+ previous_fragment_relationship_uid=None,
1110
+ previous_fragment_relationship=PREVIOUS_FRAGMENT_RELATIONSHIP,
1111
+ next_fragment_uid=None,
1112
+ next_fragment_relationship_uid=None,
1113
+ next_fragment_relationship=NEXT_FRAGMENT_RELATIONSHIP,
1114
+ ):
1115
+ child_entity, child_rel = self._add_child_attachable(
1116
+ os_workspace,
1117
+ filename,
1118
+ filetype,
1119
+ file,
1120
+ {**fields, "source_entity_uid": source_entity_uid},
1121
+ relationship,
1122
+ os_entity_uid,
1123
+ os_relationship_uid,
1124
+ os_entity_type,
1125
+ )
1126
+ prev_rel, next_rel = None, None
1127
+ fragment_uid = child_entity.record["os_entity_uid"]
1128
+ fragment_type = child_entity.record["os_concept"]
1129
+ if previous_fragment_uid:
1130
+ prev_rel = previous_fragment_relationship or PREVIOUS_FRAGMENT_RELATIONSHIP
1131
+ self._add_relationship(
1132
+ os_workspace, fragment_uid, fragment_type,
1133
+ previous_fragment_uid, os_entity_type,
1134
+ previous_fragment_relationship, {}, previous_fragment_relationship_uid,
1079
1135
  )
1080
- temp_contents.flush()
1081
- child_entity._contents = temp_contents
1082
- child_entity.request["contents_pointer"] = child_entity._contents.to_locator()
1083
- return child_entity, child_rel
1136
+ if next_fragment_uid:
1137
+ next_rel = next_fragment_relationship or NEXT_FRAGMENT_RELATIONSHIP
1138
+ self._add_relationship(
1139
+ os_workspace, fragment_uid, fragment_type,
1140
+ next_fragment_uid, os_entity_type,
1141
+ next_fragment_relationship, {}, next_fragment_relationship_uid,
1142
+ )
1143
+ return child_entity, child_rel, prev_rel, next_rel
1084
1144
 
1085
1145
  def add_tag(self, os_workspace, name, group, order, color, fields={}):
1086
1146
  return self.add_child_entity(
1087
1147
  os_workspace,
1088
- "os_tag",
1089
- {**fields,"name": name, "group": group, "order": order, "color": color},
1090
- TAG_RELATIONSHIP_NAME,
1091
- "mtm",
1148
+ TAG_ENTITY_NAME,
1149
+ {**fields, "name": name, "group": group, "order": order, "color": color},
1150
+ TAG_RELATIONSHIP,
1092
1151
  )
1093
1152
 
1094
1153
  def add_annotations(