sciform 0.33.0__py3-none-any.whl → 0.34.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.
sciform/user_options.py DELETED
@@ -1,188 +0,0 @@
1
- """UserOptions Dataclass which stores user input."""
2
-
3
-
4
- from __future__ import annotations
5
-
6
- from dataclasses import InitVar, asdict, dataclass
7
- from typing import get_args
8
-
9
- from sciform import global_options, modes
10
- from sciform.rendered_options import RenderedOptions
11
-
12
-
13
- @dataclass(frozen=True)
14
- class UserOptions:
15
- """Dataclass storing user input."""
16
-
17
- exp_mode: modes.ExpMode | None = None
18
- exp_val: int | type(modes.AutoExpVal) | None = None
19
- round_mode: modes.RoundMode | None = None
20
- ndigits: int | type(modes.AutoDigits) | None = None
21
- upper_separator: modes.UpperSeparators | None = None
22
- decimal_separator: modes.DecimalSeparators | None = None
23
- lower_separator: modes.LowerSeparators | None = None
24
- sign_mode: modes.SignMode | None = None
25
- left_pad_char: modes.LeftPadChar | None = None
26
- left_pad_dec_place: int | None = None
27
- exp_format: modes.ExpFormat | None = None
28
- extra_si_prefixes: dict[int, str] | None = None
29
- extra_iec_prefixes: dict[int, str] | None = None
30
- extra_parts_per_forms: dict[int, str] | None = None
31
- capitalize: bool | None = None
32
- superscript: bool | None = None
33
- nan_inf_exp: bool | None = None
34
- paren_uncertainty: bool | None = None
35
- pdg_sig_figs: bool | None = None
36
- left_pad_matching: bool | None = None
37
- paren_uncertainty_separators: bool | None = None
38
- pm_whitespace: bool | None = None
39
-
40
- add_c_prefix: InitVar[bool] = False
41
- add_small_si_prefixes: InitVar[bool] = False
42
- add_ppth_form: InitVar[bool] = False
43
-
44
- def __post_init__(
45
- self: UserOptions,
46
- add_c_prefix: bool, # noqa: FBT001
47
- add_small_si_prefixes: bool, # noqa: FBT001
48
- add_ppth_form: bool, # noqa: FBT001
49
- ) -> None:
50
- self.populate_dicts(
51
- add_c_prefix=add_c_prefix,
52
- add_small_si_prefixes=add_small_si_prefixes,
53
- add_ppth_form=add_ppth_form,
54
- )
55
- self.validate(self)
56
-
57
- def populate_dicts( # noqa: C901
58
- self: UserOptions,
59
- *,
60
- add_c_prefix: bool,
61
- add_small_si_prefixes: bool,
62
- add_ppth_form: bool,
63
- ) -> None:
64
- """Populate extra prefix translations from user input flags."""
65
- if add_c_prefix:
66
- if self.extra_si_prefixes is None:
67
- super().__setattr__("extra_si_prefixes", {})
68
- if -2 not in self.extra_si_prefixes:
69
- self.extra_si_prefixes[-2] = "c"
70
-
71
- if add_small_si_prefixes:
72
- if self.extra_si_prefixes is None:
73
- super().__setattr__("extra_si_prefixes", {})
74
- if -2 not in self.extra_si_prefixes:
75
- self.extra_si_prefixes[-2] = "c"
76
- if -1 not in self.extra_si_prefixes:
77
- self.extra_si_prefixes[-1] = "d"
78
- if +1 not in self.extra_si_prefixes:
79
- self.extra_si_prefixes[+1] = "da"
80
- if +2 not in self.extra_si_prefixes:
81
- self.extra_si_prefixes[+2] = "h"
82
-
83
- if add_ppth_form:
84
- if self.extra_parts_per_forms is None:
85
- super().__setattr__("extra_parts_per_forms", {})
86
- if -3 not in self.extra_parts_per_forms:
87
- self.extra_parts_per_forms[-3] = "ppth"
88
-
89
- @staticmethod
90
- def validate(options: UserOptions | RenderedOptions) -> None:
91
- """Validate user inputs."""
92
- if (
93
- options.round_mode == "sig_fig"
94
- and isinstance(options.ndigits, int)
95
- and options.ndigits < 1
96
- ):
97
- msg = f"ndigits must be >= 1 for sig fig rounding, not {options.ndigits}."
98
- raise ValueError(msg)
99
-
100
- if options.exp_val is not modes.AutoExpVal and options.exp_val is not None:
101
- if options.exp_mode in ["fixed_point", "percent"] and options.exp_val != 0:
102
- msg = (
103
- f"Exponent must must be 0, not exp_val={options.exp_val}, for "
104
- f"fixed point and percent exponent modes."
105
- )
106
- raise ValueError(msg)
107
- if (
108
- options.exp_mode in ["engineering", "engineering_shifted"]
109
- and options.exp_val % 3 != 0
110
- ):
111
- msg = (
112
- f"Exponent must be a multiple of 3, not exp_val={options.exp_val}, "
113
- f"for engineering exponent modes."
114
- )
115
- raise ValueError(msg)
116
- if options.exp_mode == "binary_iec" and options.exp_val % 10 != 0:
117
- msg = (
118
- f"Exponent must be a multiple of 10, not "
119
- f"exp_val={options.exp_val}, for binary IEC exponent mode."
120
- )
121
- raise ValueError(msg)
122
-
123
- UserOptions.validate_separators(options)
124
-
125
- @staticmethod
126
- def validate_separators(options: UserOptions | RenderedOptions) -> None:
127
- """Validate separator user input."""
128
- if options.upper_separator is not None:
129
- if options.upper_separator not in get_args(modes.UpperSeparators):
130
- msg = (
131
- f"upper_separator must be in "
132
- f"{get_args(modes.UpperSeparators)}, not "
133
- f"{options.upper_separator}."
134
- )
135
- raise ValueError(msg)
136
- if options.upper_separator == options.decimal_separator:
137
- msg = (
138
- f"upper_separator and decimal_separator "
139
- f"({options.upper_separator}) cannot be equal."
140
- )
141
- raise ValueError(msg)
142
-
143
- if options.decimal_separator is not None and (
144
- options.decimal_separator not in get_args(modes.DecimalSeparators)
145
- ):
146
- msg = (
147
- f"decimal_separator must be in "
148
- f"{get_args(modes.DecimalSeparators)}, not "
149
- f"{options.decimal_separator}."
150
- )
151
- raise ValueError(msg)
152
-
153
- if options.lower_separator is not None and (
154
- options.lower_separator not in get_args(modes.LowerSeparators)
155
- ):
156
- msg = (
157
- f"lower_separator must be in {get_args(modes.LowerSeparators)}, "
158
- f"not {options.lower_separator}."
159
- )
160
- raise ValueError(msg)
161
-
162
- def render(self: UserOptions) -> RenderedOptions:
163
- """Render UserOptions into RenderedOptions."""
164
- key_to_enum_dict = {
165
- "exp_mode": modes.ExpModeEnum,
166
- "round_mode": modes.RoundModeEnum,
167
- "upper_separator": modes.SeparatorEnum,
168
- "decimal_separator": modes.SeparatorEnum,
169
- "lower_separator": modes.SeparatorEnum,
170
- "sign_mode": modes.SignModeEnum,
171
- "left_pad_char": modes.LeftPadCharEnum,
172
- "exp_format": modes.ExpFormatEnum,
173
- }
174
-
175
- global_defaults_dict = asdict(global_options.GLOBAL_DEFAULT_OPTIONS)
176
- kwargs = {}
177
- for key, value in asdict(self).items():
178
- if value is None:
179
- rendered_value = global_defaults_dict[key]
180
- elif isinstance(value, str):
181
- enum = key_to_enum_dict[key]
182
- rendered_value = modes.mode_str_to_enum(value, enum)
183
- else:
184
- rendered_value = value
185
- kwargs[key] = rendered_value
186
- rendered_options = RenderedOptions(**kwargs)
187
- self.validate(rendered_options)
188
- return rendered_options
@@ -1,19 +0,0 @@
1
- sciform/__init__.py,sha256=wlDN6uPm7XjcbFzDA9l7m_twcT59DkBWtox_Pss-j0k,558
2
- sciform/format_utils.py,sha256=JNFlSxxM9K3M1KI5oLyTsPPzAsvgKDQAGgxPN3wqG_I,16545
3
- sciform/formatter.py,sha256=-G7HkH3bBPAtJ-gUw3tSgLXe6P6KUgL-Nif0sIJUeu4,13050
4
- sciform/formatting.py,sha256=aniYpOZK2TnPdk3sD9qvSXqIE-o6ydOEFmA_N20Sz6g,9034
5
- sciform/fsml.py,sha256=cJW3K-bPlgUd3ias5k2b3h5bdS15Sz8zq038z9If9uc,3365
6
- sciform/global_configuration.py,sha256=iCU22Bx_CjVBcnCQ_fTu_kNH8j9Ze_9Qqx_64YTHuDo,6744
7
- sciform/global_options.py,sha256=wJ9Qc728grkCx8hQ_d_rPjbTkhXSgRcywI7nQCUQNSI,936
8
- sciform/grouping.py,sha256=1hZjjVKRUy477LGGFniZwwEHHBDaSb6E0K3SAeCACVY,1641
9
- sciform/modes.py,sha256=8slohyIPHeAdgq3aszoNq9RJl6ibageFqDMxeC9NhrQ,3893
10
- sciform/output_conversion.py,sha256=bWTblhNUZZdjefdDec93jPYCna4AbSRfFfP7ouTtoXQ,5485
11
- sciform/prefix.py,sha256=1rJeKMs8m97V3ZvMzHikqXLDDINp9aEK0AI3YaCcRMw,596
12
- sciform/rendered_options.py,sha256=_Y7rO3s9j2d2S_U32eSwgwLFm8jdqHLrjDTdKpm5hig,1573
13
- sciform/scinum.py,sha256=H29BrxPYakGkdAKmrCYnj91g0u6c_fym5Kh-kNsnNy8,1926
14
- sciform/user_options.py,sha256=7XMLsE0x8mOL6IM-wJXQBb-fspm21vHQtpfqIfV5rrA,7390
15
- sciform-0.33.0.dist-info/LICENSE,sha256=-oyCEZu-6HLrRSfRg44uuNDE0c59GVEdqYIgidqSP70,1056
16
- sciform-0.33.0.dist-info/METADATA,sha256=mtFu4oLLl9rS7Q_vMgW89tcyHMs3gur_BZ_g_NuKSTI,7837
17
- sciform-0.33.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
18
- sciform-0.33.0.dist-info/top_level.txt,sha256=mC01YOQ-1u5pDk9BJia-pQKLUMvkreMsldDpFcp7NV8,8
19
- sciform-0.33.0.dist-info/RECORD,,