Skip to content

Commit

Permalink
bnet2primes: improves error message #111
Browse files Browse the repository at this point in the history
  • Loading branch information
hklarner committed May 16, 2024
1 parent c9c78c3 commit 5ae3bc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
15 changes: 13 additions & 2 deletions pyboolnet/cli/commands/trap_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@
@click.option("-o", "--fname-trap-spaces", default="", help="file name to save trap spaces")
@click.argument("fname-bnet")
def command_trap_spaces(type_: str, max_output: int, fname_asp: str, representation: str, fname_bnet: str, fname_primes: str, fname_trap_spaces: str):
primes = compute_primes_or_exit(fname_bnet=fname_bnet, fname_primes=fname_primes)
trap_spaces = compute_trap_spaces(primes=primes, type_=type_, max_output=max_output, representation=representation, fname_asp=fname_asp)
primes = compute_primes_or_exit(
fname_bnet=fname_bnet,
fname_primes=fname_primes,
)
trap_spaces = compute_trap_spaces(
primes=primes,
type_=type_,
max_output=max_output,
representation=representation,
fname_asp=fname_asp,
)

lines = [str(x) for x in trap_spaces]
for x in lines[:3]:
click.echo(x)

click.echo(f"found {len(lines)} trap spaces.")

if fname_trap_spaces:
Expand Down
4 changes: 2 additions & 2 deletions pyboolnet/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

def compute_primes_or_exit(fname_bnet: str, fname_primes: str) -> dict:
if not os.path.isfile(fname_bnet):
click.echo(f"file does not exist: fname_bnet={fname_bnet}")
sys.exit()
click.echo(f"file does not exist: {fname_bnet=}")
sys.exit(1)

primes = bnet2primes(bnet=fname_bnet)
if fname_primes:
Expand Down
3 changes: 2 additions & 1 deletion pyboolnet/external/bnet2primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def bnet_file2primes(fname_bnet: str) -> dict:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
out = out.decode()
err = err.decode().replace("\n", " ")

if not proc.returncode == 0:
log.error(f"failed to run bnet_file2primes: cmd={' '.join(cmd)}, return_code={proc.returncode}, out={out}")
log.error(f"failed to run bnet_file2primes: cmd={' '.join(cmd)}, return_code={proc.returncode}, {out=}, {err=}")
raise Exception

out = out.replace("\x08", "")
Expand Down

0 comments on commit 5ae3bc7

Please sign in to comment.