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

TOML: use default profile values by default when another profile is active #4657

Merged
merged 3 commits into from
Oct 10, 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
4 changes: 3 additions & 1 deletion pyk/src/pyk/cli/pyk.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ def get_profile(toml_profile: dict[str, Any], profile_list: list[str]) -> dict[s
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}
active_profile = {k: v for k, v in toml_profile.get(profile_list[0], {}).items() if type(v) is not dict}
default_profile = {k: v for k, v in toml_profile.get('default', {}).items() if type(v) is not dict}
return {**default_profile, **active_profile}
return get_profile(toml_profile[profile_list[0]], profile_list[1:])

toml_args: dict[str, Any] = {}
Expand Down
5 changes: 4 additions & 1 deletion pyk/src/tests/unit/test-data/pyk_toml_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ definition = "/tmp"
input = "kast-json"
no-minimize = true

[prove-legacy]
[prove-legacy.default]
kArgs = ["arg 1","args 2"]

[prove-legacy.verbose]
verbose = true

[coverage.a_profile]
verbose = true
output = "a-profile-file"
22 changes: 22 additions & 0 deletions pyk/src/tests/unit/test_toml_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ def test_prove_legacy_kargs() -> None:
assert len(args_dict['k_args']) == 2


def test_prove_legacy_profiles() -> None:
parser = create_argument_parser()
cmd_args = [
'prove-legacy',
'--config-file',
str(TEST_TOML),
'--config-profile',
'verbose',
tempfile.gettempdir(),
str(TEST_TOML),
str(TEST_TOML),
'spec-module',
'cmd_args',
]
args = parser.parse_args(cmd_args)
args_dict = parse_toml_args(args)
assert len(args_dict['k_args']) == 2
assert hasattr(args, 'verbose')
assert 'verbose' in args_dict
assert args_dict['verbose']


def test_toml_read() -> None:
change_in_toml('definition = "(.*)"', f'definition = "{tempfile.gettempdir()}"')
parser = create_argument_parser()
Expand Down
Loading