Skip to content

Commit 82916cb

Browse files
committed
generate_symbols.py: switched from contextlib to subprocess
Signed-off-by: Grzegorz Latosinski <[email protected]>
1 parent 85c95cf commit 82916cb

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,12 @@
1919

2020

2121
import sys
22-
import symbolator
2322
import argparse
2423
from pathlib import Path
2524
import errno
2625
import contextlib
2726
import traceback
28-
29-
30-
@contextlib.contextmanager
31-
def redirect_argv(args):
32-
sys._argv = sys.argv
33-
sys.argv = args
34-
yield
35-
sys.argv = sys._argv
27+
import subprocess
3628

3729

3830
def main(argv):
@@ -108,20 +100,23 @@ def main(argv):
108100
print(f'The {out_filename} already exists')
109101
return errno.EEXIST
110102

111-
arguments = (f'--libname {libname} --title -t -o {out_filename}' +
112-
f' --output-as-filename -i {str(symbol_v_file)}' +
113-
' --format svg')
114-
with redirect_argv(arguments.split(' ')):
115-
try:
116-
symbolator.main()
117-
except Exception:
118-
print(
119-
f'Failed to run: symbolator {arguments}',
120-
file=sys.stderr
121-
)
122-
print('Error message:\n', file=sys.stderr)
123-
traceback.print_exc()
124-
err.write(f'{symbol_v_file}\n')
103+
program = ('symbolator' +
104+
f' --libname {libname} --title -t -o {out_filename}' +
105+
f' --output-as-filename -i {str(symbol_v_file)}' +
106+
' --format svg')
107+
res = subprocess.run(
108+
program.split(' '),
109+
stdout=subprocess.PIPE,
110+
stderr=subprocess.STDOUT
111+
)
112+
if res.returncode != 0:
113+
print(
114+
f'Failed to run: {program}',
115+
file=sys.stderr
116+
)
117+
print('STDOUT:\n', file=sys.stderr)
118+
print(res.stdout.decode())
119+
err.write(f'{symbol_v_file}\n')
125120
return 0
126121

127122

0 commit comments

Comments
 (0)