stringcalc 0.1.0.dev2__py3-none-any.whl → 0.1.0.dev4__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.
- stringcalc/__init__.py +1 -1
- stringcalc/cli.py +42 -10
- stringcalc/frets.py +1 -1
- stringcalc/tension.py +9 -2
- {stringcalc-0.1.0.dev2.dist-info → stringcalc-0.1.0.dev4.dist-info}/METADATA +3 -3
- stringcalc-0.1.0.dev4.dist-info/RECORD +10 -0
- stringcalc-0.1.0.dev2.dist-info/RECORD +0 -10
- {stringcalc-0.1.0.dev2.dist-info → stringcalc-0.1.0.dev4.dist-info}/LICENSE +0 -0
- {stringcalc-0.1.0.dev2.dist-info → stringcalc-0.1.0.dev4.dist-info}/WHEEL +0 -0
- {stringcalc-0.1.0.dev2.dist-info → stringcalc-0.1.0.dev4.dist-info}/entry_points.txt +0 -0
stringcalc/__init__.py
CHANGED
stringcalc/cli.py
CHANGED
|
@@ -3,6 +3,7 @@ CLI
|
|
|
3
3
|
"""
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
+
import functools
|
|
6
7
|
import re
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
|
|
@@ -31,9 +32,9 @@ def _to_fancy_sci(s: str) -> str:
|
|
|
31
32
|
return f"{a}×10{b}"
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
def error(s: str, *, rc: int = 1) -> None:
|
|
35
|
+
def error(s: str, *, rc: int = 1, markup: bool = True) -> None:
|
|
35
36
|
"""Print error message."""
|
|
36
|
-
console.print(s, style=Style(color="red", bold=True), highlight=False)
|
|
37
|
+
console.print(s, style=Style(color="red", bold=True), highlight=False, markup=markup)
|
|
37
38
|
assert rc != 0
|
|
38
39
|
raise typer.Exit(rc)
|
|
39
40
|
|
|
@@ -43,6 +44,26 @@ def info(s: str) -> None:
|
|
|
43
44
|
console.print(s, style=Style(color="cyan", bold=True), highlight=False)
|
|
44
45
|
|
|
45
46
|
|
|
47
|
+
def warning(s: str) -> None:
|
|
48
|
+
"""Print warning message."""
|
|
49
|
+
console.print(s, style=Style(color="red", bold=False), highlight=False)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def pretty_warnings(f):
|
|
53
|
+
"""Decorator to catch warnings and pretty-print them with Rich after running `f`."""
|
|
54
|
+
import warnings
|
|
55
|
+
|
|
56
|
+
@functools.wraps(f)
|
|
57
|
+
def inner(*args, **kwargs):
|
|
58
|
+
with warnings.catch_warnings(record=True) as w:
|
|
59
|
+
f(*args, **kwargs)
|
|
60
|
+
|
|
61
|
+
for i in range(len(w)):
|
|
62
|
+
warning(f"- {w[i].message}")
|
|
63
|
+
|
|
64
|
+
return inner
|
|
65
|
+
|
|
66
|
+
|
|
46
67
|
def _version_callback(show: bool):
|
|
47
68
|
if show:
|
|
48
69
|
import subprocess
|
|
@@ -140,7 +161,7 @@ def pprint_table(df, *, title: str, float_format: str) -> None:
|
|
|
140
161
|
@app.command()
|
|
141
162
|
def frets(
|
|
142
163
|
N: int = typer.Option(
|
|
143
|
-
|
|
164
|
+
17, "-N", "--number", help="Number of frets, starting from nut (fret 0)."
|
|
144
165
|
),
|
|
145
166
|
L: float = typer.Option(..., "-L", "--scale-length", help="Scale length."),
|
|
146
167
|
float_format: str = typer.Option(r"%.3f", help="Format for float-to-string conversion."),
|
|
@@ -155,7 +176,7 @@ def frets(
|
|
|
155
176
|
pprint_table(df, title=f"Fret distances for L={L}", float_format=float_format)
|
|
156
177
|
|
|
157
178
|
|
|
158
|
-
_RE_LENGTH_SPEC = re.compile(r"(?P<a>[0-
|
|
179
|
+
_RE_LENGTH_SPEC = re.compile(r"(?P<a>[0-9]+|[ns])-(?P<b>[0-9]+|[ns])=(?P<d>[0-9e\.\+\-\.]+)")
|
|
159
180
|
|
|
160
181
|
|
|
161
182
|
def _ab_interp(s: str) -> int | None:
|
|
@@ -192,15 +213,25 @@ def length(
|
|
|
192
213
|
|
|
193
214
|
m = _RE_LENGTH_SPEC.fullmatch(spec)
|
|
194
215
|
if m is None:
|
|
195
|
-
error(
|
|
216
|
+
error(
|
|
217
|
+
f"Input failed to match a-b=d spec format regex {_RE_LENGTH_SPEC.pattern!r}",
|
|
218
|
+
rc=2,
|
|
219
|
+
markup=False,
|
|
220
|
+
)
|
|
196
221
|
|
|
197
222
|
assert m is not None
|
|
198
223
|
dct = m.groupdict()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
try:
|
|
225
|
+
a = _ab_interp(dct["a"])
|
|
226
|
+
b = _ab_interp(dct["b"])
|
|
227
|
+
d = float(dct["d"])
|
|
228
|
+
except ValueError as e:
|
|
229
|
+
error(f"Failed to convert input to frets. Message: {e}", rc=2)
|
|
230
|
+
|
|
231
|
+
try:
|
|
232
|
+
res = length_from_distance((a, b), d)
|
|
233
|
+
except ValueError as e:
|
|
234
|
+
error(f"Failed to compute scale length. Message: {e}", rc=2)
|
|
204
235
|
|
|
205
236
|
if round_ is not None:
|
|
206
237
|
res = round(float(res), round_)
|
|
@@ -218,6 +249,7 @@ def length(
|
|
|
218
249
|
|
|
219
250
|
|
|
220
251
|
@app.command(name="gauge")
|
|
252
|
+
@pretty_warnings
|
|
221
253
|
def gauge_(
|
|
222
254
|
T: float = typer.Option(..., "-T", "--tension", help="Desired tension"),
|
|
223
255
|
L: float = typer.Option(..., "-L", "--length", help="String length (scale length)."),
|
stringcalc/frets.py
CHANGED
stringcalc/tension.py
CHANGED
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import math
|
|
11
11
|
import re
|
|
12
|
+
import warnings
|
|
12
13
|
from functools import lru_cache
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
from typing import NamedTuple
|
|
@@ -254,9 +255,15 @@ def suggest_gauge(
|
|
|
254
255
|
data_sort["T"] = T_all[data_sort.index]
|
|
255
256
|
data_sort["dT"] = data_sort["T"] - T
|
|
256
257
|
|
|
257
|
-
# TODO:
|
|
258
|
+
b = 1.7 # TODO: allow to set this?
|
|
259
|
+
if (data_sort["dT"] > b).all() or (data_sort["dT"] < -b).all():
|
|
260
|
+
warnings.warn(
|
|
261
|
+
f"You are outside the range of what string type group(s) {types} can provide. "
|
|
262
|
+
"Maybe a different string type can give the tension/pitch/length you desire.",
|
|
263
|
+
stacklevel=2,
|
|
264
|
+
)
|
|
258
265
|
|
|
259
|
-
df = data_sort[["id", "T", "dT"]].sort_values(by="
|
|
266
|
+
df = data_sort[["id", "T", "dT"]].sort_values(by="dT").reset_index(drop=True)
|
|
260
267
|
desc = {
|
|
261
268
|
"id": "Product ID",
|
|
262
269
|
"T": "Tension",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stringcalc
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev4
|
|
4
4
|
Summary: Calculations for instrument strings
|
|
5
5
|
Author-email: zmoon <zmoon92@gmail.com>
|
|
6
6
|
Requires-Python: ~=3.8
|
|
@@ -24,12 +24,12 @@ Provides-Extra: test
|
|
|
24
24
|
|
|
25
25
|
# stringcalc
|
|
26
26
|
|
|
27
|
+
*Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings*
|
|
28
|
+
|
|
27
29
|
[](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
|
|
28
30
|
[](https://pypi.org/project/stringcalc/)
|
|
29
31
|
[](https://www.repostatus.org/#wip)
|
|
30
32
|
|
|
31
|
-
Calculations for instrument strings
|
|
32
|
-
|
|
33
33
|
## Prior art
|
|
34
34
|
|
|
35
35
|
### Web apps
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
stringcalc/__init__.py,sha256=03RMhmcDxIWvr9JrJdiPNw2nVpTibhKaGfzqpVEFRLI,77
|
|
2
|
+
stringcalc/cli.py,sha256=7vIR_RTjpUCy9R1Be6KkqApqn1uTUdmxekAz-atQuhg,9724
|
|
3
|
+
stringcalc/frets.py,sha256=jypfP1CteKQR-8Q5v2_bB71zb7RDsWbn2HQBEYmFyRU,3545
|
|
4
|
+
stringcalc/tension.py,sha256=nIZWJtinswSPG0j2krr6MPJjPHpjACqE6k_xvWwofdw,8501
|
|
5
|
+
stringcalc/data/daddario-tension.csv,sha256=syYZsCI-btdGo85XrcbgsmwdMETPT9IgQ--uOuQhs_Y,124809
|
|
6
|
+
stringcalc-0.1.0.dev4.dist-info/entry_points.txt,sha256=0DV5ry2A4YzcRzPmWKPXWSFG_dd2rE1Q17UORWHN9vI,49
|
|
7
|
+
stringcalc-0.1.0.dev4.dist-info/LICENSE,sha256=QJZDkt5nq7Pto8WzgmPHKnpeTyEyyqscYUFlKoyXgZg,1090
|
|
8
|
+
stringcalc-0.1.0.dev4.dist-info/WHEEL,sha256=rSgq_JpHF9fHR1lx53qwg_1-2LypZE_qmcuXbVUq948,81
|
|
9
|
+
stringcalc-0.1.0.dev4.dist-info/METADATA,sha256=vtGmKCIOp-DhRKm5afbsGauJTeCLnQFMRdK-Fk-qLJk,4905
|
|
10
|
+
stringcalc-0.1.0.dev4.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
stringcalc/__init__.py,sha256=zxfOgQDx_TsA49HE7SxNpqT-rZzwpj3R5PrvSmspZA8,77
|
|
2
|
-
stringcalc/cli.py,sha256=5pPZTfRDZlbWF3N1sIyzAUJWzJpx_IHGbnkYUlOhyOM,8805
|
|
3
|
-
stringcalc/frets.py,sha256=sSfgdX3DCpx5gORzT759XH3mVahctQv09MgKVOBffeM,3521
|
|
4
|
-
stringcalc/tension.py,sha256=U-nAM-mfYzn9ALaLCxL6K24SX26FnbiV9OQou--n72c,8178
|
|
5
|
-
stringcalc/data/daddario-tension.csv,sha256=syYZsCI-btdGo85XrcbgsmwdMETPT9IgQ--uOuQhs_Y,124809
|
|
6
|
-
stringcalc-0.1.0.dev2.dist-info/entry_points.txt,sha256=0DV5ry2A4YzcRzPmWKPXWSFG_dd2rE1Q17UORWHN9vI,49
|
|
7
|
-
stringcalc-0.1.0.dev2.dist-info/LICENSE,sha256=QJZDkt5nq7Pto8WzgmPHKnpeTyEyyqscYUFlKoyXgZg,1090
|
|
8
|
-
stringcalc-0.1.0.dev2.dist-info/WHEEL,sha256=rSgq_JpHF9fHR1lx53qwg_1-2LypZE_qmcuXbVUq948,81
|
|
9
|
-
stringcalc-0.1.0.dev2.dist-info/METADATA,sha256=OPf-rLp4nft9Bh6t2eITsYhcuJ5_hp0ooHzTiXADTCw,4843
|
|
10
|
-
stringcalc-0.1.0.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|