Skip to content

Commit bf3f27e

Browse files
tothtamas28Baltoli
authored andcommitted
Add parameter temp_dir to K tools
1 parent af9c9dc commit bf3f27e

4 files changed

Lines changed: 58 additions & 30 deletions

File tree

pyk/src/pyk/ktool/kprint.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def _kast(
6666
expression: str | None = None,
6767
module: str | None = None,
6868
sort: str | None = None,
69+
temp_dir: str | Path | None = None,
6970
gen_glr_parser: bool = False,
7071
# ---
7172
check: bool = True,
@@ -83,6 +84,9 @@ def _kast(
8384
definition_dir = Path(definition_dir)
8485
check_dir_path(definition_dir)
8586

87+
if temp_dir is not None:
88+
temp_dir = Path(temp_dir)
89+
8690
if input is not None:
8791
input = KAstInput(input)
8892

@@ -98,6 +102,7 @@ def _kast(
98102
expression=expression,
99103
module=module,
100104
sort=sort,
105+
temp_dir=temp_dir,
101106
gen_glr_parser=gen_glr_parser,
102107
)
103108

@@ -116,6 +121,7 @@ def gen_glr_parser(
116121
definition_dir: str | Path | None = None,
117122
module: str | None = None,
118123
sort: str | None = None,
124+
temp_dir: str | Path | None = None,
119125
) -> Path:
120126
parser_file = Path(parser_file)
121127
_kast(
@@ -124,6 +130,7 @@ def gen_glr_parser(
124130
definition_dir=definition_dir,
125131
module=module,
126132
sort=sort,
133+
temp_dir=temp_dir,
127134
gen_glr_parser=True,
128135
check=True,
129136
)
@@ -141,6 +148,7 @@ def _build_arg_list(
141148
expression: str | None,
142149
module: str | None,
143150
sort: str | None,
151+
temp_dir: Path | None,
144152
gen_glr_parser: bool,
145153
) -> list[str]:
146154
args = [command if command is not None else 'kast']
@@ -158,6 +166,8 @@ def _build_arg_list(
158166
args += ['--module', module]
159167
if sort:
160168
args += ['--sort', sort]
169+
if temp_dir:
170+
args += ['--temp-dir', str(temp_dir)]
161171
if gen_glr_parser:
162172
args += ['--gen-glr-parser']
163173
return args
@@ -311,6 +321,7 @@ def _expression_kast(
311321
output=output,
312322
module=module,
313323
sort=sort,
324+
temp_dir=self.use_directory,
314325
check=check,
315326
)
316327

@@ -326,5 +337,6 @@ def _expression_kast(
326337
output=output,
327338
module=module,
328339
sort=sort,
340+
temp_dir=self.use_directory,
329341
check=check,
330342
)

pyk/src/pyk/ktool/kprove.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _kprove(
6161
output: KProveOutput | None = None,
6262
depth: int | None = None,
6363
claims: Iterable[str] = (),
64+
temp_dir: Path | None = None,
6465
haskell_backend_command: str | None = None,
6566
dry_run: bool = False,
6667
# --
@@ -86,6 +87,7 @@ def _kprove(
8687
output=output,
8788
depth=depth,
8889
claims=claims,
90+
temp_dir=temp_dir,
8991
haskell_backend_command=haskell_backend_command,
9092
dry_run=dry_run,
9193
)
@@ -109,6 +111,7 @@ def _build_arg_list(
109111
output: KProveOutput | None,
110112
depth: int | None,
111113
claims: Iterable[str],
114+
temp_dir: Path | None,
112115
haskell_backend_command: str | None,
113116
dry_run: bool,
114117
) -> list[str]:
@@ -136,6 +139,9 @@ def _build_arg_list(
136139
if claims:
137140
args += ['--claims', ','.join(claims)]
138141

142+
if temp_dir:
143+
args += ['--temp-dir', str(temp_dir)]
144+
139145
if haskell_backend_command:
140146
args += ['--haskell-backend-command', haskell_backend_command]
141147

@@ -225,6 +231,7 @@ def prove(
225231
include_dirs=include_dirs,
226232
md_selector=md_selector,
227233
output=KProveOutput.JSON,
234+
temp_dir=self.use_directory,
228235
dry_run=dry_run,
229236
args=self.prover_args + list(args),
230237
env=env,

pyk/src/pyk/ktool/krun.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ def run(
7474
definition_dir=self.definition_dir,
7575
output=KRunOutput.JSON,
7676
depth=depth,
77-
no_expand_macros=not expand_macros,
7877
cmap=cmap,
7978
pmap=pmap,
79+
temp_dir=self.use_directory,
80+
no_expand_macros=not expand_macros,
8081
bug_report=self._bug_report,
8182
check=(expect_rc == 0),
8283
)
@@ -108,6 +109,7 @@ def run_kore(
108109
output=KRunOutput.KORE,
109110
parser='cat',
110111
depth=depth,
112+
temp_dir=self.use_directory,
111113
no_expand_macros=not expand_macros,
112114
bug_report=self._bug_report,
113115
check=(expect_rc == 0),
@@ -143,6 +145,7 @@ def run_kore_term(
143145
parser='cat',
144146
term=True,
145147
depth=depth,
148+
temp_dir=self.use_directory,
146149
no_expand_macros=not expand_macros,
147150
search_final=search_final,
148151
no_pattern=no_pattern,
@@ -236,6 +239,7 @@ def _krun(
236239
pmap: Mapping[str, str] | None = None,
237240
cmap: Mapping[str, str] | None = None,
238241
term: bool = False,
242+
temp_dir: Path | None = None,
239243
no_expand_macros: bool = False,
240244
search_final: bool = False,
241245
no_pattern: bool = False,
@@ -264,6 +268,7 @@ def _krun(
264268
pmap=pmap,
265269
cmap=cmap,
266270
term=term,
271+
temp_dir=temp_dir,
267272
no_expand_macros=no_expand_macros,
268273
search_final=search_final,
269274
no_pattern=no_pattern,
@@ -296,6 +301,7 @@ def _build_arg_list(
296301
pmap: Mapping[str, str] | None,
297302
cmap: Mapping[str, str] | None,
298303
term: bool,
304+
temp_dir: Path | None,
299305
no_expand_macros: bool,
300306
search_final: bool,
301307
no_pattern: bool,
@@ -317,6 +323,8 @@ def _build_arg_list(
317323
args += [f'-c{name}={value}']
318324
if term:
319325
args += ['--term']
326+
if temp_dir:
327+
args += ['--temp-dir', str(temp_dir)]
320328
if no_expand_macros:
321329
args += ['--no-expand-macros']
322330
if search_final:

pyk/src/tests/unit/ktool/test_krun.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,38 @@
77

88
from pyk.ktool.krun import KRunOutput, _build_arg_list
99

10-
# fmt: off
11-
required_args: dict[str, Any] = OrderedDict([
12-
('command', 'krun'),
13-
('input_file', None),
14-
('definition_dir', None),
15-
('output', None),
16-
('parser', None),
17-
('depth', None),
18-
('pmap', None),
19-
('cmap', None),
20-
('term', False),
21-
('no_expand_macros', False),
22-
('search_final', False),
23-
('no_pattern', False),
24-
])
10+
required_args: dict[str, Any] = OrderedDict(
11+
[
12+
('command', 'krun'),
13+
('input_file', None),
14+
('definition_dir', None),
15+
('output', None),
16+
('parser', None),
17+
('depth', None),
18+
('pmap', None),
19+
('cmap', None),
20+
('term', False),
21+
('temp_dir', None),
22+
('no_expand_macros', False),
23+
('search_final', False),
24+
('no_pattern', False),
25+
]
26+
)
27+
2528
optional_args: dict[str, tuple[Any, list[str]]] = {
26-
'input_file': (Path('input/path'), ['input/path']),
27-
'definition_dir': (Path('def/path'), ['--definition', 'def/path']),
28-
'output': (KRunOutput.JSON, ['--output', 'json']),
29-
'parser': ('cat', ['--parser', 'cat']),
30-
'depth': (1234, ['--depth', '1234']),
31-
'pmap': ({'FOO': 'bar', 'BUZZ': 'kill'},
32-
['-pFOO=bar', '-pBUZZ=kill']),
33-
'cmap': ({'COO': 'car', 'FUZZ': 'bill'},
34-
['-cCOO=car', '-cFUZZ=bill']),
35-
'term': (True, ['--term']),
36-
'no_expand_macros': (True, ['--no-expand-macros']),
37-
'search_final': (True, ['--search-final']),
38-
'no_pattern': (True, ['--no-pattern']),
29+
'input_file': (Path('input/path'), ['input/path']),
30+
'definition_dir': (Path('def/path'), ['--definition', 'def/path']),
31+
'output': (KRunOutput.JSON, ['--output', 'json']),
32+
'parser': ('cat', ['--parser', 'cat']),
33+
'depth': (1234, ['--depth', '1234']),
34+
'pmap': ({'FOO': 'bar', 'BUZZ': 'kill'}, ['-pFOO=bar', '-pBUZZ=kill']),
35+
'cmap': ({'COO': 'car', 'FUZZ': 'bill'}, ['-cCOO=car', '-cFUZZ=bill']),
36+
'term': (True, ['--term']),
37+
'temp_dir': (Path('/tmp/path'), ['--temp-dir', '/tmp/path']),
38+
'no_expand_macros': (True, ['--no-expand-macros']),
39+
'search_final': (True, ['--search-final']),
40+
'no_pattern': (True, ['--no-pattern']),
3941
}
40-
# fmt: on
4142

4243

4344
def make_kwargs(test_id: str, keys: list[str]) -> tuple[str, dict[str, Any], list[str]]:

0 commit comments

Comments
 (0)