labfreed 0.3.1a3__py3-none-any.whl → 0.3.1a5__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.
Potentially problematic release.
This version of labfreed might be problematic. Click here for more details.
- labfreed/__init__.py +1 -1
- labfreed/labfreed_extended/app/app_infrastructure.py +3 -1
- labfreed/labfreed_extended/app/pac_info.py +2 -2
- labfreed/pac_attributes/__init__.py +0 -0
- labfreed/pac_attributes/client/__init__.py +0 -1
- labfreed/pac_attributes/pythonic/excel_attribute_data_source.py +181 -0
- labfreed/{labfreed_extended/pac_attributes → pac_attributes/pythonic}/py_attributes.py +2 -1
- labfreed/pac_attributes/pythonic/py_dict_data_source.py +13 -0
- labfreed/pac_attributes/server/__init__.py +3 -3
- labfreed/pac_attributes/server/attribute_data_sources.py +8 -9
- labfreed/pac_attributes/server/server.py +1 -1
- labfreed/trex/{python_convenience → pythonic}/data_table.py +1 -1
- labfreed/trex/{python_convenience → pythonic}/pyTREX.py +2 -2
- {labfreed-0.3.1a3.dist-info → labfreed-0.3.1a5.dist-info}/METADATA +2 -2
- {labfreed-0.3.1a3.dist-info → labfreed-0.3.1a5.dist-info}/RECORD +21 -19
- labfreed/labfreed_extended/pac_attributes/server/excel_attribute_data_source.py +0 -129
- /labfreed/labfreed_extended/{utilities → app}/formatted_print.py +0 -0
- /labfreed/{labfreed_extended/pac_attributes/server → pac_attributes/pythonic}/attribute_server_factory.py +0 -0
- /labfreed/trex/{python_convenience → pythonic}/__init__.py +0 -0
- /labfreed/trex/{python_convenience → pythonic}/quantity.py +0 -0
- {labfreed-0.3.1a3.dist-info → labfreed-0.3.1a5.dist-info}/WHEEL +0 -0
- {labfreed-0.3.1a3.dist-info → labfreed-0.3.1a5.dist-info}/licenses/LICENSE +0 -0
labfreed/__init__.py
CHANGED
|
@@ -3,11 +3,13 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
3
3
|
|
|
4
4
|
import requests
|
|
5
5
|
|
|
6
|
+
from labfreed.labfreed_extended.app.pac_info import PacInfo
|
|
6
7
|
from labfreed.pac_attributes.client.attribute_cache import MemoryAttributeCache
|
|
7
8
|
from labfreed.pac_attributes.client.client import AttributeClient, attribute_request_default_callback_factory
|
|
8
9
|
from labfreed.pac_attributes.well_knonw_attribute_keys import MetaAttributeKeys
|
|
9
10
|
from labfreed.well_known_extensions.display_name_extension import DisplayNameExtension
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
|
|
11
13
|
from labfreed.pac_id.pac_id import PAC_ID
|
|
12
14
|
from labfreed.pac_id_resolver.resolver import PAC_ID_Resolver, cit_from_str
|
|
13
15
|
from labfreed.pac_id_resolver.services import ServiceGroup
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
|
-
from
|
|
4
|
+
from labfreed.pac_attributes.pythonic.py_attributes import pyAttribute, pyAttributes
|
|
5
5
|
from labfreed.pac_cat.pac_cat import PAC_CAT
|
|
6
6
|
from labfreed.pac_id.pac_id import PAC_ID
|
|
7
7
|
from labfreed.pac_id_resolver.services import ServiceGroup
|
|
8
|
-
from labfreed_extended.
|
|
8
|
+
from labfreed.labfreed_extended.app.formatted_print import StringIOLineBreak
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class PacInfo(BaseModel):
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import labfreed.utilities.translations
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import Optional, Tuple, List, Dict
|
|
6
|
+
from urllib.parse import urlparse, urlsplit, urlunsplit, parse_qsl, urlencode
|
|
7
|
+
|
|
8
|
+
from cachetools import TTLCache, cached
|
|
9
|
+
|
|
10
|
+
from labfreed.pac_attributes.api_data_models.response import AttributeGroup
|
|
11
|
+
from labfreed.pac_attributes.pythonic.py_attributes import pyAttribute, pyAttributes
|
|
12
|
+
from labfreed.pac_attributes.server.server import AttributeGroupDataSource
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from openpyxl import load_workbook
|
|
16
|
+
except ImportError:
|
|
17
|
+
raise ImportError("Please install labfreed with the [extended] extra: pip install labfreed[extended]")
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------------
|
|
20
|
+
# Cache (shared by all instances). TTL can be overridden per instance.
|
|
21
|
+
# ---------------------------------------------------------------------
|
|
22
|
+
_cache = TTLCache(maxsize=128, ttl=0)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# ---------------------------------------------------------------------
|
|
26
|
+
# Helpers
|
|
27
|
+
# ---------------------------------------------------------------------
|
|
28
|
+
def _is_sharepoint_url(s: str) -> bool:
|
|
29
|
+
try:
|
|
30
|
+
parsed = urlparse(s)
|
|
31
|
+
if parsed.scheme not in {"http", "https"}:
|
|
32
|
+
return False
|
|
33
|
+
host = (parsed.netloc or "").lower()
|
|
34
|
+
return ("sharepoint.com" in host) or ("1drv.ms" in host)
|
|
35
|
+
except Exception:
|
|
36
|
+
return False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _is_local_path(s: str) -> bool:
|
|
40
|
+
return os.path.exists(s) if not _is_sharepoint_url(s) else False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _ensure_download_query(u: str) -> str:
|
|
44
|
+
parts = urlsplit(u)
|
|
45
|
+
q = dict(parse_qsl(parts.query, keep_blank_values=True))
|
|
46
|
+
# Preserve all params (guest tokens, etc.), just force file response.
|
|
47
|
+
q["download"] = "1"
|
|
48
|
+
return urlunsplit((parts.scheme, parts.netloc, parts.path, urlencode(q, doseq=True), parts.fragment))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _get_row_by_first_cell(sheet_rows: List[tuple], match_value: str, base_url: str) -> Optional[Dict[str, object]]:
|
|
52
|
+
if not sheet_rows:
|
|
53
|
+
return None
|
|
54
|
+
headers = sheet_rows[0]
|
|
55
|
+
for row in sheet_rows[1:]:
|
|
56
|
+
if not row:
|
|
57
|
+
continue
|
|
58
|
+
first = str(row[0]).strip() if row[0] is not None else ""
|
|
59
|
+
if first == match_value:
|
|
60
|
+
return {
|
|
61
|
+
base_url + str(headers[i]).strip(): row[i]
|
|
62
|
+
for i in range(1, len(headers))
|
|
63
|
+
if headers[i] is not None
|
|
64
|
+
}
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------
|
|
69
|
+
# Base class
|
|
70
|
+
# ---------------------------------------------------------------------
|
|
71
|
+
class _BaseExcelAttributeDataSource(AttributeGroupDataSource):
|
|
72
|
+
"""
|
|
73
|
+
Common mapping logic from Excel rows to AttributeGroup.
|
|
74
|
+
Subclasses implement `_read_rows_and_last_changed()`.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self, *, base_url: str = "", cache_duration_seconds: int = 0, **kwargs):
|
|
78
|
+
self._base_url = base_url
|
|
79
|
+
# allow instance-level TTL override
|
|
80
|
+
try:
|
|
81
|
+
_cache.ttl = int(cache_duration_seconds)
|
|
82
|
+
except Exception:
|
|
83
|
+
pass
|
|
84
|
+
super().__init__(**kwargs)
|
|
85
|
+
|
|
86
|
+
def is_static(self) -> bool:
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
def _read_rows_and_last_changed(self) -> Tuple[List[tuple], Optional[datetime]]:
|
|
90
|
+
raise NotImplementedError
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def provides_attributes(self) -> List[str]:
|
|
94
|
+
rows, _ = self._read_rows_and_last_changed()
|
|
95
|
+
if not rows:
|
|
96
|
+
return []
|
|
97
|
+
return [self._base_url + r for r in rows[0][1:]]
|
|
98
|
+
|
|
99
|
+
def attributes(self, pac_url: str) -> Optional[AttributeGroup]:
|
|
100
|
+
if not self._include_extensions:
|
|
101
|
+
pac_url = pac_url.split('*')[0]
|
|
102
|
+
rows, last_changed = self._read_rows_and_last_changed()
|
|
103
|
+
d = _get_row_by_first_cell(rows, pac_url, self._base_url)
|
|
104
|
+
if not d:
|
|
105
|
+
return None
|
|
106
|
+
attributes = [pyAttribute(key=k, value=v) for k, v in d.items()]
|
|
107
|
+
return AttributeGroup(
|
|
108
|
+
key=self._attribute_group_key,
|
|
109
|
+
attributes=pyAttributes(attributes).to_payload_attributes(),
|
|
110
|
+
state_of=last_changed,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# ---------------------------------------------------------------------
|
|
115
|
+
# Local file implementation
|
|
116
|
+
# ---------------------------------------------------------------------
|
|
117
|
+
class LocalExcelAttributeDataSource(_BaseExcelAttributeDataSource):
|
|
118
|
+
def __init__(self, file_path: str, **kwargs):
|
|
119
|
+
self._file_path = file_path
|
|
120
|
+
super().__init__(**kwargs)
|
|
121
|
+
|
|
122
|
+
@cached(_cache)
|
|
123
|
+
def _read_rows_and_last_changed(self) -> Tuple[List[tuple], Optional[datetime]]:
|
|
124
|
+
wb = load_workbook(filename=self._file_path, read_only=True, data_only=True)
|
|
125
|
+
ws = wb.active
|
|
126
|
+
rows = list(ws.iter_rows(values_only=True))
|
|
127
|
+
last_changed = wb.properties.modified
|
|
128
|
+
wb.close()
|
|
129
|
+
return rows, last_changed
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# # ---------------------------------------------------------------------
|
|
133
|
+
# # SharePoint/OneDrive (anonymous only)
|
|
134
|
+
# # ---------------------------------------------------------------------
|
|
135
|
+
# class SharePointExcelAttributeDataSource(_BaseExcelAttributeDataSource):
|
|
136
|
+
# """
|
|
137
|
+
# Anonymous 'anyone with the link' reader for SharePoint/OneDrive Excel.
|
|
138
|
+
# No MSAL, no AAD app permissions.
|
|
139
|
+
# """
|
|
140
|
+
|
|
141
|
+
# def __init__(self, url: str, *, timeout: int = 30, **kwargs):
|
|
142
|
+
# self._url = url
|
|
143
|
+
# self._timeout = timeout
|
|
144
|
+
# super().__init__(**kwargs)
|
|
145
|
+
|
|
146
|
+
# @cached(_cache)
|
|
147
|
+
# def _read_rows_and_last_changed(self) -> Tuple[List[tuple], Optional[datetime]]:
|
|
148
|
+
# content, last_changed = self._download_bytes_anon(self._url, timeout=self._timeout)
|
|
149
|
+
# with io.BytesIO(content) as fh:
|
|
150
|
+
# wb = load_workbook(filename=fh, read_only=True, data_only=True)
|
|
151
|
+
# ws = wb.active
|
|
152
|
+
# rows = list(ws.iter_rows(values_only=True))
|
|
153
|
+
# wb_last = wb.properties.modified # often None for streamed files
|
|
154
|
+
# wb.close()
|
|
155
|
+
# return rows, (wb_last or last_changed)
|
|
156
|
+
|
|
157
|
+
# def _download_bytes_anon(self, url: str, *, timeout: int) -> Tuple[bytes, Optional[datetime]]:
|
|
158
|
+
# u = _ensure_download_query(url)
|
|
159
|
+
# headers = {"User-Agent": "python-requests/anon-sharepoint-downloader"}
|
|
160
|
+
# resp = requests.get(u, headers=headers, timeout=timeout, allow_redirects=True)
|
|
161
|
+
# resp.raise_for_status()
|
|
162
|
+
|
|
163
|
+
# last = None
|
|
164
|
+
# lm_hdr = resp.headers.get("Last-Modified")
|
|
165
|
+
# if lm_hdr:
|
|
166
|
+
# try:
|
|
167
|
+
# last = parsedate_to_datetime(lm_hdr)
|
|
168
|
+
# if last.tzinfo is None:
|
|
169
|
+
# last = last.replace(tzinfo=timezone.utc)
|
|
170
|
+
# else:
|
|
171
|
+
# last = last.astimezone(timezone.utc)
|
|
172
|
+
# except Exception:
|
|
173
|
+
# last = None
|
|
174
|
+
# return resp.content, last
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
__all__ = [
|
|
180
|
+
"LocalExcelAttributeDataSource",
|
|
181
|
+
]
|
|
@@ -8,7 +8,7 @@ from pydantic import RootModel
|
|
|
8
8
|
from labfreed.labfreed_infrastructure import LabFREED_BaseModel
|
|
9
9
|
from labfreed.pac_attributes.api_data_models.response import AttributeBase, BoolAttribute, DateTimeAttribute, NumericAttribute, NumericValue, ObjectAttribute, ReferenceAttribute, TextAttribute
|
|
10
10
|
from labfreed.pac_id.pac_id import PAC_ID
|
|
11
|
-
from labfreed.trex.
|
|
11
|
+
from labfreed.trex.pythonic.quantity import Quantity
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class pyReference(RootModel[str]):
|
|
@@ -30,6 +30,7 @@ class pyAttribute(LabFREED_BaseModel):
|
|
|
30
30
|
class pyAttributes(RootModel[list[pyAttribute]]):
|
|
31
31
|
def to_payload_attributes(self) -> list[AttributeBase]:
|
|
32
32
|
return [self._attribute_to_attribute_payload_type(e) for e in self.root]
|
|
33
|
+
|
|
33
34
|
|
|
34
35
|
@staticmethod
|
|
35
36
|
def _attribute_to_attribute_payload_type(attribute:pyAttribute) -> AttributeBase:
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from labfreed.pac_attributes.pythonic.py_attributes import pyAttributes
|
|
2
|
+
from labfreed.pac_attributes.server.attribute_data_sources import Dict_DataSource
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class pyDict_DataSource(Dict_DataSource):
|
|
6
|
+
def __init__(self, data:dict[str, pyAttributes], *args, **kwargs):
|
|
7
|
+
if not all([isinstance(e, pyAttributes) for e in data.values()]):
|
|
8
|
+
raise ValueError('Invalid data')
|
|
9
|
+
d = {k: v.to_payload_attributes() for k,v in data.items()}
|
|
10
|
+
super().__init__(data=d, *args, **kwargs)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from labfreed.pac_attributes.server.server import AttributeServerRequestHandler
|
|
2
|
-
from labfreed.pac_attributes.server.attribute_data_sources import Dict_DataSource
|
|
3
|
-
from labfreed.pac_attributes.server.translation_data_sources import DictTranslationDataSource
|
|
1
|
+
from labfreed.pac_attributes.server.server import AttributeServerRequestHandler # noqa: F401
|
|
2
|
+
from labfreed.pac_attributes.server.attribute_data_sources import Dict_DataSource # noqa: F401
|
|
3
|
+
from labfreed.pac_attributes.server.translation_data_sources import DictTranslationDataSource # noqa: F401
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod, abstractproperty
|
|
2
2
|
from datetime import datetime, timezone
|
|
3
|
-
from labfreed.pac_attributes.api_data_models.response import VALID_FOREVER, AttributeGroup
|
|
4
|
-
from labfreed_extended.pac_attributes.py_attributes import pyAttributes
|
|
3
|
+
from labfreed.pac_attributes.api_data_models.response import VALID_FOREVER, AttributeBase, AttributeGroup
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
class AttributeGroupDataSource(ABC):
|
|
@@ -30,10 +29,11 @@ class AttributeGroupDataSource(ABC):
|
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
class Dict_DataSource(AttributeGroupDataSource):
|
|
33
|
-
def __init__(self, data:dict[str,
|
|
34
|
-
if not all([isinstance(e,
|
|
32
|
+
def __init__(self, data:dict[str, list[AttributeBase]], *args, **kwargs):
|
|
33
|
+
if not all([isinstance(e, list) for e in data.values()]):
|
|
35
34
|
raise ValueError('Invalid data')
|
|
36
|
-
|
|
35
|
+
|
|
36
|
+
self._data = data
|
|
37
37
|
self._state_of = datetime.now(tz=timezone.utc)
|
|
38
38
|
|
|
39
39
|
super().__init__(*args, **kwargs)
|
|
@@ -41,17 +41,16 @@ class Dict_DataSource(AttributeGroupDataSource):
|
|
|
41
41
|
|
|
42
42
|
@property
|
|
43
43
|
def provides_attributes(self):
|
|
44
|
-
return [a.key for attributes in self._data.values() for a in attributes
|
|
44
|
+
return [a.key for attributes in self._data.values() for a in attributes]
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def attributes(self, pac_url: str) -> AttributeGroup:
|
|
48
48
|
if not self._include_extensions:
|
|
49
49
|
pac_url = pac_url.split('*')[0]
|
|
50
50
|
|
|
51
|
-
attributes
|
|
51
|
+
attributes = self._data.get(pac_url)
|
|
52
52
|
if not attributes:
|
|
53
|
-
return None
|
|
54
|
-
attributes = attributes.to_payload_attributes()
|
|
53
|
+
return None
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
valid_until = VALID_FOREVER if self._is_static else None
|
|
@@ -4,7 +4,7 @@ import warnings
|
|
|
4
4
|
import rich
|
|
5
5
|
|
|
6
6
|
from labfreed.pac_attributes.api_data_models.request import AttributeRequestPayload
|
|
7
|
-
from labfreed.pac_attributes.api_data_models.response import AttributeResponsePayload,
|
|
7
|
+
from labfreed.pac_attributes.api_data_models.response import AttributeResponsePayload, AttributesOfPACID, ReferenceAttribute
|
|
8
8
|
from labfreed.pac_attributes.api_data_models.server_capabilities_response import ServerCapabilities
|
|
9
9
|
from labfreed.pac_attributes.server.attribute_data_sources import AttributeGroupDataSource
|
|
10
10
|
from labfreed.pac_attributes.server.translation_data_sources import TranslationDataSource
|
|
@@ -5,7 +5,7 @@ from typing import Union
|
|
|
5
5
|
from pydantic import BaseModel, Field, PrivateAttr, model_validator
|
|
6
6
|
|
|
7
7
|
from labfreed.utilities.base36 import base36
|
|
8
|
-
from labfreed.trex.
|
|
8
|
+
from labfreed.trex.pythonic.quantity import Quantity
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class DataTable(BaseModel):
|
|
@@ -6,10 +6,10 @@ from typing import Self
|
|
|
6
6
|
|
|
7
7
|
from pydantic import RootModel
|
|
8
8
|
from labfreed.well_known_keys.unece.unece_units import unece_unit
|
|
9
|
-
from labfreed.trex.
|
|
9
|
+
from labfreed.trex.pythonic.data_table import DataTable
|
|
10
10
|
from labfreed.utilities.base36 import from_base36, base36, to_base36
|
|
11
11
|
|
|
12
|
-
from labfreed.trex.
|
|
12
|
+
from labfreed.trex.pythonic.quantity import Quantity, unece_unit_code_from_quantity
|
|
13
13
|
from labfreed.trex.table_segment import ColumnHeader, TableSegment
|
|
14
14
|
from labfreed.trex.trex import TREX
|
|
15
15
|
from labfreed.trex.trex_base_models import AlphanumericValue, BinaryValue, BoolValue, DateValue, ErrorValue, NumericValue, TextValue
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: labfreed
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1a5
|
|
4
4
|
Summary: Python implementation of LabFREED building blocks
|
|
5
5
|
Author-email: Reto Thürer <thuerer.r@buchi.com>
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -24,7 +24,7 @@ Requires-Dist: PyYAML>=6.0.2
|
|
|
24
24
|
Requires-Dist: jsonpath-ng>=1.7.0
|
|
25
25
|
Requires-Dist: requests>=2.32.3
|
|
26
26
|
Requires-Dist: requests_cache>=1.2.1
|
|
27
|
-
Requires-Dist:
|
|
27
|
+
Requires-Dist: cachetools>=6.1.0
|
|
28
28
|
Requires-Dist: pytest>=8.3.5 ; extra == "dev"
|
|
29
29
|
Requires-Dist: pdoc>=15.0.1 ; extra == "dev"
|
|
30
30
|
Requires-Dist: flit>=3.12.0 ; extra == "dev"
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
labfreed/__init__.py,sha256=
|
|
1
|
+
labfreed/__init__.py,sha256=Gp9Q1dgFaKojedBoRsfKbL67CroxQPmGsZmKZrldqck,338
|
|
2
2
|
labfreed/labfreed_infrastructure.py,sha256=YZmU-kgopyB1tvpTR_k_uIt1Q2ezexMrWvu-HaP65IE,10104
|
|
3
|
-
labfreed/labfreed_extended/app/app_infrastructure.py,sha256=
|
|
4
|
-
labfreed/labfreed_extended/app/
|
|
5
|
-
labfreed/labfreed_extended/
|
|
6
|
-
labfreed/
|
|
7
|
-
labfreed/labfreed_extended/pac_attributes/server/excel_attribute_data_source.py,sha256=PM-C97bp2zZPDgtZtp0CNRXlOwyiWyLpvMVZPnsOo7U,4328
|
|
8
|
-
labfreed/labfreed_extended/utilities/formatted_print.py,sha256=DcwWP0ix1e_wYNIdceIp6cETkJdG2DqpU8Gs3aZAL40,1930
|
|
3
|
+
labfreed/labfreed_extended/app/app_infrastructure.py,sha256=kDWjxkLd9p9-RBMRtAUkg8rg2BHdQ8TltgkTWEm9G1U,4396
|
|
4
|
+
labfreed/labfreed_extended/app/formatted_print.py,sha256=DcwWP0ix1e_wYNIdceIp6cETkJdG2DqpU8Gs3aZAL40,1930
|
|
5
|
+
labfreed/labfreed_extended/app/pac_info.py,sha256=8_EC1YtBy1JsWtlrRW1gP6GK7aPdOO3AfLLUnwtiGvc,2601
|
|
6
|
+
labfreed/pac_attributes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
7
|
labfreed/pac_attributes/well_knonw_attribute_keys.py,sha256=ruHawnr1AffuhdKz1j1Nx67QphvcpmWsObgZhkuwkH0,318
|
|
10
8
|
labfreed/pac_attributes/api_data_models/request.py,sha256=x-GuFYhCIpqAKa1AHs968OfD8O2cJKg14YUw2hTKVg4,1871
|
|
11
9
|
labfreed/pac_attributes/api_data_models/response.py,sha256=czqQ59myLsN4WNgCdI_dnxRG8hSw4YI062XOPydfePU,5715
|
|
12
10
|
labfreed/pac_attributes/api_data_models/server_capabilities_response.py,sha256=ypDm4f8xZZl036fp8PuIe6lJHNW5Zg1fItgUlnV75V0,178
|
|
13
|
-
labfreed/pac_attributes/client/__init__.py,sha256=
|
|
11
|
+
labfreed/pac_attributes/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
12
|
labfreed/pac_attributes/client/attribute_cache.py,sha256=eWFy7h-T6gd25ENj9pLvSadNFRrzzIineqBoov2cGyw,2688
|
|
15
13
|
labfreed/pac_attributes/client/client.py,sha256=EdGWxi22DBx67-t_ICvm3YJGy0wwU1sMn4efwXtkvWg,6231
|
|
16
|
-
labfreed/pac_attributes/
|
|
17
|
-
labfreed/pac_attributes/
|
|
18
|
-
labfreed/pac_attributes/
|
|
14
|
+
labfreed/pac_attributes/pythonic/attribute_server_factory.py,sha256=1rRsZG-7Rm-kbxxj3vYMCfnagPw-uNxjylPKhYXf0ZA,3844
|
|
15
|
+
labfreed/pac_attributes/pythonic/excel_attribute_data_source.py,sha256=mS310M3UOKuv00mJsRAK7acfTdyOw9c-_9UHXKuAqvs,6923
|
|
16
|
+
labfreed/pac_attributes/pythonic/py_attributes.py,sha256=K9NTPH606cBepVKwyThbfGvd26WAzjbc5L64MTLKcV4,5134
|
|
17
|
+
labfreed/pac_attributes/pythonic/py_dict_data_source.py,sha256=nAz6GA7Xx_0IORPPpt_Wl3sFJa1Q5Fnq5vdf1uQiJF8,531
|
|
18
|
+
labfreed/pac_attributes/server/__init__.py,sha256=JvQ2kpQx62OUwP18bGhOWYU9an_nQW59Y8Lh7HyfVxY,301
|
|
19
|
+
labfreed/pac_attributes/server/attribute_data_sources.py,sha256=bCFqozKBEVdR8etRJjG9RCE5Uea9SMudPN4Mwh-iQr4,2083
|
|
20
|
+
labfreed/pac_attributes/server/server.py,sha256=0dM9BmL0u_6g8O-v7_tPRUj6og2LwlhrcPiDPFdp5Bo,10772
|
|
19
21
|
labfreed/pac_attributes/server/translation_data_sources.py,sha256=axALOqfP840sOSdVCRYtrens97mm-hpfONMUyuVlCrY,2145
|
|
20
22
|
labfreed/pac_cat/__init__.py,sha256=KNPtQzBD1XVohvG_ucOs7RJj-oi6biUTGB1k-T2o6pk,568
|
|
21
23
|
labfreed/pac_cat/category_base.py,sha256=nFa-y1IiTnPV1xz3RibqkEINISvP045329z8QgbsJ-4,2483
|
|
@@ -40,10 +42,10 @@ labfreed/trex/table_segment.py,sha256=qlItBK1x3Qr7KUSM_L6dcmv3Y2fNhiqTaiXbXm5BKs
|
|
|
40
42
|
labfreed/trex/trex.py,sha256=WDoPvuhiilLtRSIkntCmDGkFBnD6oRZg0E6hhoV-I2g,2400
|
|
41
43
|
labfreed/trex/trex_base_models.py,sha256=591559BISc82fyIoEP_dq_GHDbPCVzApx7FM3TRQPlY,7545
|
|
42
44
|
labfreed/trex/value_segments.py,sha256=_fbDHDRfo7pxIWpzcbyjppv1VNd8Tnd-VXhbd6igI8g,3698
|
|
43
|
-
labfreed/trex/
|
|
44
|
-
labfreed/trex/
|
|
45
|
-
labfreed/trex/
|
|
46
|
-
labfreed/trex/
|
|
45
|
+
labfreed/trex/pythonic/__init__.py,sha256=dyAQG7t-uYN6VfGXbWIq2bHxGcGI63l7FS2-VPYs2RQ,137
|
|
46
|
+
labfreed/trex/pythonic/data_table.py,sha256=KGyA5hRdDOOkJB0EOyjmzbbMusgYkBB_2SIFzrJ25yI,3148
|
|
47
|
+
labfreed/trex/pythonic/pyTREX.py,sha256=WZPp8pZIrlibiLBz2vnXZoJOnxjrJ4Vll9eA-w5K_Ks,10145
|
|
48
|
+
labfreed/trex/pythonic/quantity.py,sha256=CzK3kCXopTl11qOCirkaiThDvMN6m1FbpLMrsHy2NkI,5336
|
|
47
49
|
labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,2895
|
|
48
50
|
labfreed/utilities/ensure_utc_time.py,sha256=1ZTTzyIt7IimQ4ArTzdgw5hxiabkkplltbQe3Wdt2ZQ,307
|
|
49
51
|
labfreed/utilities/translations.py,sha256=XY4Wud_BfXswUOpebdh0U_D2bMzb2vqluuGWzFK-3uU,1851
|
|
@@ -57,7 +59,7 @@ labfreed/well_known_keys/labfreed/well_known_keys.py,sha256=p-hXwEEIs7p2SKn9DQeL
|
|
|
57
59
|
labfreed/well_known_keys/unece/UneceUnits.json,sha256=kwfQSp_nTuWbADfBBgqTWrvPl6XtM5SedEVLbMJrM7M,898953
|
|
58
60
|
labfreed/well_known_keys/unece/__init__.py,sha256=MSP9lmjg9_D9iqG9Yq2_ajYfQSNS9wIT7FXA1c--59M,122
|
|
59
61
|
labfreed/well_known_keys/unece/unece_units.py,sha256=J20d64H69qKDE3XlGdJoXIIh0G-d0jKoiIDsg9an5pk,1655
|
|
60
|
-
labfreed-0.3.
|
|
61
|
-
labfreed-0.3.
|
|
62
|
-
labfreed-0.3.
|
|
63
|
-
labfreed-0.3.
|
|
62
|
+
labfreed-0.3.1a5.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
|
|
63
|
+
labfreed-0.3.1a5.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
64
|
+
labfreed-0.3.1a5.dist-info/METADATA,sha256=w6gukW0c5-ctDkwyhbWbAPAFm-uZ-bUsKss-gW57wtM,19740
|
|
65
|
+
labfreed-0.3.1a5.dist-info/RECORD,,
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from urllib.parse import urlparse
|
|
5
|
-
from cachetools import TTLCache, cached
|
|
6
|
-
|
|
7
|
-
from labfreed.pac_attributes.api_data_models.response import AttributeGroup
|
|
8
|
-
from labfreed.pac_attributes.server.server import AttributeGroupDataSource
|
|
9
|
-
from labfreed.labfreed_extended.pac_attributes.py_attributes import pyAttribute, pyAttributes
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
try:
|
|
13
|
-
from openpyxl import load_workbook
|
|
14
|
-
except ImportError:
|
|
15
|
-
raise ImportError("Please install labfreed with the [extended] extra: pip install labfreed[extended]")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
cache = TTLCache(maxsize=128, ttl=0)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class ExcelAttributeDataSource(AttributeGroupDataSource):
|
|
22
|
-
'''
|
|
23
|
-
Demonstrates how to analyze the PAC-ID and it's extensions to provide some data
|
|
24
|
-
'''
|
|
25
|
-
def __init__(self, file_path:str, cache_duration_seconds:int=0, base_url:str="", *args, **kwargs):
|
|
26
|
-
self._file_path = file_path
|
|
27
|
-
self._base_url = base_url
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if is_sharepoint_url(file_path):
|
|
31
|
-
self._file_location = "sharepoint"
|
|
32
|
-
else:
|
|
33
|
-
self._file_location = "local"
|
|
34
|
-
|
|
35
|
-
super().__init__(*args, **kwargs)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def is_static(self) -> bool:
|
|
39
|
-
return False
|
|
40
|
-
|
|
41
|
-
@property
|
|
42
|
-
def provides_attributes(self):
|
|
43
|
-
if self._file_location == "local":
|
|
44
|
-
rows, last_changed = read_excel_openpyxl(self._file_path)
|
|
45
|
-
headers = [self._base_url + r for r in rows[0][1:] ]
|
|
46
|
-
elif self._file_location == "sharepoint":
|
|
47
|
-
raise NotImplementedError('Sharepoint Access not implemented')
|
|
48
|
-
return headers
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def attributes(self, pac_url: str) -> AttributeGroup:
|
|
52
|
-
if not self._include_extensions:
|
|
53
|
-
pac_url = pac_url.split('*')[0]
|
|
54
|
-
|
|
55
|
-
if self._file_location == "local":
|
|
56
|
-
rows, last_changed = read_excel_openpyxl(self._file_path)
|
|
57
|
-
elif self._file_location == "sharepoint":
|
|
58
|
-
raise NotImplementedError('Sharepoint Access not implemented')
|
|
59
|
-
|
|
60
|
-
d = get_row_by_first_cell(rows, pac_url, self._base_url)
|
|
61
|
-
if not d:
|
|
62
|
-
return None
|
|
63
|
-
|
|
64
|
-
attributes = [pyAttribute(key=k, value=v) for k,v in d.items()]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return AttributeGroup(key=self._attribute_group_key,
|
|
68
|
-
attributes=pyAttributes(attributes).to_payload_attributes(),
|
|
69
|
-
state_of=last_changed)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@cached(cache)
|
|
74
|
-
def read_excel_openpyxl(path: str, worksheet: str = None) -> list[tuple]:
|
|
75
|
-
"""
|
|
76
|
-
Read and cache Excel worksheet as list of rows (including headers),
|
|
77
|
-
then close the workbook.
|
|
78
|
-
"""
|
|
79
|
-
wb = load_workbook(filename=path, read_only=True, data_only=True)
|
|
80
|
-
ws = wb[worksheet] if worksheet else wb.active
|
|
81
|
-
|
|
82
|
-
rows = list(ws.iter_rows(values_only=True))
|
|
83
|
-
|
|
84
|
-
last_changed: datetime | None = wb.properties.modified
|
|
85
|
-
wb.close() # immediately release the file
|
|
86
|
-
|
|
87
|
-
return rows, last_changed # list of tuples (header + data rows)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def get_row_by_first_cell(sheet_rows: list[tuple], match_value: str, base_url:str) -> dict | None:
|
|
91
|
-
"""
|
|
92
|
-
Takes list of rows and returns the first row where the first cell == match_value,
|
|
93
|
-
as a dict using headers from the first row.
|
|
94
|
-
"""
|
|
95
|
-
if not sheet_rows:
|
|
96
|
-
return None
|
|
97
|
-
|
|
98
|
-
headers = sheet_rows[0]
|
|
99
|
-
for row in sheet_rows[1:]:
|
|
100
|
-
if not row:
|
|
101
|
-
continue
|
|
102
|
-
first = str(row[0]).strip() if row[0] is not None else ""
|
|
103
|
-
if first == match_value:
|
|
104
|
-
return {
|
|
105
|
-
base_url + str(headers[i]).strip(): row[i]
|
|
106
|
-
for i in range(1, len(headers))
|
|
107
|
-
if headers[i] is not None
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return None
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
def is_sharepoint_url(s: str) -> bool:
|
|
115
|
-
try:
|
|
116
|
-
parsed = urlparse(s)
|
|
117
|
-
if parsed.scheme not in {"http", "https"}:
|
|
118
|
-
return False
|
|
119
|
-
if "sharepoint.com" in parsed.netloc or "1drv.ms" in parsed.netloc:
|
|
120
|
-
return True
|
|
121
|
-
return False
|
|
122
|
-
except Exception:
|
|
123
|
-
return False
|
|
124
|
-
|
|
125
|
-
def is_local_path(s: str) -> bool:
|
|
126
|
-
if is_sharepoint_url(s):
|
|
127
|
-
return False
|
|
128
|
-
# Treat anything that's not a URL and points to an existing file as a local path
|
|
129
|
-
return os.path.exists(s)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|