Skip to content

Commit

Permalink
Release 3.1.2 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeklat authored Jun 20, 2024
1 parent 6fca89d commit 694be53
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/delfino.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/runConfigurations/Integration_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/runConfigurations/verify_all.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Types of changes are:

## [Unreleased]

## [3.1.2] - 2024-06-20

### Fixes

- Hide sub-commands based on function name, not the command name.

## [3.1.1] - 2024-01-23

### Fixes
Expand Down Expand Up @@ -498,7 +504,8 @@ Commands can raise `AssertionError` exceptions to tell `delfino` some pre-condit

- Initial copy of source codes.

[Unreleased]: https://github.com/radeklat/delfino/compare/3.1.1...HEAD
[Unreleased]: https://github.com/radeklat/delfino/compare/3.1.2...HEAD
[3.1.2]: https://github.com/radeklat/delfino/compare/3.1.1...3.1.2
[3.1.1]: https://github.com/radeklat/delfino/compare/3.1.0...3.1.1
[3.1.0]: https://github.com/radeklat/delfino/compare/3.0.2...3.1.0
[3.0.2]: https://github.com/radeklat/delfino/compare/3.0.1...3.0.2
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "delfino"
version = "3.1.1"
version = "3.1.2"
description = "A collection of command line helper scripts wrapping tools used during Python development."
authors = ["Radek Lát <radek.lat@gmail.com>"]
license = "MIT License"
Expand Down
15 changes: 8 additions & 7 deletions src/delfino/click_utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def module_root_dir(self) -> Path:
@dataclass(frozen=True)
class _Command:
name: str
func_name: str
command: click.Command
package: _CommandPackage

Expand Down Expand Up @@ -94,7 +95,7 @@ def find_commands(command_package: _CommandPackage) -> List[_Command]:
module = import_module(f"{command_package.module_name}.{filename[:-3]}")

commands.extend(
_Command(name=obj.name, command=obj, package=command_package)
_Command(name=obj.name, func_name=obj_name, command=obj, package=command_package)
for obj_name, obj in vars(module).items()
if not obj_name.startswith("_") and isinstance(obj, click.Command) and obj.name is not None
)
Expand Down Expand Up @@ -224,8 +225,8 @@ def _filter_and_log_invalid_command_names(
def _register_packages(self):
sub_commands: Set[str] = set()
for command_package in self._command_packages:
commands = {command.name: command for command in find_commands(command_package)}
available_command_names = set(commands.keys())
commands = {command.func_name: command for command in find_commands(command_package)}
available_command_names = {command.name for command in commands.values()}

filter_and_log_invalid_command_names = partial(
self._filter_and_log_invalid_command_names, command_package.plugin_name, available_command_names
Expand All @@ -241,11 +242,11 @@ def _register_packages(self):

enabled_commands.difference_update(disabled_commands)

for command_name, command in commands.items():
if command_name not in sub_commands: # hide sub-commands
self._register(command, command_name in enabled_commands)
for command_func_name, command in commands.items():
if command_func_name not in sub_commands: # hide sub-commands
self._register(command, command.name in enabled_commands)
if hasattr(command.command, "commands"):
sub_commands.update(command.command.commands.keys())
sub_commands.update(command.callback.__name__ for command in command.command.commands.values())

def _register(self, command: _Command, enabled: bool):
existing_command = self._visible_commands.pop(command.name, None) or self._hidden_commands.pop(
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_command_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ def should_not_load_sub_commands_of_a_group():
assert {command.name for command in registry.visible_commands} == {"visible-group"}
assert not registry.hidden_commands

@staticmethod
def should_ignore_sub_commands_by_function_name():
model_path = Path("same_name_different_function")
fake_command_files = [
FakeCommandFile(
content_template="import click\n"
"@click.group('visible')\ndef visible_group():\n pass\n"
"@visible_group.group('hidden')\ndef hidden_group():\n pass\n"
"@hidden_group.command('command')\ndef hidden_sub_command():\n pass\n"
"@click.command('command')\ndef visible_command():\n pass\n",
),
]
with demo_commands(model_path, fake_command_files):
registry = CommandRegistry({}, local_command_folders=[model_path])
assert {command.name for command in registry.visible_commands} == {"visible", "command"}
assert not registry.hidden_commands


@pytest.mark.usefixtures("install_fake_plugins")
class TestCommandRegistryPluginAndCommandSelection:
Expand Down

0 comments on commit 694be53

Please sign in to comment.