|
3 | 3 | import re
|
4 | 4 | import sys
|
5 | 5 |
|
| 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 | + |
6 | 24 | a = argparse.ArgumentParser("release.py")
|
7 | 25 | a.add_argument("version", help="release tag")
|
8 | 26 | args = a.parse_args()
|
9 | 27 |
|
10 | 28 | # 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)) |
22 | 32 |
|
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)) |
28 | 36 |
|
29 | 37 |
|
30 | 38 | cmd("python3 -m build --sdist")
|
31 | 39 | 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 :( |
0 commit comments