This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds `Options` class hierarchy which stores all the parameters associated with command line options for pyk, and is extendable by downstream projects. This is a part of the changes pulled out from #967. - Adds `Options` which automatically populates its fields from a prepared `dict` from the parsed command line args and sets default values when the values are missing - Adds `LoggingOptions`, etc., which are groups of options that can be inherited by commands - Adds `ProveOptions`, etc. which are directly associated with particular pyk commands but otherwise behave the same - `exec_*` functions now take the corresponding `*Options` type instead of generic `Namespace` - Defaults are no longer set at the argparse level since they are now set in `Options` constructor. --------- Co-authored-by: devops <[email protected]>
- Loading branch information
Showing
9 changed files
with
422 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.711 | ||
0.1.712 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "pyk" | ||
version = "0.1.711" | ||
version = "0.1.712" | ||
description = "" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
|
||
class Options: | ||
def __init__(self, args: dict[str, Any]) -> None: | ||
# Get defaults from this and all superclasses that define them, preferring the most specific class | ||
defaults: dict[str, Any] = {} | ||
for cl in reversed(type(self).mro()): | ||
if hasattr(cl, 'default'): | ||
defaults = defaults | cl.default() | ||
|
||
# Overwrite defaults with args from command line | ||
_args = defaults | args | ||
|
||
for attr, val in _args.items(): | ||
self.__setattr__(attr, val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import IO, TYPE_CHECKING, Any | ||
|
||
from pyk.ktool.kompile import KompileBackend | ||
|
||
from .args import DefinitionOptions, DisplayOptions, KDefinitionOptions, LoggingOptions, OutputFileOptions | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Iterable | ||
from pathlib import Path | ||
|
||
from pyk.ktool import TypeInferenceMode | ||
|
||
|
||
def generate_options(args: dict[str, Any]) -> LoggingOptions: | ||
command = args['command'] | ||
match command: | ||
case 'json-to-kore': | ||
return JsonToKoreOptions(args) | ||
case 'kore-to-json': | ||
return KoreToJsonOptions(args) | ||
case 'coverage': | ||
return CoverageOptions(args) | ||
case 'graph-imports': | ||
return GraphImportsOptions(args) | ||
case 'rpc-kast': | ||
return RPCKastOptions(args) | ||
case 'rpc-print': | ||
return RPCPrintOptions(args) | ||
case 'print': | ||
return PrintOptions(args) | ||
case 'prove-legacy': | ||
return ProveLegacyOptions(args) | ||
case 'prove': | ||
return ProveOptions(args) | ||
case 'kompile': | ||
return KompileCommandOptions(args) | ||
case 'run': | ||
return RunOptions(args) | ||
case _: | ||
raise ValueError(f'Unrecognized command: {command}') | ||
|
||
|
||
class PrintInput(Enum): | ||
KORE_JSON = 'kore-json' | ||
KAST_JSON = 'kast-json' | ||
|
||
|
||
class JsonToKoreOptions(LoggingOptions): | ||
... | ||
|
||
|
||
class KoreToJsonOptions(LoggingOptions): | ||
... | ||
|
||
|
||
class CoverageOptions(DefinitionOptions, OutputFileOptions, LoggingOptions): | ||
coverage_file: IO[Any] | ||
|
||
|
||
class GraphImportsOptions(DefinitionOptions, LoggingOptions): | ||
... | ||
|
||
|
||
class RPCKastOptions(OutputFileOptions, LoggingOptions): | ||
reference_request_file: IO[Any] | ||
response_file: IO[Any] | ||
|
||
|
||
class RPCPrintOptions(DefinitionOptions, OutputFileOptions, LoggingOptions): | ||
input_file: IO[Any] | ||
|
||
|
||
class PrintOptions(DefinitionOptions, OutputFileOptions, DisplayOptions, LoggingOptions): | ||
term: IO[Any] | ||
input: PrintInput | ||
minimize: bool | ||
omit_labels: str | None | ||
keep_cells: str | None | ||
|
||
@staticmethod | ||
def default() -> dict[str, Any]: | ||
return { | ||
'input': PrintInput.KAST_JSON, | ||
'omit_labels': None, | ||
'keep_cells': None, | ||
} | ||
|
||
|
||
class ProveLegacyOptions(DefinitionOptions, OutputFileOptions, LoggingOptions): | ||
main_file: Path | ||
spec_file: Path | ||
spec_module: str | ||
k_args: Iterable[str] | ||
|
||
@staticmethod | ||
def default() -> dict[str, Any]: | ||
return { | ||
'k_args': [], | ||
} | ||
|
||
|
||
class KompileCommandOptions(LoggingOptions, KDefinitionOptions): | ||
definition_dir: Path | None | ||
main_file: str | ||
backend: KompileBackend | ||
type_inference_mode: TypeInferenceMode | None | ||
|
||
@staticmethod | ||
def default() -> dict[str, Any]: | ||
return { | ||
'definition_dir': None, | ||
'backend': KompileBackend.LLVM, | ||
'type_inference_mode': None, | ||
} | ||
|
||
|
||
class ProveOptions(LoggingOptions): | ||
spec_file: Path | ||
definition_dir: Path | None | ||
spec_module: str | None | ||
type_inference_mode: TypeInferenceMode | None | ||
failure_info: bool | ||
|
||
@staticmethod | ||
def default() -> dict[str, Any]: | ||
return { | ||
'definition_dir': None, | ||
'spec_module': None, | ||
'type_inference_mode': None, | ||
'failure_info': False, | ||
} | ||
|
||
|
||
class RunOptions(LoggingOptions): | ||
pgm_file: str | ||
definition_dir: Path | None | ||
|
||
@staticmethod | ||
def default() -> dict[str, Any]: | ||
return { | ||
'definition_dir': None, | ||
} |
Oops, something went wrong.