ymf 0.3.0__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.
ymf/__init__.py ADDED
@@ -0,0 +1,149 @@
1
+ """YMF — YAML Modeling Format for computational physics.
2
+
3
+ Importing this package pulls in the **core** only: :mod:`ymf.archive` (the
4
+ archive data model and YAML I/O, needing just ``pyyaml``),
5
+ :mod:`ymf.xdmf` (the ``.xmf`` converter, stdlib-only), and
6
+ :mod:`ymf.normalize` (stdlib-only).
7
+
8
+ The validation stack is *not* imported eagerly. ``ymf.schema`` needs
9
+ ``strictyaml`` (``pip install ymf[spec]``) and ``ymf.units`` needs ``pint``
10
+ (``ymf[units]``); both are resolved on first attribute access via PEP 562,
11
+ so a solver that only writes archives never loads them and never needs them
12
+ installed. That is deliberate and load-bearing -- see the trust-boundary
13
+ section of :mod:`ymf.archive` -- so please don't turn these back into
14
+ module-level imports for tidiness.
15
+ """
16
+
17
+ from importlib.metadata import PackageNotFoundError, version as _version
18
+ from typing import Any
19
+
20
+ from ymf.archive import (
21
+ ARCHIVE_FORMAT_VERSION,
22
+ YmfArchiveError,
23
+ add_spatial_step,
24
+ add_uniform_step,
25
+ attribute,
26
+ canonicalize_approximation,
27
+ canonicalize_domain,
28
+ check_dimensions,
29
+ data_item,
30
+ data_item_for,
31
+ dump_grid,
32
+ geometry,
33
+ grid,
34
+ load_grid,
35
+ new_approximation,
36
+ new_domain,
37
+ read_ymf,
38
+ require_libyaml,
39
+ topology,
40
+ validate_approximation,
41
+ validate_domain,
42
+ write_ymf,
43
+ )
44
+ from ymf.normalize import (boundary_conditions, equations_in_order, normalize_equations,
45
+ normalize_unknowns)
46
+ from ymf.xdmf import (
47
+ build_xdmf_tree,
48
+ grid_element_time,
49
+ parse_grid_element,
50
+ read_xdmf,
51
+ round_trip_equal,
52
+ write_xdmf,
53
+ )
54
+
55
+ #: Attribute name -> (module, name within that module). Resolved lazily by
56
+ #: :func:`__getattr__` so that the heavy dependencies behind these modules
57
+ #: are only imported if something actually asks for them.
58
+ _LAZY_ATTRS = {
59
+ # ymf.schema -- requires strictyaml (ymf[spec])
60
+ "YMF_SCHEMA": ("ymf.schema", "YMF_SCHEMA"),
61
+ "load_ymf": ("ymf.schema", "load_ymf"),
62
+ "validate_ymf": ("ymf.schema", "validate_ymf"),
63
+ # ymf.units -- requires pint (ymf[units])
64
+ "check_units": ("ymf.units", "check"),
65
+ "non_dimensionalize": ("ymf.units", "non_dimensionalize"),
66
+ # ymf.data_sources -- stdlib only, but a front-end concern
67
+ "resolve_roughness_source": ("ymf.data_sources", "resolve_roughness_source"),
68
+ "validate_source_record": ("ymf.data_sources", "validate_source_record"),
69
+ }
70
+
71
+ #: Which extra to suggest when a lazy import fails for a missing dependency.
72
+ _EXTRA_FOR_MODULE = {"ymf.schema": "spec", "ymf.units": "units"}
73
+
74
+ __all__ = [
75
+ # --- core: archive model and YAML I/O ---
76
+ "ARCHIVE_FORMAT_VERSION",
77
+ "YmfArchiveError",
78
+ "new_approximation",
79
+ "add_uniform_step",
80
+ "add_spatial_step",
81
+ "grid",
82
+ "topology",
83
+ "geometry",
84
+ "attribute",
85
+ "data_item",
86
+ "data_item_for",
87
+ "canonicalize_approximation",
88
+ "validate_approximation",
89
+ "check_dimensions",
90
+ "write_ymf",
91
+ "read_ymf",
92
+ "dump_grid",
93
+ "load_grid",
94
+ "require_libyaml",
95
+ # the names before 2026-11, kept for one release
96
+ "new_domain",
97
+ "canonicalize_domain",
98
+ "validate_domain",
99
+ # --- core: XDMF conversion ---
100
+ "build_xdmf_tree",
101
+ "write_xdmf",
102
+ "read_xdmf",
103
+ "round_trip_equal",
104
+ "parse_grid_element",
105
+ "grid_element_time",
106
+ # --- core: stdlib helpers ---
107
+ "normalize_unknowns",
108
+ "normalize_equations",
109
+ "equations_in_order",
110
+ "boundary_conditions",
111
+ # --- lazy: front-end validation (see _LAZY_ATTRS) ---
112
+ *_LAZY_ATTRS,
113
+ ]
114
+
115
+
116
+ def __getattr__(name: str) -> Any:
117
+ """Resolve the front-end attributes in :data:`_LAZY_ATTRS` on demand."""
118
+ target = _LAZY_ATTRS.get(name)
119
+ if target is None:
120
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
121
+ module_name, attr_name = target
122
+ import importlib
123
+
124
+ try:
125
+ module = importlib.import_module(module_name)
126
+ except ImportError as exc:
127
+ extra = _EXTRA_FOR_MODULE.get(module_name)
128
+ if extra is None:
129
+ raise
130
+ raise ImportError(
131
+ f"ymf.{name} lives in {module_name}, which needs an optional "
132
+ f"dependency that isn't installed. Install it with: "
133
+ f"pip install 'ymf[{extra}]'. (The YMF core deliberately depends "
134
+ f"on pyyaml alone, so a solver writing archives doesn't have to "
135
+ f"carry the validation stack.)"
136
+ ) from exc
137
+ value = getattr(module, attr_name)
138
+ globals()[name] = value # cache, so this path runs at most once per name
139
+ return value
140
+
141
+
142
+ def __dir__() -> list:
143
+ return sorted(__all__)
144
+
145
+
146
+ try:
147
+ __version__ = _version("ymf")
148
+ except PackageNotFoundError:
149
+ __version__ = "0.0.0+unknown"