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

Add topological sort option to list* commands #62

Merged

Conversation

ThomasBinsfeld
Copy link
Member

Add a new --sort option on the list-depend command allowing to apply a topological sorting to the result.
https://docs.python.org/3/library/graphlib.html

src/manifestoo/commands/list_depends.py Outdated Show resolved Hide resolved
src/manifestoo/main.py Show resolved Hide resolved
@sbidoul
Copy link
Member

sbidoul commented Oct 30, 2023

I see graphlib is python 3.9+, but that is ok, we can simply error out if the topological sort is selected by the user and sys.version_info < (3,9).

@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch from e280f9a to a3b1a4e Compare October 30, 2023 16:21
src/manifestoo/main.py Outdated Show resolved Hide resolved
@sbidoul
Copy link
Member

sbidoul commented Oct 30, 2023

This is taking shape. Can you add tests for the sorters and update the documentation too?

@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch from a3b1a4e to 748eda0 Compare October 30, 2023 17:04
@sbidoul
Copy link
Member

sbidoul commented Oct 30, 2023

Can you also

  • add a news/62.feature with a short changelog entry
  • add the sort option to the list and list-codepends commands

@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch from 748eda0 to b10263d Compare October 30, 2023 17:24
@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch 3 times, most recently from 9512cd2 to ca6b019 Compare October 31, 2023 08:49
@sbidoul sbidoul changed the title [IMP] list-depends: topological sorting Add topological sort option to list* commands Oct 31, 2023
@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch 3 times, most recently from 088598d to 886f034 Compare October 31, 2023 10:09
Comment on lines 50 to 54
result_dict[addon_name] = set(
[
depend
for depend in addon.manifest.depends
if depend in addons_selection
]
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
result_dict[addon_name] = set(
[
depend
for depend in addon.manifest.depends
if depend in addons_selection
]
)
result_dict[addon_name] = set(
depend
for depend in addon.manifest.depends
if depend in addons_selection
)

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
res = result if include_selected else result - set(addons_selection)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
res = result if include_selected else result - set(addons_selection)
res = result if include_selected else result - addons_selection

This change was not necessary?

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
res = result if include_selected else result - set(addons_selection)
return set(addon_sorter.sort(res, addons_set))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return set(addon_sorter.sort(res, addons_set))
return addon_sorter.sort(res, addons_set)

Set would defeat the sorting.

"--sorting",
"--sort",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"--sorting",
"--sort",
"--sort",

--sorting sounds a bit strange to me. Not sure.

"--sorting",
"--sort",
help=(
"Choice between 'alphabetical' and 'topological'."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Choice between 'alphabetical' and 'topological'."
"Choice between 'alphabetical' and 'topological'. "

Also for the 2 others

@ThomasBinsfeld ThomasBinsfeld force-pushed the imp_manifestoo_list_depends_command_topological_sorting_tbi branch from 886f034 to b304897 Compare November 2, 2023 09:13
@sbidoul sbidoul merged commit ee8e871 into main Nov 2, 2023
@sbidoul sbidoul deleted the imp_manifestoo_list_depends_command_topological_sorting_tbi branch November 2, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants