Skip to content

Commit 992ebd7

Browse files
fix a few bugs
- use unicode for characters instead of entities - use fixed values instead of data-attributes and calc() which are not widely supported
1 parent 5f01e89 commit 992ebd7

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

release.py

+42-20
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,55 @@
33
import re
44
import sys
55

6+
7+
def cmd(sh_line):
8+
print(sh_line)
9+
if code := os.system(sh_line):
10+
print("***Exit", code, file=sys.stderr)
11+
sys.exit(code)
12+
13+
14+
def readfile(file):
15+
with open(file) as f:
16+
return f.read()
17+
18+
19+
def writefile(file, text):
20+
with open(file, "w") as f:
21+
f.write(text)
22+
23+
624
a = argparse.ArgumentParser("release.py")
725
a.add_argument("version", help="release tag")
826
args = a.parse_args()
927

1028
# Patch new version into files
11-
with open("pyproject.toml") as pyproject:
12-
pp_text = pyproject.read()
13-
with open("pyproject.toml", "w") as pyproject:
14-
pyproject.write(
15-
re.sub(r'version = "[\d.]+"', f'version = "{args.version}"', pp_text))
16-
17-
with open("schemascii/__init__.py") as init:
18-
init_text = init.read()
19-
with open("schemascii/__init__.py", "w") as init:
20-
init.write(
21-
re.sub(r'__version__ = "[\d.]+"', f'__version__ = "{args.version}"', init_text))
29+
pp_text = readfile("pyproject.toml")
30+
writefile("pyproject.toml",
31+
re.sub(r'version = "[\d.]+"', f'version = "{args.version}"', pp_text))
2232

23-
24-
def cmd(sh_line):
25-
print(sh_line)
26-
if os.system(sh_line):
27-
sys.exit(1)
33+
init_text = readfile("schemascii/__init__.py")
34+
writefile("schemascii/__init__.py",
35+
re.sub(r'__version__ = "[\d.]+"', f'__version__ = "{args.version}"', init_text))
2836

2937

3038
cmd("python3 -m build --sdist")
3139
cmd("python3 -m build --wheel")
32-
print("git add -A")
33-
print("git commit -m 'blah'")
34-
print(f"git tag {args.version}")
35-
print("git push --tags")
40+
cmd("schemascii test_data/test_charge_pump.txt --out test_data/test_charge_pump.txt.svg --padding 30")
41+
cmd("convert test_data/test_charge_pump.txt.svg test_data/test_charge_pump.png")
42+
43+
svg_content = readfile("test_data/test_charge_pump.txt.svg")
44+
css_content = readfile("schemascii_example.css")
45+
writefile("test_data/test_charge_pump.txt.svg",
46+
svg_content.replace("</svg>", f'<style>{css_content}</style></svg>'))
47+
cmd("convert test_data/test_charge_pump.txt.svg test_data/test_charge_pump_css.png")
48+
writefile("test_data/test_charge_pump.txt.svg", svg_content)
49+
50+
# cmd("git add -A")
51+
# cmd("git commit -m 'blah'")
52+
# cmd(f"git tag {args.version}")
53+
# cmd("git push --tags")
54+
55+
# sudo apt update && sudo apt install imagemagick
56+
# for convert command
57+
# doesn't seem to work with the css though :(

schemascii/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def render(filename: str, text: str = None, **options) -> str:
6060
f'{grid.height * scale + padding * 2}',
6161
xmlns="http://www.w3.org/2000/svg",
6262
class_="schemascii",
63-
data__scale=scale,
6463
)
6564

6665

schemascii/components_render.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def resistor(
107107
return (polylinegon(points, **options)
108108
+ make_variable(mid, angle, "V" in box.type, **options)
109109
+ id_text(
110-
box, bom_data, terminals, (("&ohm;", False), ("W", False)),
110+
box, bom_data, terminals, (("Ω", False), ("W", False)),
111111
text_pt, **options))
112112

113113

schemascii/metric.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def prefix_to_exponent(prefix: int) -> str:
2525
E.g. "u" --> -6 (micro)"""
2626
if prefix in (' ', ''):
2727
return 0
28+
if prefix == "µ":
29+
prefix = "u" # allow unicode
2830
if prefix == 'K':
2931
prefix = prefix.lower() # special case (preferred is lowercase)
3032
i = "pnum kMG".index(prefix)
@@ -59,7 +61,7 @@ def format_metric_unit(num: str, unit: str = '', six: bool = False) -> str:
5961
exp, digits = sorted(possibilities, key=lambda x: len(
6062
x[1]) + (0.5 * ('.' in x[1])))[0]
6163
out = digits + " " + exponent_to_prefix(exp) + unit
62-
return out.replace(" u", " &micro;")
64+
return out.replace(" u", " µ")
6365

6466

6567
if __name__ == '__main__':

schemascii_example.css

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
svg.schemascii {
22
background: black;
33

4-
--sch-scale: attr(data-scale);
54
}
65

76
svg.schemascii .wire line {
87
stroke: var(--sch-color, blue);
9-
stroke-width: calc(0.15 * var(--sch-scale, 1));
8+
stroke-width: 2;
109
stroke-linecap: round;
1110
transition-duration: 0.2s;
1211
}
@@ -22,14 +21,14 @@ svg.schemascii :is(.wire, .component):hover {
2221

2322
svg.schemascii .component :is(polyline, path, line, polygon, rect, circle) {
2423
stroke: var(--sch-color, red);
25-
stroke-width: calc(0.15 * var(--sch-scale, 1));
24+
stroke-width: 2;
2625
stroke-linecap: round;
2726
transition-duration: 0.2s;
2827
fill: transparent;
2928
}
3029

3130
svg.schemascii .component .plus :is(polyline, path, line) {
32-
stroke-width: calc(0.075 * var(--sch-scale, 1));
31+
stroke-width: 1;
3332
}
3433

3534
svg.schemascii .component polygon {

test_data/test_charge_pump.txt.svg

+1-1
Loading

0 commit comments

Comments
 (0)