hestia-earth-utils 0.15.3__py3-none-any.whl → 0.15.5__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.
@@ -144,8 +144,9 @@ def get_node_value(
144
144
  )] if isinstance(value, list) and len(value) > 0 else None
145
145
 
146
146
  return reducer(value) if reducer else (
147
- value if any([isinstance(value, float), isinstance(value, int), isinstance(value, bool)])
148
- else (value or default)
147
+ value if any([isinstance(value, float), isinstance(value, int), isinstance(value, bool)]) else
148
+ default if value is None else
149
+ value
149
150
  )
150
151
 
151
152
 
@@ -25,7 +25,7 @@ class NpEncoder(json.JSONEncoder):
25
25
  return super(NpEncoder, self).default(obj)
26
26
 
27
27
 
28
- def to_string(data: dict): return json.dumps(data, ensure_ascii=False, cls=NpEncoder)
28
+ def to_string(data: dict, indent: int = None): return json.dumps(data, indent=indent, ensure_ascii=False, cls=NpEncoder)
29
29
 
30
30
 
31
31
  def to_bytes(data: dict): return to_string(data).encode('utf8')
@@ -156,15 +156,15 @@ def _node_id(node: dict): return node.get('@id', node.get('id'))
156
156
  def _node_path(node: dict, folder: str = ''): return join(folder, _node_type(node), f"{_node_id(node)}.jsonld")
157
157
 
158
158
 
159
- def is_calculating(bucket: str, node: dict):
160
- return _read_metadata(bucket, _node_path(node)).get(METADATA_PROGRESS_KEY, 'false') == 'true'
159
+ def is_calculating(bucket: str, node: dict, folder: str = ''):
160
+ return _read_metadata(bucket, _node_path(node, folder)).get(METADATA_PROGRESS_KEY, 'false') == 'true'
161
161
 
162
162
 
163
- def set_calculating(bucket: str, node: dict, in_progress: bool):
164
- return _update_metadata(bucket, _node_path(node), {METADATA_PROGRESS_KEY: str(in_progress).lower()})
163
+ def set_calculating(bucket: str, node: dict, in_progress: bool, folder: str = ''):
164
+ return _update_metadata(bucket, _node_path(node, folder), {METADATA_PROGRESS_KEY: str(in_progress).lower()})
165
165
 
166
166
 
167
- def get_stage(bucket: str, node: dict):
167
+ def get_stage(bucket: str, node: dict, folder: str = CALC_FOLDER):
168
168
  stage = _read_metadata(bucket, _node_path(node, folder=CALC_FOLDER)).get(METADATA_STAGE_KEY)
169
169
  return int(stage) if stage else stage
170
170
 
@@ -0,0 +1,31 @@
1
+ import json
2
+ from functools import lru_cache
3
+ from typing import Union
4
+ from hestia_earth.schema import TermTermType
5
+
6
+ from .storage import _load_from_storage
7
+ from .api import download_hestia
8
+
9
+
10
+ @lru_cache()
11
+ def _load_term_file(term_type: str):
12
+ try:
13
+ filepath = f"glossary/{term_type}.json"
14
+ nodes = json.loads(_load_from_storage(filepath, glossary=True))
15
+ return {node.get('@id'): node for node in nodes}
16
+ except Exception:
17
+ return {}
18
+
19
+
20
+ def download_term(term: Union[str, dict], termType: Union[str, TermTermType] = None):
21
+ """
22
+ Download a Term, using the glossary file if available, or default to the standard download.
23
+ """
24
+ term_id = term.get('@id', term.get('id')) if isinstance(term, dict) else term
25
+ term_type = (
26
+ termType if isinstance(termType, str) else termType.value
27
+ ) if termType else (
28
+ term.get('termType') if isinstance(term, dict) else None
29
+ )
30
+ cached_nodes = _load_term_file(term_type) if term_type else {}
31
+ return cached_nodes.get(term_id) or download_hestia(term_id)
@@ -1 +1 @@
1
- VERSION = '0.15.3'
1
+ VERSION = '0.15.5'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hestia-earth-utils
3
- Version: 0.15.3
3
+ Version: 0.15.5
4
4
  Summary: HESTIA's utils library
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-utils
6
6
  Author: HESTIA Team
@@ -1,7 +1,7 @@
1
1
  hestia_earth/__init__.py,sha256=G-d438vPx7m_ks5e9XTtM3u7LDRO5dSSukibukWmyPM,56
2
2
  hestia_earth/utils/__init__.py,sha256=qEFeq3yuf3lQKVseALmL8aPM8fpCS54B_5pry00M3hk,76
3
3
  hestia_earth/utils/api.py,sha256=y0gw5pCCHNnFIhM62Hok_5eDtH3QDAZdkye_1mANMNs,9654
4
- hestia_earth/utils/blank_node.py,sha256=8BeKKzKRZXvwMpJ13p41kVL7KAju9tY1Le_RUmca2Ig,7320
4
+ hestia_earth/utils/blank_node.py,sha256=COmhDWc9mdk2EyXJIQHw_reGM_0Drs1Onh4lNP8rxa4,7345
5
5
  hestia_earth/utils/calculation_status.py,sha256=X7lbgVMD9luH1gj9lEcxd3_P2-u7e8ZPGCvX1czPZUo,2238
6
6
  hestia_earth/utils/cycle.py,sha256=rFLRL9X4KQ1UrE6fEPA_gV8KmwzrZpR3Ce56zg41lRk,1326
7
7
  hestia_earth/utils/date.py,sha256=SPQ69uxHiv1o3BqIkBKkM5XX_CmS20CB7g6u2rhsdh8,1807
@@ -10,12 +10,13 @@ hestia_earth/utils/emission.py,sha256=crHAJOQRI0NRHht0fFOFjEqcarsFqzbV4pDgk90dfM
10
10
  hestia_earth/utils/lookup.py,sha256=0RLqy3HPzkbhkRaO7fYoHU0jKhAYzI6QHMptMEbqTlg,10344
11
11
  hestia_earth/utils/lookup_utils.py,sha256=9pkJUKo3NEBspoN9yRPoDCzkxcbpnbLpC7Z0I6HiP7I,5369
12
12
  hestia_earth/utils/model.py,sha256=uUcrF07XmBzqLni8VSaP0HoebJnQ57kk0EOmhwYMbfI,4637
13
- hestia_earth/utils/pipeline.py,sha256=tTAyyJlpNsq7zdNeE-1ETBWv1PFwvCHntMh_JtHXdoo,9163
13
+ hestia_earth/utils/pipeline.py,sha256=KDA1PBimFIUJKVytbxaXh33QGFW55I-2kcVDCRbYxn4,9277
14
14
  hestia_earth/utils/request.py,sha256=bu7hkWKmFdXl2_Feawiam_x32whlclA9oP0asJyC69k,626
15
15
  hestia_earth/utils/stats.py,sha256=4t3op10xDJbGxWJEY1Jtyl302PYWyMFwLpsSkMlzQn8,34667
16
16
  hestia_earth/utils/table.py,sha256=RrTt-KF_QzjKiCpaAueoG6La1FG-Iusxw5NMDpoRBpQ,2861
17
+ hestia_earth/utils/term.py,sha256=6LiUSc6KX3IOkfWF6fYkQ2tENCO8ENljcdDypxU6WtA,1060
17
18
  hestia_earth/utils/tools.py,sha256=eCppZ0gFR6RPF7TEraMLwLJnUCJb93xP0iEzFPcYpK0,4685
18
- hestia_earth/utils/version.py,sha256=hLVHxDXaHRJkp3GyxChJ7hdO6Bfi56LSrfl3kHEh7ds,19
19
+ hestia_earth/utils/version.py,sha256=pY2Xj289NO4A3rIbFygWGENP2l3wteL9fyCFESz8zI0,19
19
20
  hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
21
  hestia_earth/utils/pivot/_shared.py,sha256=sRE_PGe9u0-sFnCb0mdeM7vPOkFWt3-kDs8WSGQTQGk,875
21
22
  hestia_earth/utils/pivot/pivot_csv.py,sha256=Ed-sCKEqVIFJu71AncS7zlMkHbw5V15QLd5c5B_uxiE,12296
@@ -25,12 +26,12 @@ hestia_earth/utils/storage/_azure_client.py,sha256=sevCZni04eknMql2DgUsWG23f7u0K
25
26
  hestia_earth/utils/storage/_local_client.py,sha256=IbzziUKY0QS3ybHFfgEpELqvafa7hQnZ-DdGdjQuypE,515
26
27
  hestia_earth/utils/storage/_s3_client.py,sha256=sR_HkvNmDFpLYislSUw1nffHicznCcPo1p_5cve2ExU,2216
27
28
  hestia_earth/utils/storage/_sns_client.py,sha256=LowUatj78Egu6_Id6Rr7hZjfZx1WguS3lozB3yAwSps,347
28
- hestia_earth_utils-0.15.3.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
29
- hestia_earth_utils-0.15.3.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
29
+ hestia_earth_utils-0.15.5.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
30
+ hestia_earth_utils-0.15.5.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
30
31
  tests/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
32
  tests/pivot/test_pivot_csv.py,sha256=aYni7o3QDPSgtVxVCspEetotgpYHY7Lz5VHf-DR89gw,8131
32
33
  tests/pivot/test_pivot_json.py,sha256=UYTAN4AZhzVicIYsU1A2VgJcctUXohjHppg6s-pqwcg,8287
33
- hestia_earth_utils-0.15.3.dist-info/METADATA,sha256=-q7en-j-NiVkaxpr40KNmAlpDRtC26-G6eQ37td17JI,1757
34
- hestia_earth_utils-0.15.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
35
- hestia_earth_utils-0.15.3.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
36
- hestia_earth_utils-0.15.3.dist-info/RECORD,,
34
+ hestia_earth_utils-0.15.5.dist-info/METADATA,sha256=EbkWkjevuBFHeiPK6aBme7mppB5H0HsN0cooulyOK_w,1757
35
+ hestia_earth_utils-0.15.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
36
+ hestia_earth_utils-0.15.5.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
37
+ hestia_earth_utils-0.15.5.dist-info/RECORD,,