-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.py
executable file
·66 lines (47 loc) · 1.79 KB
/
release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env python3
import argparse
import os
import re
import sys
# pylint: disable=unspecified-encoding,missing-function-docstring
def cmd(sh_line):
print(sh_line)
if code := os.system(sh_line):
print("***Error", code, file=sys.stderr)
sys.exit(code)
def readfile(file):
with open(file) as f:
return f.read()
def writefile(file, text):
with open(file, "w") as f:
f.write(text)
a = argparse.ArgumentParser()
a.add_argument("version", help="release tag")
args = a.parse_args()
# Patch new version into files
pp_text = readfile("pyproject.toml")
writefile("pyproject.toml",
re.sub(r'version = "[\d.]+"',
f'version = "{args.version}"', pp_text))
init_text = readfile("schemascii/__init__.py")
writefile("schemascii/__init__.py",
re.sub(r'__version__ = "[\d.]+"',
f'__version__ = "{args.version}"', init_text))
cmd("python3 -m build --sdist")
cmd("python3 -m build --wheel")
cmd("schemascii test_data/test_charge_pump.txt --out test_data/test_charge_pump.txt.svg")
print("for some reason convert isn't working with the css, so aborting the auto-rendering")
sys.exit(0)
cmd("convert test_data/test_charge_pump.txt.svg test_data/test_charge_pump.png")
svg_content = readfile("test_data/test_charge_pump.txt.svg")
css_content = readfile("schemascii_example.css")
writefile("test_data/test_charge_pump_css.txt.svg",
svg_content.replace("</svg>", f'<style>{css_content}</style></svg>'))
cmd("convert test_data/test_charge_pump_css.txt.svg test_data/test_charge_pump_css.png")
# cmd("git add -A")
# cmd("git commit -m 'blah'")
# cmd(f"git tag {args.version}")
# cmd("git push --tags")
# sudo apt update && sudo apt install imagemagick
# for convert command
# doesn't seem to work with the css though :(