Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set logging level to DEBUG for llvm_interpret_raw #4518

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyk/src/pyk/ktool/krun.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,4 @@ def llvm_interpret_raw(definition_dir: str | Path, kore: str, depth: int | None
depth = depth if depth is not None else -1
args = [str(interpreter_file), '/dev/stdin', str(depth), '/dev/stdout']

return run_process_2(args, input=kore)
return run_process_2(args, input=kore, logger=_LOGGER, loglevel=logging.DEBUG)
27 changes: 15 additions & 12 deletions pyk/src/pyk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def run_process_2(
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
logger: Logger | None = None,
loglevel: int | None = None,
check: bool = True,
) -> CompletedProcess:
if type(args) is str:
Expand All @@ -478,6 +479,9 @@ def run_process_2(
if not logger:
logger = _LOGGER

if loglevel is None:
loglevel = logging.INFO

res = _subprocess_run(
args,
input=input,
Expand All @@ -486,6 +490,7 @@ def run_process_2(
cwd=cwd,
env=env,
logger=logger,
loglevel=loglevel,
)

if check:
Expand All @@ -503,6 +508,7 @@ def _subprocess_run(
env: Mapping[str, str] | None,
cwd: Path | None,
logger: Logger,
loglevel: int,
) -> CompletedProcess:
with Popen(
args,
Expand All @@ -517,26 +523,27 @@ def _subprocess_run(

command = shlex.join(args)
for line in command.split('\n'):
logger.info(f'{log_prefix}[exec] {line}')
logger.log(loglevel, f'{log_prefix}[exec] {line}')

start_time = time.time()

try:
returncode, stdout, stderr = _subprocess_communicate(
popen,
input=input,
logger=logger,
write_stdout=write_stdout,
write_stderr=write_stderr,
logger=logger,
loglevel=loglevel,
)
except BaseException:
popen.kill()
delta_time = time.time() - start_time
logger.info(f'{log_prefix}[fail] time={delta_time:.3f}s')
logger.log(loglevel, f'{log_prefix}[fail] time={delta_time:.3f}s')
raise

delta_time = time.time() - start_time
logger.info(f'{log_prefix}[done] status={returncode} time={delta_time:.3f}s')
logger.log(loglevel, f'{log_prefix}[done] status={returncode} time={delta_time:.3f}s')

return CompletedProcess(popen.args, returncode, stdout, stderr)

Expand All @@ -548,6 +555,7 @@ def _subprocess_communicate(
write_stdout: bool,
write_stderr: bool,
logger: Logger,
loglevel: int,
) -> tuple[int, str, str]:
assert popen.stdout is not None
assert popen.stderr is not None
Expand All @@ -562,7 +570,7 @@ def readerthread(
) -> None:
for line in input_fh:
buffer.append(line)
logger.info(f'{log_prefix}{stream_prefix} {line.rstrip()}')
logger.log(loglevel, f'{log_prefix}{stream_prefix} {line.rstrip()}')
if output_fh:
output_fh.write(line)
output_fh.flush()
Expand All @@ -585,7 +593,7 @@ def readerthread(
if input is not None:
assert popen.stdin is not None
for line in input.split('\n'):
logger.info(f'{log_prefix}[stdi] {line}')
logger.log(loglevel, f'{log_prefix}[stdi] {line}')
# Note: popen.stdin.write does not work for llvm_interpret_raw
popen._stdin_write(input) # type: ignore [attr-defined]

Expand Down Expand Up @@ -649,11 +657,6 @@ def ensure_dir_path(path: str | Path) -> Path:
return path


# Implementation because of outdated Python versions: https://github.com/python/cpython/blob/1de4395f62bb140563761ef5cbdf46accef3c550/Lib/pathlib.py#L554
def is_relative_to(_self: Path, other: Path) -> bool:
return _self == other or other in _self.parents


Comment on lines -652 to -656
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated cleanup, but since it is straightforward to adjust for in dependents I decided to include it in this PR.

def abs_or_rel_to(path: Path, base: Path) -> Path:
if path.is_absolute():
return path
Expand Down Expand Up @@ -699,7 +702,7 @@ def _remap_arg(_a: str) -> str:
_a_path = Path(_a)
for _f in self._file_remap:
_f_path = Path(_f)
if is_relative_to(_a_path, _f_path):
if _a_path.is_relative_to(_f_path):
return str(Path(self._file_remap[_f]) / _a_path.relative_to(_f_path))
return _a

Expand Down
Loading