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

Codependencies #19

Merged
merged 1 commit into from
May 12, 2022
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Manifestoo is a command line tool that provides the following features:

* listing addons,
* listing direct and transitive dependencies of selected addons,
* listing direct and transitive co-dependencies of selected addons,
* listing core Odoo CE and EE addons,
* listing external dependencies,
* displaying the dependency tree,
Expand Down Expand Up @@ -83,6 +84,14 @@ $ manifestoo -d /tmp/myaddons list-depends --separator=,
crm,mail
```

The `list-codepends` command shows the transitive co-dependencies.
It is handy to know which modules are impacted by changes in selected modules.

```console
$ manifestoo --addons-path /tmp/myaddons --select a list-codepends --separator=,
b,c
```

You can explore the dependency tree of module `a` like this:

```console
Expand Down
29 changes: 29 additions & 0 deletions src/manifestoo/commands/list_codepends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Iterable, Set

from ..addons_selection import AddonsSelection
from ..addons_set import AddonsSet


def list_codepends_command(
addons_selection: AddonsSelection,
addons_set: AddonsSet,
transitive: bool = True,
include_selected: bool = True,
) -> Iterable[str]:
result: Set[str] = set(addons_selection) if include_selected else set()
codeps = direct_codependencies(addons_selection, addons_set, result)
result |= codeps
while transitive and codeps:
codeps = direct_codependencies(codeps, addons_set, result)
result |= codeps
return result if include_selected else result - addons_selection


def direct_codependencies(
root_addons: Set[str], addons_set: AddonsSet, accumulator: Set[str]
) -> Set[str]:
return {
a
for a in addons_set
if set(addons_set[a].manifest.depends) & root_addons and a not in accumulator
}
31 changes: 31 additions & 0 deletions src/manifestoo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .commands.check_dev_status import check_dev_status_command
from .commands.check_licenses import check_licenses_command
from .commands.list import list_command
from .commands.list_codepends import list_codepends_command
from .commands.list_depends import list_depends_command
from .commands.list_external_dependencies import list_external_dependencies_command
from .commands.tree import tree_command
Expand Down Expand Up @@ -253,6 +254,36 @@ def list_depends(
)


@app.command()
def list_codepends(
ctx: typer.Context,
separator: Optional[str] = typer.Option(
None,
help="Separator character to use (by default, print one item per line).",
),
transitive: bool = typer.Option(
True,
"--transitive",
help="Print all transitive co-dependencies.",
),
include_selected: bool = typer.Option(
True,
"--include-selected",
help="Print the selected addons along with their co-dependencies"
"(the set of addons that depends on the set of selected addons).",
),
) -> None:
"""Print the co-dependencies of selected addons."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le's put the explanation about what a co-dependency is here rather than in the --include-selected description ?

main_options: MainOptions = ctx.obj
result = list_codepends_command(
main_options.addons_selection,
main_options.addons_set,
transitive,
include_selected,
)
print_list(result, separator or main_options.separator or "\n")


@app.command()
def list_external_dependencies(
ctx: typer.Context,
Expand Down