gemd 2.0.0__tar.gz → 2.1.1__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.
- {gemd-2.0.0 → gemd-2.1.1}/PKG-INFO +3 -1
- gemd-2.1.1/gemd/__version__.py +1 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/cake.py +2 -4
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/strehlow_and_cook.py +2 -3
- {gemd-2.0.0 → gemd-2.1.1}/gemd/units/impl.py +97 -54
- {gemd-2.0.0 → gemd-2.1.1}/gemd.egg-info/PKG-INFO +3 -1
- {gemd-2.0.0 → gemd-2.1.1}/gemd.egg-info/requires.txt +2 -0
- {gemd-2.0.0 → gemd-2.1.1}/setup.py +3 -1
- gemd-2.0.0/gemd/__version__.py +0 -1
- {gemd-2.0.0 → gemd-2.1.1}/LICENSE +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/README.md +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/builders/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/builders/impl.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/material_run_example.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/measurement_example.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/strehlow_and_cook.pif +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/strehlow_and_cook_small.pif +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/table_example.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/demo/toothpick.jpg +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/base_attribute.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/condition.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/parameter.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/property.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/attribute/property_and_conditions.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/base_entity.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/base_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/categorical_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/composition_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/integer_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/molecular_structure_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds/real_bounds.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/bounds_validation.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/case_insensitive_dict.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/dict_serializable.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/file_link.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/has_dependencies.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/link_by_uid.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/base_object.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_conditions.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_material.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_parameters.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_process.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_properties.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_quantities.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_source.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_spec.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/has_template_check_generator.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/ingredient_run.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/ingredient_spec.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/material_run.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/material_spec.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/measurement_run.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/measurement_spec.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/process_run.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/object/process_spec.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/setters.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/source/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/source/performed_source.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/attribute_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/base_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/condition_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/has_condition_templates.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/has_parameter_templates.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/has_property_templates.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/material_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/measurement_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/parameter_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/process_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/template/property_template.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/util.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/valid_list.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/base_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/categorical_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/composition_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/continuous_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/discrete_categorical.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/empirical_formula.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/inchi_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/integer_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/molecular_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/nominal_categorical.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/nominal_composition.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/nominal_integer.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/nominal_real.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/normal_real.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/smiles_value.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/uniform_integer.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/entity/value/uniform_real.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/enumeration/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/enumeration/base_enumeration.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/enumeration/origin.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/enumeration/sample_type.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/json/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/json/gemd_encoder.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/json/gemd_json.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/units/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/units/citrine_en.txt +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/units/constants_en.txt +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/util/__init__.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd/util/impl.py +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd.egg-info/SOURCES.txt +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd.egg-info/dependency_links.txt +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/gemd.egg-info/top_level.txt +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/setup.cfg +0 -0
- {gemd-2.0.0 → gemd-2.1.1}/tests/test_examples.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gemd
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: Python binding for Citrine's GEMD data model
|
|
5
5
|
Home-page: http://github.com/CitrineInformatics/gemd-python
|
|
6
6
|
Author: Citrine Informatics
|
|
@@ -14,6 +14,8 @@ Requires-Python: >=3.8
|
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: pint<0.24,>=0.20
|
|
16
16
|
Requires-Dist: deprecation<3,>=2.1.0
|
|
17
|
+
Requires-Dist: typing_extensions<5,>=4.8
|
|
18
|
+
Requires-Dist: importlib-resources<7,>=5.3
|
|
17
19
|
Provides-Extra: tests
|
|
18
20
|
Requires-Dist: pytest<9,>=8.0.0; extra == "tests"
|
|
19
21
|
Provides-Extra: tests-demo
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.1.1"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Bake a cake."""
|
|
2
|
+
from importlib_resources import files
|
|
2
3
|
from io import BytesIO
|
|
3
4
|
import random
|
|
4
5
|
|
|
@@ -67,10 +68,7 @@ def get_template_scope():
|
|
|
67
68
|
|
|
68
69
|
def import_toothpick_picture() -> BytesIO:
|
|
69
70
|
"""Return the stream of the toothpick picture."""
|
|
70
|
-
|
|
71
|
-
resource = read_binary("gemd.demo", "toothpick.jpg")
|
|
72
|
-
|
|
73
|
-
return BytesIO(resource)
|
|
71
|
+
return files("gemd.demo").joinpath("toothpick.jpg").open("rb")
|
|
74
72
|
|
|
75
73
|
|
|
76
74
|
def make_cake_templates():
|
|
@@ -45,11 +45,10 @@ __all__ = [
|
|
|
45
45
|
|
|
46
46
|
def import_table(filename=SMALL_TABLE):
|
|
47
47
|
"""Return the deserialized JSON table."""
|
|
48
|
-
from
|
|
48
|
+
from importlib_resources import files
|
|
49
49
|
import json
|
|
50
|
-
table = json.loads(read_text("gemd.demo", filename))
|
|
51
50
|
|
|
52
|
-
return
|
|
51
|
+
return json.loads(files("gemd.demo").joinpath(filename).read_text())
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
def _fingerprint(row):
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"""Implementation of units."""
|
|
2
|
+
from deprecation import deprecated
|
|
2
3
|
import functools
|
|
3
|
-
from
|
|
4
|
+
from importlib_resources import files
|
|
4
5
|
import os
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
import re
|
|
7
8
|
from tempfile import TemporaryDirectory
|
|
8
9
|
from typing import Union, List, Tuple, Generator, Any
|
|
9
10
|
|
|
10
|
-
from pint import UnitRegistry,
|
|
11
|
+
from pint import UnitRegistry, register_unit_format
|
|
11
12
|
try: # Pint 0.23 migrated the location of this method, and augmented it
|
|
12
13
|
from pint.pint_eval import tokenizer
|
|
13
14
|
except ImportError: # pragma: no cover
|
|
@@ -27,18 +28,19 @@ __all__ = [
|
|
|
27
28
|
]
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
def _deploy_default_files() ->
|
|
31
|
+
def _deploy_default_files() -> Tuple[Path, Path]:
|
|
31
32
|
"""Copy the units & constants file into a temporary directory."""
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
resources = files("gemd.units")
|
|
34
|
+
target_dir = Path(_TEMP_DIRECTORY.name)
|
|
35
|
+
target_paths = tuple(target_dir / f for f in ("citrine_en.txt", "constants_en.txt"))
|
|
36
|
+
for target in target_paths:
|
|
37
|
+
source = resources.joinpath(target.name)
|
|
38
|
+
target.write_text(source.read_text(), encoding="utf-8")
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
constants_path.write_text(read_text("gemd.units", "constants_en.txt"), encoding="utf-8")
|
|
40
|
+
return target_paths
|
|
37
41
|
|
|
38
|
-
return str(units_path)
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
DEFAULT_FILE = _deploy_default_files()
|
|
43
|
+
DEFAULT_FILE, DEFAULT_CONSTANTS = _deploy_default_files()
|
|
42
44
|
_ALLOWED_OPERATORS = {".", "+", "-", "*", "/", "//", "^", "**", "(", ")"}
|
|
43
45
|
|
|
44
46
|
|
|
@@ -131,6 +133,7 @@ def _scaling_identify_factors(
|
|
|
131
133
|
"""
|
|
132
134
|
todo = []
|
|
133
135
|
for block in blocks:
|
|
136
|
+
# Note: while Python does not recognize ^ as exponentiation, pint does
|
|
134
137
|
i_exp = next((i for i, t in enumerate(block) if t.string in {"**", "^"}), len(block))
|
|
135
138
|
i_name = next((i for i, t in enumerate(block) if t.type == NAME), None)
|
|
136
139
|
numbers = [(i, t.string) for i, t in enumerate(block) if t.type == NUMBER and i < i_exp]
|
|
@@ -168,10 +171,14 @@ def _scaling_store_and_mangle(input_string: str, todo: List[Tuple[str, str, str]
|
|
|
168
171
|
"""
|
|
169
172
|
for scaled_term, number_string, unit_string in todo:
|
|
170
173
|
regex = rf"(?<![-+0-9.]){re.escape(scaled_term)}(?![0-9.])"
|
|
171
|
-
stripped = re.sub(
|
|
174
|
+
stripped = re.sub(
|
|
175
|
+
r"(?<=\d)_(?=\d)", "", re.sub(r"[+\s]+", "", scaled_term).replace("--", "")
|
|
176
|
+
)
|
|
172
177
|
|
|
173
178
|
if unit_string is not None:
|
|
174
|
-
stripped_unit = re.sub(
|
|
179
|
+
stripped_unit = re.sub(
|
|
180
|
+
r"(?<!0)(?=\.)", "0", re.sub(r"[+\s]+", "", unit_string)
|
|
181
|
+
).replace("--", "")
|
|
175
182
|
long_unit = f"{_REGISTRY.parse_units(stripped_unit)}"
|
|
176
183
|
short_unit = f"{_REGISTRY.parse_units(stripped_unit):~}"
|
|
177
184
|
long = stripped.replace(stripped_unit, "_" + long_unit)
|
|
@@ -201,7 +208,58 @@ def _scaling_preprocessor(input_string: str) -> str:
|
|
|
201
208
|
return _scaling_store_and_mangle(input_string, todo)
|
|
202
209
|
|
|
203
210
|
|
|
204
|
-
|
|
211
|
+
def _unmangle_scaling(input_string: str) -> str:
|
|
212
|
+
"""Convert mangled scaling values into a pint-compatible expression."""
|
|
213
|
+
number_re = r'\b_(_)?(\d+)(_\d+)?([eE]_?\d+)?(_(?=[a-zA-Z]))?'
|
|
214
|
+
while match := re.search(number_re, input_string):
|
|
215
|
+
replacement = '' if match.group(1) is None else '-'
|
|
216
|
+
replacement += match.group(2)
|
|
217
|
+
replacement += '' if match.group(3) is None else match.group(3).replace('_', '.')
|
|
218
|
+
replacement += '' if match.group(4) is None else match.group(4).replace('_', '-')
|
|
219
|
+
replacement += '' if match.group(5) is None else match.group(5).replace('_', ' ')
|
|
220
|
+
input_string = input_string.replace(match.group(0), replacement)
|
|
221
|
+
return input_string
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
try: # pragma: no cover
|
|
225
|
+
# Pint 0.23 modified the preferred way to derive a custom class
|
|
226
|
+
# https://pint.readthedocs.io/en/0.23/advanced/custom-registry-class.html
|
|
227
|
+
from pint.registry import GenericUnitRegistry
|
|
228
|
+
from typing_extensions import TypeAlias
|
|
229
|
+
|
|
230
|
+
class _ScaleFactorUnit(UnitRegistry.Unit):
|
|
231
|
+
"""Child class of Units for generating units w/ clean scaling factors."""
|
|
232
|
+
|
|
233
|
+
def __format__(self, format_spec):
|
|
234
|
+
result = super().__format__(format_spec)
|
|
235
|
+
return _unmangle_scaling(result)
|
|
236
|
+
|
|
237
|
+
class _ScaleFactorQuantity(UnitRegistry.Quantity):
|
|
238
|
+
"""Child class of Quantity for generating units w/ clean scaling factors."""
|
|
239
|
+
|
|
240
|
+
pass
|
|
241
|
+
|
|
242
|
+
class _ScaleFactorRegistry(GenericUnitRegistry[_ScaleFactorQuantity, _ScaleFactorUnit]):
|
|
243
|
+
"""UnitRegistry class that uses _GemdUnits."""
|
|
244
|
+
|
|
245
|
+
Quantity: TypeAlias = _ScaleFactorQuantity
|
|
246
|
+
Unit: TypeAlias = _ScaleFactorUnit
|
|
247
|
+
|
|
248
|
+
except ImportError: # pragma: no cover
|
|
249
|
+
# https://pint.readthedocs.io/en/0.21/advanced/custom-registry-class.html
|
|
250
|
+
class _ScaleFactorUnit(UnitRegistry.Unit):
|
|
251
|
+
"""Child class of Units for generating units w/ clean scaling factors."""
|
|
252
|
+
|
|
253
|
+
def __format__(self, format_spec):
|
|
254
|
+
result = super().__format__(format_spec)
|
|
255
|
+
return _unmangle_scaling(result)
|
|
256
|
+
|
|
257
|
+
class _ScaleFactorRegistry(UnitRegistry):
|
|
258
|
+
"""UnitRegistry class that uses _GemdUnits."""
|
|
259
|
+
|
|
260
|
+
_unit_class = _ScaleFactorUnit
|
|
261
|
+
|
|
262
|
+
_REGISTRY: _ScaleFactorRegistry = None # global requires it be defined in this scope
|
|
205
263
|
|
|
206
264
|
|
|
207
265
|
@functools.lru_cache(maxsize=1024 * 1024)
|
|
@@ -244,38 +302,23 @@ def convert_units(value: float, starting_unit: str, final_unit: str) -> float:
|
|
|
244
302
|
|
|
245
303
|
|
|
246
304
|
@register_unit_format("clean")
|
|
305
|
+
@deprecated(deprecated_in="2.1.0", removed_in="3.0.0", details="Scaling factor clean-up ")
|
|
247
306
|
def _format_clean(unit, registry, **options):
|
|
248
|
-
"""
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
for
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if p == 1:
|
|
257
|
-
numerator.append(u)
|
|
258
|
-
elif p > 0:
|
|
259
|
-
numerator.append(f"{u} ** {p}")
|
|
260
|
-
elif p == -1:
|
|
261
|
-
denominator.append(u)
|
|
262
|
-
elif p < 0:
|
|
263
|
-
denominator.append(f"{u} ** {-p}")
|
|
264
|
-
|
|
265
|
-
if len(numerator) == 0:
|
|
266
|
-
numerator = ["1"]
|
|
267
|
-
|
|
268
|
-
if len(denominator) > 0:
|
|
269
|
-
return " / ".join((" * ".join(numerator), " / ".join(denominator)))
|
|
270
|
-
else:
|
|
271
|
-
return " * ".join(numerator)
|
|
307
|
+
"""
|
|
308
|
+
DEPRECATED Formatter that turns scaling-factor-units into numbers again.
|
|
309
|
+
|
|
310
|
+
Responsibility for this piece of clean-up has been shifted to a custom class.
|
|
311
|
+
|
|
312
|
+
"""
|
|
313
|
+
from pint.formatting import _FORMATTERS
|
|
314
|
+
return _FORMATTERS["D"](unit, registry, **options)
|
|
272
315
|
|
|
273
316
|
|
|
274
317
|
@functools.lru_cache(maxsize=1024)
|
|
275
|
-
def parse_units(units: Union[str, Unit, None],
|
|
318
|
+
def parse_units(units: Union[str, UnitRegistry.Unit, None],
|
|
276
319
|
*,
|
|
277
320
|
return_unit: bool = False
|
|
278
|
-
) -> Union[str, Unit, None]:
|
|
321
|
+
) -> Union[str, UnitRegistry.Unit, None]:
|
|
279
322
|
"""
|
|
280
323
|
Parse a string or Unit into a standard string representation of the unit.
|
|
281
324
|
|
|
@@ -298,19 +341,20 @@ def parse_units(units: Union[str, Unit, None],
|
|
|
298
341
|
else:
|
|
299
342
|
return None
|
|
300
343
|
elif isinstance(units, str):
|
|
301
|
-
|
|
344
|
+
# SPT-1311 Protect against leaked mangled strings
|
|
345
|
+
parsed = _REGISTRY.parse_units(_unmangle_scaling(units))
|
|
302
346
|
if return_unit:
|
|
303
347
|
return parsed
|
|
304
348
|
else:
|
|
305
|
-
return f"{parsed
|
|
306
|
-
elif isinstance(units, Unit):
|
|
349
|
+
return f"{parsed}"
|
|
350
|
+
elif isinstance(units, UnitRegistry.Unit):
|
|
307
351
|
return units
|
|
308
352
|
else:
|
|
309
353
|
raise UndefinedUnitError("Units must be given as a recognized unit string or Units object")
|
|
310
354
|
|
|
311
355
|
|
|
312
356
|
@functools.lru_cache(maxsize=1024)
|
|
313
|
-
def get_base_units(units: Union[str, Unit]) -> Tuple[Unit, float, float]:
|
|
357
|
+
def get_base_units(units: Union[str, UnitRegistry.Unit]) -> Tuple[UnitRegistry.Unit, float, float]:
|
|
314
358
|
"""
|
|
315
359
|
Get the base units and conversion factors for the given unit.
|
|
316
360
|
|
|
@@ -350,21 +394,20 @@ def change_definitions_file(filename: str = None):
|
|
|
350
394
|
if filename is None:
|
|
351
395
|
target = DEFAULT_FILE
|
|
352
396
|
else:
|
|
353
|
-
# TODO: Handle case where user provides a units file but no constants file
|
|
354
397
|
target = Path(filename).expanduser().resolve(strict=True)
|
|
355
398
|
|
|
356
399
|
current_dir = Path.cwd()
|
|
357
400
|
try:
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
_REGISTRY =
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
401
|
+
os.chdir(target.parent)
|
|
402
|
+
# Need to re-verify path because of some slippiness around tmp on macOS
|
|
403
|
+
updated = (Path.cwd() / target.name).resolve(strict=True)
|
|
404
|
+
_REGISTRY = _ScaleFactorRegistry(filename=updated,
|
|
405
|
+
preprocessors=[_space_after_minus_preprocessor,
|
|
406
|
+
_scientific_notation_preprocessor,
|
|
407
|
+
_scaling_preprocessor
|
|
408
|
+
],
|
|
409
|
+
autoconvert_offset_to_baseunit=True
|
|
410
|
+
)
|
|
368
411
|
finally:
|
|
369
412
|
os.chdir(current_dir)
|
|
370
413
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gemd
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: Python binding for Citrine's GEMD data model
|
|
5
5
|
Home-page: http://github.com/CitrineInformatics/gemd-python
|
|
6
6
|
Author: Citrine Informatics
|
|
@@ -14,6 +14,8 @@ Requires-Python: >=3.8
|
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: pint<0.24,>=0.20
|
|
16
16
|
Requires-Dist: deprecation<3,>=2.1.0
|
|
17
|
+
Requires-Dist: typing_extensions<5,>=4.8
|
|
18
|
+
Requires-Dist: importlib-resources<7,>=5.3
|
|
17
19
|
Provides-Extra: tests
|
|
18
20
|
Requires-Dist: pytest<9,>=8.0.0; extra == "tests"
|
|
19
21
|
Provides-Extra: tests-demo
|
gemd-2.0.0/gemd/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.0.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|