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

Added a way to exclude some modules from the result of dependencies #28

Merged
merged 1 commit into from
Jul 6, 2023
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
14 changes: 12 additions & 2 deletions odoo_tools/cli/click/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def show_module(ctx, module):
)
@click.option(
'--include-modules',
help="Remove logs and warnings.",
help="Include dependencies that aren't in the addons_paths.",
is_flag=True,
default=False
)
Expand All @@ -207,6 +207,12 @@ def show_module(ctx, module):
is_flag=True,
default=False
)
@click.option(
'--exclude-modules',
help="Exclude queried modules from the found dependencies.",
is_flag=True,
default=False
)
@click.pass_context
def show_dependencies(
ctx,
Expand All @@ -220,7 +226,8 @@ def show_dependencies(
path,
auto,
quiet,
include_modules
include_modules,
exclude_modules,
):
env = ctx.obj['env']

Expand Down Expand Up @@ -278,6 +285,9 @@ def check_module(mod):
mods = [
mod.path.name if only_name else str(mod)
for mod in sorted_dependencies
if (
exclude_modules and mod.path.name not in check_modules
) or not exclude_modules
]

if csv:
Expand Down
50 changes: 50 additions & 0 deletions tests/cli/test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from mock import patch, MagicMock
from odoo_tools.cli.odot import command
from odoo_tools.api.environment import Environment

from odoo_tools.api.modules import ModuleApi
from odoo_tools.api.objects import Manifest


def test_module_deps(runner, tmp_path):

with patch.object(ModuleApi, 'list') as list_modules:

list_modules.return_value = [
Manifest(tmp_path / 'a', attrs={'version': 1, 'depends': {}}),
Manifest(tmp_path / 'b', attrs={'version': 1, 'depends': {'a'}}),
Manifest(tmp_path / 'c', attrs={'version': 1, 'depends': {'b'}}),
Manifest(
tmp_path / 'd',
attrs={
'version': 1,
'depends': {'a', 'c'}
}
)
]

result = runner.invoke(
command,
[
'module',
'deps',
'--only-name',
'--exclude-modules',
'--csv-modules', 'c,d',
]
)

modules = set(result.stdout.strip().split('\n'))
assert modules == {'a', 'b'}

result = runner.invoke(
command,
[
'module',
'deps',
'--only-name',
'--csv-modules', 'c,d',
]
)
modules = set(result.stdout.strip().split('\n'))
assert modules == {'a', 'b', 'c', 'd'}