Skip to content

Commit

Permalink
for implicit defaults, set a separate help message
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma-eth committed Jun 3, 2024
1 parent 1c9ba82 commit 90bc601
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/halmos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def arg(
choices: Optional[str] = None,
short: Optional[str] = None,
countable: bool = False,
global_default_str: Optional[str] = None,
):
return field(
default=None,
Expand All @@ -41,6 +42,7 @@ def arg(
"choices": choices,
"short": short,
"countable": countable,
"global_default_str": global_default_str,
},
)

Expand Down Expand Up @@ -86,14 +88,18 @@ class Config:
#
# We can then layer these Config objects on top of the `default_config()`

root: str = arg(
help="Project root directory",
metavar="PROJECT_ROOT",
global_default=os.getcwd,
global_default_str="'.'",
)

config: str = arg(
help="path to the configuration file",
global_default=lambda: os.path.join(os.getcwd(), "halmos.toml"),
metavar="FILE",
)

root: str = arg(
help="Project root directory", global_default=os.getcwd, metavar="PATH"
global_default=lambda: os.path.join(os.getcwd(), "halmos.toml"),
global_default_str="PROJECT_ROOT/halmos.toml",
)

contract: str = arg(
Expand Down Expand Up @@ -343,9 +349,10 @@ class Config:

solver_threads: int = arg(
help="set the number of threads for parallel solvers",
global_default=(lambda: os.cpu_count() or 1),
metavar="N",
group=solver,
global_default=(lambda: os.cpu_count() or 1),
global_default_str="number of CPUs",
)

### Experimental options
Expand Down Expand Up @@ -576,7 +583,9 @@ def _create_arg_parser() -> argparse.ArgumentParser:
# add the default value to the help text
default = field_info.metadata.get("global_default", None)
if default is not None:
arg_help += f" (default: {default!r})"
default_str = field_info.metadata.get("global_default_str", None)
default_str = repr(default) if default_str is None else default_str
arg_help += f" (default: {default_str})"

kwargs = {
"help": arg_help,
Expand Down

0 comments on commit 90bc601

Please sign in to comment.