Skip to content

Commit

Permalink
feat: show note about barebones mode only in non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthkoushik committed Jun 27, 2024
1 parent aa1eb61 commit 2fdd791
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
17 changes: 11 additions & 6 deletions dist/pyseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ def add_type(s: str) -> str:

name = self.name
arg_name = f"-{name}" if len(name) == 1 else f"--{name.replace('_', '-')}"

help_txt = self.description
if any(member.value is self for member in BAREBONES_MODE_IGNORED_CONFIG_KEYS):
help_txt += " (ignored in barebones mode)"
if self.default is not None:
help_txt += f" [default: '{self.default}']"

arg_default = None if no_default_required else self.default
arg_required = False if no_default_required else self.default is None
argparser.add_argument(
Expand Down Expand Up @@ -442,9 +446,12 @@ def add_arg_to_argparser(
# * If there is no default value, both the above arguments
# are added to a mutually exclusive group.
true_arg = f"--{self.name.replace('_', '-')}"
true_help = self.description
help_txt = self.description
if any(member.value is self for member in BAREBONES_MODE_IGNORED_CONFIG_KEYS):
help_txt += " (ignored in barebones mode)"
true_help = help_txt
false_arg = f"--no-{self.name.replace('_', '-')}"
false_help = f"do not {self.description}"
false_help = f"do not {help_txt}"
if self.default is False:
argparser.add_argument(
true_arg,
Expand Down Expand Up @@ -499,17 +506,15 @@ class ConfigKey(Enum):
)
max_py_version = StrConfigKeySpec(
"pyM",
"maximum python3 version (for github actions; ignored in barebones mode)",
"maximum python3 version, for github actions",
"3.12",
validate_string_python_version,
)
add_py_typed = BoolConfigKeySpec(
"py_typed", "add 'py.typed' file indicating typing support", True
)
update_pc_hooks_on_schedule = BoolConfigKeySpec(
"pc_cron",
"add support for updating pre-commit hooks monthly (ignored in barebones mode)",
True,
"pc_cron", "add support for updating pre-commit hooks monthly", True
)
add_deps = StrConfigKeySpec(
"add_deps",
Expand Down
17 changes: 11 additions & 6 deletions src/pyseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,13 @@ def add_type(s: str) -> str:

name = self.name
arg_name = f"-{name}" if len(name) == 1 else f"--{name.replace('_', '-')}"

help_txt = self.description
if any(member.value is self for member in BAREBONES_MODE_IGNORED_CONFIG_KEYS):
help_txt += " (ignored in barebones mode)"
if self.default is not None:
help_txt += f" [default: '{self.default}']"

arg_default = None if no_default_required else self.default
arg_required = False if no_default_required else self.default is None
argparser.add_argument(
Expand Down Expand Up @@ -440,9 +444,12 @@ def add_arg_to_argparser(
# * If there is no default value, both the above arguments
# are added to a mutually exclusive group.
true_arg = f"--{self.name.replace('_', '-')}"
true_help = self.description
help_txt = self.description
if any(member.value is self for member in BAREBONES_MODE_IGNORED_CONFIG_KEYS):
help_txt += " (ignored in barebones mode)"
true_help = help_txt
false_arg = f"--no-{self.name.replace('_', '-')}"
false_help = f"do not {self.description}"
false_help = f"do not {help_txt}"
if self.default is False:
argparser.add_argument(
true_arg,
Expand Down Expand Up @@ -497,17 +504,15 @@ class ConfigKey(Enum):
)
max_py_version = StrConfigKeySpec(
"pyM",
"maximum python3 version (for github actions; ignored in barebones mode)",
"maximum python3 version, for github actions",
"3.12",
validate_string_python_version,
)
add_py_typed = BoolConfigKeySpec(
"py_typed", "add 'py.typed' file indicating typing support", True
)
update_pc_hooks_on_schedule = BoolConfigKeySpec(
"pc_cron",
"add support for updating pre-commit hooks monthly (ignored in barebones mode)",
True,
"pc_cron", "add support for updating pre-commit hooks monthly", True
)
add_deps = StrConfigKeySpec(
"add_deps",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_pyseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ def test_str_config_key_does_not_make_required_if_no_default_required(self):
args = argparser.parse_args([])
self.assertHasAttrWithValue(args, "dummy_param", None)

def test_str_config_key_adds_note_about_barebones_iff_in_ignored_list(self):
argparser = ArgumentParser(add_help=False, usage="")
pyseed.ConfigKey.url.value.add_arg_to_argparser(argparser)
self.assertIn("ignored in barebones mode", argparser.format_help())

argparser = ArgumentParser(add_help=False, usage="")
pyseed.ConfigKey.description.value.add_arg_to_argparser(argparser)
self.assertNotIn("ignored in barebones mode", argparser.format_help())


class TestBoolConfigKeySpec(TestCase):
def assertHasAttrWithValue(self, obj, attr, value): # noqa: N802
Expand Down Expand Up @@ -446,6 +455,15 @@ def test_bool_config_key_returns_none_with_no_default_required(self):
args = argparser.parse_args([])
self.assertHasAttrWithValue(args, "dummy_param", None)

def test_bool_config_key_adds_note_about_barebones_iff_in_ignored_list(self):
argparser = ArgumentParser(add_help=False, usage="")
pyseed.ConfigKey.no_github.value.add_arg_to_argparser(argparser)
self.assertIn("ignored in barebones mode", argparser.format_help())

argparser = ArgumentParser(add_help=False, usage="")
pyseed.ConfigKey.add_deps.value.add_arg_to_argparser(argparser)
self.assertNotIn("ignored in barebones mode", argparser.format_help())


class TestGetConf(TestCase):
def setUp(self):
Expand Down

0 comments on commit 2fdd791

Please sign in to comment.