splight-lib 3.0.0.dev2__py3-none-any.whl → 3.0.0.dev3__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.
@@ -215,7 +215,7 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
215
215
  response = self._list(url, **kwargs)
216
216
  yield response
217
217
  next_page = (
218
- response["next"].split("page=")[1]
218
+ furl(response["next"]).query.params["page"]
219
219
  if response["next"]
220
220
  else None
221
221
  )
@@ -50,8 +50,7 @@ class LocalDatalakeClient(AbstractDatalakeClient):
50
50
 
51
51
  def _raw_get(
52
52
  self,
53
- resource_name: str,
54
- collection: str,
53
+ resource_type: DLResource,
55
54
  limit_: int = 1000,
56
55
  skip_: int = 0,
57
56
  sort: Union[List, str] = ["timestamp__desc"],
@@ -73,9 +72,10 @@ class LocalDatalakeClient(AbstractDatalakeClient):
73
72
  handler = FixedLineNumberFileHandler(
74
73
  file_path=file_path, total_lines=self._TOTAL_DOCS
75
74
  )
76
- documents = [
77
- json.loads(doc) for doc in handler.read()[skip_ : skip_ + limit_]
78
- ]
75
+ documents = [json.loads(doc) for doc in handler.read()]
76
+
77
+ filters = kwargs
78
+ filters.update({"output_format": resource_type.__name__})
79
79
  documents = self._filter(documents, filters=filters)
80
80
 
81
81
  reverse = False
@@ -83,7 +83,46 @@ class LocalDatalakeClient(AbstractDatalakeClient):
83
83
  reverse = True
84
84
  documents.sort(key=lambda x: x["timestamp"], reverse=reverse)
85
85
 
86
- return documents
86
+ # TODO: review how to apply grouping
87
+ return [
88
+ resource_type.parse_obj(doc)
89
+ for doc in documents[skip_ : limit_ + 1]
90
+ ]
91
+
92
+ def get(
93
+ self,
94
+ resource_type: Type,
95
+ limit_: int = 50,
96
+ skip_: int = 0,
97
+ sort: Union[List, str] = ["timestamp__desc"],
98
+ group_id: Union[List, str] = [],
99
+ group_fields: Union[List, str] = [],
100
+ tzinfo: timezone = timezone(timedelta()),
101
+ **kwargs,
102
+ ) -> QuerySet:
103
+ logger.debug(
104
+ "Retrieving object of type %s from datalake.",
105
+ resource_type,
106
+ tags=LogTags.DATALAKE,
107
+ )
108
+
109
+ new_kwargs = {
110
+ "get_func": "_raw_get",
111
+ "count_func": "None",
112
+ "collection": resource_type.Meta.collection_name,
113
+ "resource_type": resource_type,
114
+ "limit_": limit_,
115
+ "skip_": skip_,
116
+ "sort": sort,
117
+ "group_id": group_id,
118
+ "group_fields": group_fields,
119
+ "tzinfo": tzinfo,
120
+ }
121
+ kwargs.update(new_kwargs)
122
+ return QuerySet(self, **kwargs)
123
+
124
+ def get_output(self, query: Query) -> List[Dict]:
125
+ raise NotImplementedError()
87
126
 
88
127
  def get_dataframe(
89
128
  self,
@@ -5,10 +5,13 @@ from typing import Dict, List, Optional, Union
5
5
 
6
6
  import pandas as pd
7
7
  from furl import furl
8
+ from pydantic import BaseModel
8
9
  from retry import retry
9
- from splight_lib.abstract.client import AbstractRemoteClient
10
+ from splight_abstract import AbstractRemoteClient
11
+ from splight_abstract.datalake import (
12
+ AbstractDatalakeClient,
13
+ )
10
14
  from splight_lib.auth import SplightAuthToken
11
- from splight_lib.client.datalake.abstract import AbstractDatalakeClient
12
15
  from splight_lib.client.exceptions import SPLIGHT_REQUEST_EXCEPTIONS
13
16
  from splight_lib.logging._internal import LogTags, get_splight_logger
14
17
  from splight_lib.restclient import SplightRestClient
@@ -1,22 +1,10 @@
1
1
  from abc import ABC, abstractmethod, abstractproperty
2
- from functools import wraps
3
- from typing import Callable, Dict, List, Tuple, Type
2
+ from typing import Dict, List, Tuple, Type
4
3
 
5
4
  from pydantic import BaseModel
6
5
  from splight_lib.abstract.client import AbstractClient, QuerySet
7
6
 
8
7
 
9
- def validate_client_resource_type(func: Callable) -> Callable:
10
- @wraps(func)
11
- def wrapper(self, resource_type: Type, *args, **kwargs):
12
- if resource_type not in self.valid_classes:
13
- raise NotImplementedError(
14
- f"Not a valid resource_type: {resource_type.__name__}"
15
- )
16
- return func(self, resource_type, *args, **kwargs)
17
-
18
- return wrapper
19
-
20
8
 
21
9
  class AbstractHubSubClient(AbstractClient):
22
10
  @abstractmethod
@@ -1,4 +1,4 @@
1
- from typing import Dict, List, Optional, Tuple, Type
1
+ from typing import Dict, List, Optional, Tuple
2
2
 
3
3
  import requests
4
4
  from furl import furl
@@ -7,33 +7,27 @@ from splight_lib.auth import SplightAuthToken
7
7
  from splight_lib.client.hub.abstract import (
8
8
  AbstractHubClient,
9
9
  AbstractHubSubClient,
10
- validate_client_resource_type,
11
10
  )
12
- from splight_lib.models.hub import HubComponent, HubComponentVersion
13
- from splight_lib.settings import settings
14
11
 
15
12
 
16
13
  class _SplightHubGenericClient(AbstractHubSubClient):
17
14
  _PREFIX: str = "v2/hub"
18
- valid_classes = [
19
- HubComponent,
20
- HubComponentVersion,
21
- ]
22
15
  _CLASS_MAP = {
23
- HubComponent: "components",
24
- HubComponentVersion: "component-versions",
16
+ 'HubComponent': "components",
17
+ 'HubComponentVersion': "component-versions",
25
18
  }
26
19
 
27
20
  def __init__(
28
21
  self,
29
22
  base_path: str,
23
+ api_host: str,
30
24
  headers: Optional[Dict[str, str]] = {},
31
25
  *args,
32
26
  **kwargs,
33
27
  ):
34
28
  super().__init__(*args, **kwargs)
35
29
  self._base_url = furl(
36
- settings.SPLIGHT_PLATFORM_API_HOST,
30
+ api_host,
37
31
  path=f"{self._PREFIX}/{base_path}/",
38
32
  )
39
33
  self._session = requests.Session()
@@ -56,10 +50,9 @@ class _SplightHubGenericClient(AbstractHubSubClient):
56
50
  def save(self, instance: BaseModel) -> BaseModel:
57
51
  raise NotImplementedError
58
52
 
59
- @validate_client_resource_type
60
53
  def _get(
61
54
  self,
62
- resource_type: Type,
55
+ resource_type: str,
63
56
  first: bool = False,
64
57
  limit_: int = -1,
65
58
  skip_: int = 0,
@@ -71,14 +64,14 @@ class _SplightHubGenericClient(AbstractHubSubClient):
71
64
  assert (
72
65
  response.status_code == 200
73
66
  ), f"Failed to get components {response.content}"
74
- queryset = [resource_type(**v) for v in response.json()["results"]]
67
+ queryset = response.json()["results"]
75
68
  if first:
76
69
  return queryset[0] if queryset else None
77
70
  return queryset
78
71
 
79
72
  def count(
80
73
  self,
81
- resource_type: Type,
74
+ resource_type: str,
82
75
  first=False,
83
76
  limit_: int = -1,
84
77
  skip_: int = 0,
@@ -92,15 +85,14 @@ class _SplightHubGenericClient(AbstractHubSubClient):
92
85
  ), f"Failed to get components {response.content}"
93
86
  return response.json()["count"]
94
87
 
95
- def delete(self, resource_type: Type, id: str) -> None:
88
+ def delete(self, resource_type: str, id: str) -> None:
96
89
  url = self._get_url(resource_type, id)
97
90
  response = self._session.delete(url)
98
91
  assert (
99
92
  response.status_code == 204
100
93
  ), f"Failed to delete component {response.content}"
101
94
 
102
- @validate_client_resource_type
103
- def update(self, resource_type: Type, id: str, data: Dict) -> BaseModel:
95
+ def update(self, resource_type: str, id: str, data: Dict) -> BaseModel:
104
96
  url = self._get_url(resource_type, id)
105
97
  response = self._session.put(url, json=data)
106
98
  assert (
@@ -108,9 +100,8 @@ class _SplightHubGenericClient(AbstractHubSubClient):
108
100
  ), f"Failed to update component. {response.content}"
109
101
  return resource_type(**response.json())
110
102
 
111
- @validate_client_resource_type
112
103
  def partial_update(
113
- self, resource_type: Type, id: str, data: Dict
104
+ self, resource_type: str, id: str, data: Dict
114
105
  ) -> BaseModel:
115
106
  url = self._get_url(resource_type, id)
116
107
  response = self._session.patch(url, json=data)
@@ -119,8 +110,7 @@ class _SplightHubGenericClient(AbstractHubSubClient):
119
110
  ), f"Failed to update component. {response.content}"
120
111
  return resource_type.parse_obj(response.json())
121
112
 
122
- @validate_client_resource_type
123
- def rebuild(self, resource_type: Type, id: str) -> None:
113
+ def rebuild(self, resource_type: str, id: str) -> None:
124
114
  url = self._get_url(resource_type, id)
125
115
  url = url / "rebuild/"
126
116
  response = self._session.post(url, headers=self.headers)
@@ -130,28 +120,34 @@ class _SplightHubGenericClient(AbstractHubSubClient):
130
120
 
131
121
 
132
122
  class SplightHubClient(AbstractHubClient):
133
- def __init__(self, *args, **kwargs) -> None:
123
+ def __init__(
124
+ self,
125
+ access_key: str,
126
+ secret_key: str,
127
+ api_host: str,
128
+ *args, **kwargs
129
+ ) -> None:
134
130
  super().__init__()
135
131
  token = SplightAuthToken(
136
- access_key=settings.SPLIGHT_ACCESS_ID,
137
- secret_key=settings.SPLIGHT_SECRET_KEY,
132
+ access_key=access_key,
133
+ secret_key=secret_key,
138
134
  )
139
135
  self._all = _SplightHubGenericClient(
140
- base_path="all", headers=token.header
136
+ base_path="all", headers=token.header, api_host=api_host
141
137
  )
142
138
  self._mine = _SplightHubGenericClient(
143
- base_path="mine", headers=token.header
139
+ base_path="mine", headers=token.header, api_host=api_host
144
140
  )
145
141
  self._public = _SplightHubGenericClient(
146
- base_path="public", headers=token.header
142
+ base_path="public", headers=token.header, api_host=api_host
147
143
  )
148
144
  self._private = _SplightHubGenericClient(
149
- base_path="private", headers=token.header
145
+ base_path="private", headers=token.header, api_host=api_host
150
146
  )
151
147
  self._setup = _SplightHubGenericClient(
152
- base_path="setup", headers=token.header
148
+ base_path="setup", headers=token.header, api_host=api_host
153
149
  )
154
- self._host = furl(settings.SPLIGHT_PLATFORM_API_HOST)
150
+ self._host = furl(api_host)
155
151
  self._headers = token.header
156
152
 
157
153
  def upload(self, data: Dict, files: Dict) -> Tuple:
@@ -161,14 +157,14 @@ class SplightHubClient(AbstractHubClient):
161
157
  )
162
158
  status_code = response.status_code
163
159
  assert status_code == 201, "Unable to upload component to HUB"
164
- return response.json(), status_code
160
+ return response.json()
165
161
 
166
162
  def download(self, data: Dict) -> Tuple:
167
163
  url = self._host / "v2/hub/download/"
168
164
  response = requests.post(url, data=data, headers=self._headers)
169
165
  status_code = response.status_code
170
166
  assert status_code == 200, "Unable to download component"
171
- return response.content, status_code
167
+ return response.content
172
168
 
173
169
  @property
174
170
  def all(self) -> AbstractHubSubClient:
@@ -7,9 +7,8 @@ from splight_lib.models.component import (
7
7
  ComponentObjectInstance,
8
8
  )
9
9
  from splight_lib.models.file import File
10
- from splight_lib.models.hub import HubComponent, HubComponentVersion
11
- from splight_lib.models.native import Boolean, Number, String
12
10
  from splight_lib.models.query import Query
11
+ from splight_lib.models.native import Number, String, Boolean
13
12
  from splight_lib.models.secret import Secret
14
13
  from splight_lib.models.setpoint import SetPoint
15
14
 
@@ -19,9 +18,6 @@ __all__ = [
19
18
  Asset,
20
19
  Attribute,
21
20
  Boolean,
22
- Component,
23
- ComponentObject,
24
- ComponentObjectInstance,
25
21
  File,
26
22
  HubComponent,
27
23
  HubComponentVersion,
@@ -1,9 +1,7 @@
1
- import json
2
- from datetime import datetime, timezone
3
- from typing import ClassVar, Dict, List, Optional, Set, Tuple
4
-
5
- import pandas as pd
6
- from pydantic import BaseModel, Field, PrivateAttr
1
+ from typing import Dict, List, Optional
2
+ from pydantic import BaseModel, PrivateAttr, Field
3
+ from splight_abstract.database import AbstractDatabaseClient
4
+ from splight_abstract.datalake import AbstractDatalakeClient
7
5
  from splight_lib.client.database import DatabaseClientBuilder
8
6
  from splight_lib.client.database.abstract import AbstractDatabaseClient
9
7
  from splight_lib.client.datalake import DatalakeClientBuilder
@@ -21,6 +21,13 @@ from strenum import LowercaseStrEnum
21
21
  warnings.filterwarnings("ignore", category=RuntimeWarning)
22
22
 
23
23
 
24
+ class PrivacyPolicy(LowercaseStrEnum):
25
+ PUBLIC = auto()
26
+ PRIVATE = auto()
27
+
28
+ warnings.filterwarnings("ignore", category=RuntimeWarning)
29
+
30
+
24
31
  class PrivacyPolicy(LowercaseStrEnum):
25
32
  PUBLIC = auto()
26
33
  PRIVATE = auto()
splight_lib/models/hub.py CHANGED
@@ -1,13 +1,44 @@
1
+ import json
2
+ import os
1
3
  from typing import List, Optional
2
4
 
3
- from pydantic import BaseModel, validator
5
+ import py7zr
6
+ from pydantic import BaseModel, PrivateAttr, validator
7
+
8
+ from splight_lib.client.hub.abstract import AbstractHubClient
9
+ from splight_lib.client.hub.client import SplightHubClient
10
+ from splight_lib.models.component import (
11
+ Binding,
12
+ Command,
13
+ ComponentType,
14
+ Endpoint,
15
+ InputParameter,
16
+ Output,
17
+ )
18
+ from splight_lib.settings import settings
19
+ from splight_lib.utils.hub import (
20
+ COMPRESSION_TYPE,
21
+ README_FILE_1,
22
+ README_FILE_2,
23
+ get_ignore_pathspec,
24
+ get_spec,
25
+ )
4
26
 
5
27
  VERIFICATION_CHOICES = ["verified", "unverified", "official"]
6
28
 
7
29
 
30
+ def get_hub_client() -> AbstractHubClient:
31
+ return SplightHubClient(
32
+ access_key=settings.SPLIGHT_ACCESS_ID,
33
+ secret_key=settings.SPLIGHT_SECRET_KEY,
34
+ api_host=settings.SPLIGHT_PLATFORM_API_HOST,
35
+ )
36
+
37
+
8
38
  class HubComponent(BaseModel):
9
39
  id: Optional[str]
10
40
  name: str
41
+ version: str
11
42
  splight_cli_version: str
12
43
  build_status: Optional[str]
13
44
  description: Optional[str]
@@ -24,12 +55,148 @@ class HubComponent(BaseModel):
24
55
  min_component_capacity: Optional[str]
25
56
  usage_count: int = 0
26
57
 
58
+ input: List[InputParameter] = []
59
+ output: List[Output] = []
60
+ commands: List[Command] = []
61
+ endpoints: List[Endpoint] = []
62
+ bindings: List[Binding] = []
63
+
64
+ _hub_client: AbstractHubClient = PrivateAttr()
65
+
66
+ def __init__(self, *args, **kwargs):
67
+ super().__init__(*args, **kwargs)
68
+ self._hub_client = get_hub_client()
69
+
27
70
  @validator("verification", pre=True, always=True)
28
71
  def set_verification_now(cls, v):
29
72
  if v:
30
73
  assert v in VERIFICATION_CHOICES, "Verification value not allowed."
31
74
  return v
32
75
 
76
+ @classmethod
77
+ def list_mine(cls, **params) -> List["HubComponent"]:
78
+ hub_client = get_hub_client()
79
+ data = hub_client.mine.get(resource_type=cls.__name__, **params)
80
+ return [cls.parse_obj(obj) for obj in data]
81
+
82
+ @classmethod
83
+ def list_all(cls, **params) -> List["HubComponent"]:
84
+ hub_client = get_hub_client()
85
+ data = hub_client.all.get(resource_type=cls.__name__, **params)
86
+ return [cls.parse_obj(obj) for obj in data]
87
+
88
+ @classmethod
89
+ def list_public(cls, **params) -> List["HubComponent"]:
90
+ hub_client = get_hub_client()
91
+ data = hub_client.public.get(resource_type=cls.__name__, **params)
92
+ return [cls.parse_obj(obj) for obj in data]
93
+
94
+ @classmethod
95
+ def list_private(cls, **params) -> List["HubComponent"]:
96
+ hub_client = get_hub_client()
97
+ data = hub_client.private.get(resource_type=cls.__name__, **params)
98
+ return [cls.parse_obj(obj) for obj in data]
99
+
100
+ @classmethod
101
+ def list_setup(cls, **params) -> List["HubComponent"]:
102
+ hub_client = get_hub_client()
103
+ data = hub_client.setup.get(resource_type=cls.__name__, **params)
104
+ return [cls.parse_obj(obj) for obj in data]
105
+
106
+ @classmethod
107
+ def retrieve_mine(cls, id: str) -> "HubComponent":
108
+ hub_client = get_hub_client()
109
+ data = hub_client.mine.get(
110
+ resource_type=cls.__name__, id=id, first=True
111
+ )
112
+ return cls.parse_obj(data)
113
+
114
+ @classmethod
115
+ def retrieve_all(cls, id: str) -> "HubComponent":
116
+ hub_client = get_hub_client()
117
+ data = hub_client.all.get(
118
+ resource_type=cls.__name__, id=id, first=True
119
+ )
120
+ return cls.parse_obj(data)
121
+
122
+ @classmethod
123
+ def retrieve_public(cls, id: str) -> "HubComponent":
124
+ hub_client = get_hub_client()
125
+ data = hub_client.public.get(
126
+ resource_type=cls.__name__, id=id, first=True
127
+ )
128
+ return cls.parse_obj(data)
129
+
130
+ @classmethod
131
+ def retrieve_private(cls, id: str) -> "HubComponent":
132
+ hub_client = get_hub_client()
133
+ data = hub_client.private.get(
134
+ resource_type=cls.__name__, id=id, first=True
135
+ )
136
+ return cls.parse_obj(data)
137
+
138
+ @classmethod
139
+ def retrieve_setup(cls, id: str) -> "HubComponent":
140
+ hub_client = get_hub_client()
141
+ data = hub_client.setup.get(
142
+ resource_type=cls.__name__, id=id, first=True
143
+ )
144
+ return cls.parse_obj(data)
145
+
146
+ def delete(self):
147
+ return self._hub_client.mine.delete(self.id)
148
+
149
+ def download(self):
150
+ return self._hub_client.download(data=self.dict())
151
+
152
+ @classmethod
153
+ def upload(cls, path: str):
154
+ hub_client = get_hub_client()
155
+ spec = get_spec(path)
156
+ name = spec["name"]
157
+ version = spec["version"]
158
+ file_name = f"{name}-{version}.{COMPRESSION_TYPE}"
159
+ ignore_pathspec = get_ignore_pathspec(path)
160
+ versioned_name = f"{name}-{version}"
161
+ readme_path = os.path.join(path, README_FILE_1)
162
+ if not os.path.exists(readme_path):
163
+ readme_path = os.path.join(path, README_FILE_2)
164
+ with py7zr.SevenZipFile(file_name, "w") as archive:
165
+ for root, _, files in os.walk(path):
166
+ if ignore_pathspec and ignore_pathspec.match_file(root):
167
+ continue
168
+ for file in files:
169
+ if ignore_pathspec and ignore_pathspec.match_file(
170
+ os.path.join(root, file)
171
+ ):
172
+ continue
173
+ filepath = os.path.join(root, file)
174
+ archive.write(filepath, os.path.join(versioned_name, file))
175
+ data = {
176
+ "name": name,
177
+ "version": version,
178
+ "splight_cli_version": spec["splight_cli_version"],
179
+ "privacy_policy": spec.get("privacy_policy", "private"),
180
+ "tags": spec.get("tags", []),
181
+ "custom_types": json.dumps(spec.get("custom_types", [])),
182
+ "input": json.dumps(spec.get("input", [])),
183
+ "output": json.dumps(spec.get("output", [])),
184
+ "component_type": spec.get(
185
+ "component_type", ComponentType.CONNECTOR.value
186
+ ),
187
+ "commands": json.dumps(spec.get("commands", [])),
188
+ "bindings": json.dumps(spec.get("bindings", [])),
189
+ "endpoints": json.dumps(spec.get("endpoints", [])),
190
+ }
191
+ files = {
192
+ "file": open(file_name, "rb"),
193
+ "readme": open(readme_path, "rb"),
194
+ }
195
+ component = hub_client.upload(data=data, files=files)
196
+ if os.path.exists(file_name):
197
+ os.remove(file_name)
198
+ return cls.parse_obj(component)
199
+
33
200
 
34
201
  class HubComponentVersion(HubComponent):
35
202
  pass
@@ -0,0 +1,102 @@
1
+ import os
2
+ from datetime import datetime
3
+ from typing import Any, Dict, List
4
+
5
+ import pytest
6
+ from pytest_mock import MockerFixture
7
+
8
+ from splight_lib.component.spec import Spec
9
+ from splight_lib.models import (
10
+ Asset,
11
+ Attribute,
12
+ Component,
13
+ ComponentObjectInstance,
14
+ File,
15
+ )
16
+ from splight_lib.models.component import CustomType, Parameter
17
+ from splight_lib.settings import settings
18
+
19
+ settings.configure(LOCAL_ENVIRONMENT=True)
20
+
21
+ FAKE_NATIVE_VALUES = {
22
+ "int": 1,
23
+ "bool": True,
24
+ "str": "fake",
25
+ "float": 5.5,
26
+ "datetime": datetime(2022, 12, 18),
27
+ "url": "www.google.com",
28
+ }
29
+
30
+ FAKE_DATABASE_VALUES = {
31
+ "Component": Component(name="ComponentTest", version="1.0.0"),
32
+ "Asset": Asset(name="AssetTest"),
33
+ "Attribute": Attribute(name="AttrTest"),
34
+ "File": File(file=""),
35
+ }
36
+
37
+
38
+ def get_test_value(type_: str, custom_types: Dict[str, CustomType]) -> Any:
39
+ if type_ in FAKE_NATIVE_VALUES:
40
+ value = FAKE_NATIVE_VALUES.get(type_)
41
+ elif type_ in FAKE_DATABASE_VALUES:
42
+ value = FAKE_DATABASE_VALUES.get(type_)
43
+ else:
44
+ custom_type_def = custom_types[type_]
45
+ model_class = ComponentObjectInstance.from_custom_type(custom_type_def)
46
+ aux_value = component_object_attributes(
47
+ custom_type_def.fields, custom_types
48
+ )
49
+ value = model_class.parse_obj(aux_value)
50
+ return value
51
+
52
+
53
+ def component_object_attributes(
54
+ parameters: List[Parameter], custom_types: Dict[str, CustomType]
55
+ ) -> Dict[str, Any]:
56
+ values_dict = {
57
+ param.name: get_test_value(param.type, custom_types)
58
+ for param in parameters
59
+ }
60
+ return values_dict
61
+
62
+
63
+ def get_test_input(spec: Spec):
64
+ input_model_class = spec.get_input_model()
65
+ custom_types = {ct.name: ct for ct in spec.custom_types}
66
+ input_fake_values = {}
67
+ for param in spec.input:
68
+ param_name = param.name
69
+ type_ = param.type
70
+ value = get_test_value(type_, custom_types)
71
+
72
+ if param.multiple:
73
+ value = [value]
74
+
75
+ input_fake_values.update({param_name: value})
76
+ return input_model_class.parse_obj(input_fake_values)
77
+
78
+
79
+ @pytest.fixture(autouse=True)
80
+ def mock_component(mocker: MockerFixture):
81
+ # Patch method for checking duplicated component
82
+ mocker.patch(
83
+ (
84
+ "splight_lib.component.abstract.SplightBaseComponent."
85
+ "_check_duplicated_component"
86
+ ),
87
+ return_value=None,
88
+ )
89
+
90
+ # Patch HealthCheckProcessor
91
+ mocker.patch(
92
+ "splight_lib.execution.ExecutionClient.start", return_value=None
93
+ )
94
+
95
+ base_path = os.getcwd()
96
+ spec = Spec.from_file(os.path.join(base_path, "spec.json"))
97
+ # Generate fake input for testing
98
+ mocker.patch(
99
+ "splight_lib.component.spec.Spec.component_input",
100
+ return_value=get_test_input(spec),
101
+ )
102
+ return mocker
@@ -0,0 +1,27 @@
1
+ import os
2
+ from typing import Any, Dict, Optional
3
+ import pathspec
4
+ import json
5
+
6
+ SPLIGHT_IGNORE = ".splightignore"
7
+ COMPRESSION_TYPE = "7z"
8
+ SPEC_FILE = "spec.json"
9
+ README_FILE_1 = "README.md"
10
+ README_FILE_2 = "README"
11
+
12
+
13
+ def get_spec(path: str) -> Dict[str, Any]:
14
+ with open(os.path.join(path, SPEC_FILE)) as fid:
15
+ return json.load(fid)
16
+
17
+
18
+ def get_ignore_pathspec(path: str) -> Optional[pathspec.PathSpec]:
19
+ try:
20
+ with open(
21
+ os.path.join(path, SPLIGHT_IGNORE), "r"
22
+ ) as splightignore:
23
+ return pathspec.PathSpec.from_lines(
24
+ "gitwildmatch", splightignore
25
+ )
26
+ except FileNotFoundError:
27
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: splight-lib
3
- Version: 3.0.0.dev2
3
+ Version: 3.0.0.dev3
4
4
  Summary: Library for public use. Splight
5
5
  Home-page: UNKNOWN
6
6
  Author: Splight
@@ -25,15 +25,15 @@ splight_lib/client/database/abstract.py,sha256=r9mz_FK1fYzQBabXGzAeBrWOMiRsMesyu
25
25
  splight_lib/client/database/builder.py,sha256=hL_Cv7ZxNG7MysKDbEoDGxPlAVvqm5BZKIzYL5jOxWI,582
26
26
  splight_lib/client/database/classmap.py,sha256=l4zoxIDyXoDUdW6c5mM0lGsI5PppNQr4lqo7JKVSsVk,661
27
27
  splight_lib/client/database/local_client.py,sha256=0dkHwJDH1alXPCRRnfnaduI6uiHbRPgabRvT1BPqoW0,6161
28
- splight_lib/client/database/remote_client.py,sha256=k__1or1_I5rO89FKa03OcLzU9VkiSUr2mu9rQHKInI4,8864
28
+ splight_lib/client/database/remote_client.py,sha256=pAHc4wSc74lqVGKAQ6K0Go8juqo9PS_gIsrqE4h7i4I,8873
29
29
  splight_lib/client/datalake/__init__.py,sha256=EBjSk_W4bdN9MRR3dVl-WgK-ldAw-FOXSXBelPaTuh4,311
30
30
  splight_lib/client/datalake/abstract.py,sha256=QIO43nuFy7bjPl6DbCVtvkikhuMihFqXYItTiYwTXQE,1807
31
31
  splight_lib/client/datalake/builder.py,sha256=SZMXotbc2sbyruphph899bnpKBU5ZgNTya3k9qap8-Q,582
32
- splight_lib/client/datalake/local_client.py,sha256=t66avSfbvPbFVgWQrd5wMFUY69t89aQb-m-fjw1nKFU,5180
33
- splight_lib/client/datalake/remote_client.py,sha256=Di9UyPJQAbFzTvvD91JRdx2A-2YUeAU3U2E3f4Tmf4M,6284
32
+ splight_lib/client/datalake/local_client.py,sha256=eEPaUPFxLjNfV7HfhBCj2_BajRThPmgYs-bOSjEWxAA,6401
33
+ splight_lib/client/datalake/remote_client.py,sha256=8uxSAwlBCZK75pwq9n3MgSw5Gbgq-NjPr2AMx6CyAj8,6302
34
34
  splight_lib/client/hub/__init__.py,sha256=tJPnRcjJ-WYdvmzDw5vXTiHiS4ueJQ-5HRZNnQY8oxA,96
35
- splight_lib/client/hub/abstract.py,sha256=SV03PtUO1eNxBVoP79A3gF0qqNFODVCyJubl4vkIB5U,1874
36
- splight_lib/client/hub/client.py,sha256=2MFQv-VTeQbiD3Z6dVjk95q1lWR2uTrQlYN4XszErOE,6284
35
+ splight_lib/client/hub/abstract.py,sha256=te34eKUqX4wPj-Jqi2lysfBBC-DDOjVTBQ6Fja9m_ow,1440
36
+ splight_lib/client/hub/client.py,sha256=ymM4-e74Y_aqv-sPvjqX6brn_oo0jkzzgtkXjt7CdGg,5983
37
37
  splight_lib/communication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  splight_lib/communication/event_handler.py,sha256=lYawd-p_GySaukB2stNch6oP5tBt-OgjRkkM7G1C1IM,5449
39
39
  splight_lib/component/__init__.py,sha256=wMBecMg5w43g0qowQYrM3RxnX0CU_exFNm_DVQnAxNc,105
@@ -44,17 +44,17 @@ splight_lib/logging/__init__.py,sha256=aZ2aMBzJFSaopL4eaLcCp_1Mi18NBZ3vw9pHkFEYX
44
44
  splight_lib/logging/_internal.py,sha256=B6MQAZeKQcPpeWeupznud4KyzZq6SBScDq8F3e3MSsE,1631
45
45
  splight_lib/logging/component.py,sha256=huOqJCOfqxQUk0fc6VBcWopFnMa27O03ReqI_-jUkf4,1438
46
46
  splight_lib/logging/logging.py,sha256=WkEMOBjMP8E1SUrN3w79INpiywSgj2PX1txnhHc1baE,4863
47
- splight_lib/models/__init__.py,sha256=WVg6mhsT2pG4KQBnTE4ZwE5R90R2_4CQI2_IOlcr8w4,836
47
+ splight_lib/models/__init__.py,sha256=GsuGdZxNRB1W4dBr5zKto7odER8BL-8q6I65yrD1h60,702
48
48
  splight_lib/models/alert.py,sha256=qpjKZ9J8hmaRrMENsNJD5lB__My00q1Z0KxNSi8-S5k,1340
49
49
  splight_lib/models/asset.py,sha256=C209i8WL0MKfxONezBpUfppJow2d8Tad2ER58Xu_QEU,1313
50
50
  splight_lib/models/attribute.py,sha256=5F-J_Uuz5CLNeH2O4qXwVBv9tGgbXiqZfZPpxW1M0PA,171
51
- splight_lib/models/base.py,sha256=Dl4MP7k66u-IWXhioPthMI4OTm573OdjYENr2Pk-4Xc,5373
51
+ splight_lib/models/base.py,sha256=eRop-kVv4qIKZkOLx6vSoBEVMVvZoWCA9vtiGU7WUUE,5400
52
52
  splight_lib/models/communication.py,sha256=NyK4_YwJDm66T31LmzGhqHG8a7mTAvYP1rJ6hcpPWaI,810
53
- splight_lib/models/component.py,sha256=adxCi2HXdTAeNoUMBuy2sANPxNFSpjqGxhK4VcW7jTU,9264
53
+ splight_lib/models/component.py,sha256=50qIfgVc9Ics4vP8nGrhtvHbrBBOXBaguAoboi398ZI,9406
54
54
  splight_lib/models/event.py,sha256=ZjlY8w20ixkXsLZa86sKhviYdTPW8gulXh59zg4s_7c,2973
55
55
  splight_lib/models/exceptions.py,sha256=NkIrzm9DBV5el0LE4hrH1UsSdMmFSX8PtNAilEfnQQw,367
56
56
  splight_lib/models/file.py,sha256=tGrkrn7FggrlyApQFymOf3PnQ2-LtaV4iTjUGgB6IEI,1229
57
- splight_lib/models/hub.py,sha256=0td4sNbrmkVDGpZv2WDDi2DwsXmNDYmqySzQ9JGuu9M,936
57
+ splight_lib/models/hub.py,sha256=Z6JH4BVEVuFxCCJj8W-nFlXOUA-69LQ0kbKpz2udSl0,6736
58
58
  splight_lib/models/native.py,sha256=nCB8DDC7yBzBl18c97Qa0OzIUCrcVOrdxM_4Bl9sh1Q,679
59
59
  splight_lib/models/query.py,sha256=XwAEelAJcomWiBFxTQivqTmU5PneLGJUxLEzx2mGgJc,2956
60
60
  splight_lib/models/secret.py,sha256=XWTo0vY3RZQ1OlYAgGMn-shsHNgK7ndQW237xDiIkd0,366
@@ -63,10 +63,12 @@ splight_lib/restclient/__init__.py,sha256=nD2HBPvZPl_9wxu79XL6gn8AmaTbu-0xTXPQFF
63
63
  splight_lib/restclient/client.py,sha256=k9hIXIdZ-69iUR3AslYgrJhV6D4Zfjpit5CGsFqzd48,14065
64
64
  splight_lib/restclient/exceptions.py,sha256=LPAAggsdG73LLRheI7h2Qmwf43j2EQOBx2hhKQZP5-4,964
65
65
  splight_lib/restclient/types.py,sha256=u1SAzdkNKFRlaq2mKb1Nmw32iy2ZtPGcGIZndivcv8M,2453
66
+ splight_lib/testing/__init__.py,sha256=DS4KZyQEQC7DCo8hmf5gzN98-K-0apuQjIjmEbiqJ7s,2824
66
67
  splight_lib/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
67
68
  splight_lib/utils/custom_model.py,sha256=u6qO1ceJOKU-J5XHPLZlefcz_Lmk8lG8EQv6UzF2yGQ,2288
68
- splight_lib-3.0.0.dev2.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
69
- splight_lib-3.0.0.dev2.dist-info/METADATA,sha256=JnIewAV08Jfi5BYfKzP5JCrgChY1qaGWAViixw9oQrI,1808
70
- splight_lib-3.0.0.dev2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
71
- splight_lib-3.0.0.dev2.dist-info/top_level.txt,sha256=fWfYJl_oNnsorzbmF42OnO53PCvm6ky1riqrMu_bQ3w,12
72
- splight_lib-3.0.0.dev2.dist-info/RECORD,,
69
+ splight_lib/utils/hub.py,sha256=Re5Zh3Wk1HuRcHnBD-N5Y152Gcq7vrvNtL5WtWNMCLs,677
70
+ splight_lib-3.0.0.dev3.dist-info/LICENSE.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
+ splight_lib-3.0.0.dev3.dist-info/METADATA,sha256=7ZagIEEerEmPfA7-y_aneYomf0Lk-Y6KIxYJykWclJs,1808
72
+ splight_lib-3.0.0.dev3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
73
+ splight_lib-3.0.0.dev3.dist-info/top_level.txt,sha256=fWfYJl_oNnsorzbmF42OnO53PCvm6ky1riqrMu_bQ3w,12
74
+ splight_lib-3.0.0.dev3.dist-info/RECORD,,