Skip to content

Commit

Permalink
more fixes for errors missed during rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
ovatman committed Apr 19, 2024
1 parent 4a55c57 commit 68705e1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 44 deletions.
37 changes: 0 additions & 37 deletions pyk/src/pyk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

import tomli
from graphviz import Digraph

from .cli.pyk import PrintInput, create_argument_parser, generate_options, parse_toml_args
Expand Down Expand Up @@ -39,7 +38,6 @@
from .utils import check_file_path, ensure_dir_path, exit_with_process_error

if TYPE_CHECKING:
from argparse import Namespace
from typing import Any, Final

from .cli.pyk import (
Expand Down Expand Up @@ -385,40 +383,5 @@ def exec_json_to_kore(options: JsonToKoreOptions) -> None:
sys.stdout.write('\n')


def parse_toml_args(args: Namespace) -> dict[str, Any | Iterable]:
def get_profile(toml_profile: dict[str, Any], profile_list: list[str]) -> dict[str, Any]:
if len(profile_list) == 0 or profile_list[0] not in toml_profile:
return {k: v for k, v in toml_profile.items() if type(v) is not dict}
elif len(profile_list) == 1:
return {k: v for k, v in toml_profile[profile_list[0]].items() if type(v) is not dict}
return get_profile(toml_profile[profile_list[0]], profile_list[1:])

toml_args = {}
if args.config_file.is_file():
with open(args.config_file, 'rb') as config_file:
try:
toml_args = tomli.load(config_file)
except tomli.TOMLDecodeError:
_LOGGER.error(
'Input config file is not in TOML format, ignoring the file and carrying on with the provided command line agruments'
)

toml_args = (
get_profile(toml_args[args.command], args.config_profile.split('.')) if args.command in toml_args else {}
)
toml_args = {get_option_string_destination(args.command, k): v for k, v in toml_args.items()}
for k, v in toml_args.items():
if k[:3] == 'no-' and (v == 'true' or v == 'false'):
del toml_args[k]
toml_args[k[3:]] = 'false' if v == 'true' else 'true'
if k == 'optimization-level':
level = toml_args[k] if toml_args[k] >= 0 else 0
level = level if toml_args[k] <= 3 else 3
del toml_args[k]
toml_args['-O' + str(level)] = 'true'

return toml_args


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions pyk/src/pyk/cli/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def from_option_string() -> dict[str, Any]:
'v': 'verbose',
}


class WarningOptions(Options):
warnings: Warnings | None
warnings_to_errors: bool
Expand Down
7 changes: 0 additions & 7 deletions pyk/src/pyk/cli/pyk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import logging
from argparse import ArgumentParser, FileType
import logging
from argparse import ArgumentParser, FileType
from enum import Enum
Expand All @@ -10,14 +8,11 @@
import tomli

from ..ktool.kompile import KompileBackend
from ..ktool import TypeInferenceMode
from .args import (
ConfigArgs,
ConfigArgs,
DefinitionOptions,
DisplayOptions,
KCLIArgs,
KCLIArgs,
KDefinitionOptions,
KompileOptions,
LoggingOptions,
Expand All @@ -39,7 +34,6 @@
_LOGGER: Final = logging.getLogger(__name__)



def generate_options(args: dict[str, Any]) -> LoggingOptions:
command = args['command']
match command:
Expand Down Expand Up @@ -200,7 +194,6 @@ def from_option_string() -> dict[str, str]:
)



class KompileCommandOptions(LoggingOptions, WarningOptions, KDefinitionOptions, KompileOptions):
definition_dir: Path | None
main_file: str
Expand Down

0 comments on commit 68705e1

Please sign in to comment.