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

feat: abbreviated dependency tree printing #1814

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
32 changes: 32 additions & 0 deletions doc/user-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ stay on top of `alr` new features.

## Release `2.1`

### Abbreviated `--tree` output for repeating dependencies

PR [1814](https://github.com/alire-project/alire/pull/1814)

By default, repeated dependencies are now omitted by `--tree` output, e.g.:

```
$ alr show --tree libgpr2
...
Dependencies (tree):
gnat=14.1.3 (gnat_native) (>=14)
gnatcoll=25.0.0 (~25.0.0)
├── gnat=14.1.3 (gnat_native) (>=13)
└── libgpr=25.0.0 (~25.0.0)
├── gnat=14.1.3 (gnat_native) (/=2020)
└── xmlada=25.0.0 (~25.0.0)
└── gnat=14.1.3 (gnat_native) (>=11)
gnatcoll_gmp=25.0.0 (~25.0.0)
├── gnatcoll=25.0.0 (~25.0.0) ···
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest a small change. Make the suspension points on a new line like so:

   gnatcoll_gmp=25.0.0 (~25.0.0)
   ├── gnatcoll=25.0.0 (~25.0.0) 
       └── ...

This better shows that there are dependencies omitted in the output in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point.

└── libgmp=6.3.0 (*)
gnatcoll_iconv=25.0.0 (~25.0.0)
└── gnatcoll=25.0.0 (~25.0.0) ···
```

Whenever '...' appears, it means that the preceding release has its
dependencies already printed somewhere in the preceding tree lines.

The old behavior can be obtained by increasing verbosity with the global `-v`
switch.

### Faster `alr search` without resolving dependencies

PR [1799](https://github.com/alire-project/alire/pull/1799)

`alr search` no longer solves dependencies of releases by default, in order to
Expand Down
86 changes: 67 additions & 19 deletions src/alire/alire-solutions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ package body Alire.Solutions is
procedure Print_Tree (This : Solution;
Root : Alire.Releases.Release;
Prefix : String := "";
Print_Root : Boolean := True)
Print_Root : Boolean := True;
Concise : Boolean := not Detailed)
is

Mid_Node : constant String :=
Expand All @@ -925,14 +926,52 @@ package body Alire.Solutions is
(if TTY.Color_Enabled then U ("└── ") else "+-- ");
Branch : constant String :=
(if TTY.Color_Enabled then U ("│ ") else "| ");
More_Deps : constant String :=
(if TTY.Color_Enabled then U (" ···") else " ...");
No_Branch : constant String := " ";

Printed : AAA.Strings.Sets.Set;
-- Dependencies already printed, to avoid reprinting in Concise mode

-----------
-- Label --
-----------
-- The dependency Milestone or State
function Label (Dep : Dependencies.Dependency) return String
is (if This.State (Dep.Crate).Has_Release
then This.State (Dep.Crate).Milestone_Image
else This.State (Dep.Crate).TTY_Image);

-----------
-- Print --
-----------

procedure Print (Deps : Dependencies.Containers.Set;
Prefix : String := "";
Omit : Boolean := False)
-- Omit is used to remove the top-level connectors, for when the tree
-- is printed without the root release.
is

-------------------------------------
-- Inline_Concise_Marker_If_Needed --
-------------------------------------

function Inline_Concise_Marker_If_Needed
(Dep : Dependencies.Dependency) return String is
begin
if Concise
and then Printed.Contains (Label (Dep))
and then This.State (Dep.Crate).Has_Release
and then not Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).Is_Empty
then
return More_Deps;
else
return "";
end if;
end Inline_Concise_Marker_If_Needed;

Last : UString;
-- Used to store the last dependency name in a subtree, to be able to
-- use the proper ASCII connector. See just below.
Expand Down Expand Up @@ -966,27 +1005,36 @@ package body Alire.Solutions is

-- For a dependency solved by a release, print exact
-- version. Otherwise print the state of the dependency.
& (if This.State (Dep.Crate).Has_Release
then This.State (Dep.Crate).Milestone_Image
else This.State (Dep.Crate).TTY_Image)
& Label (Dep)

-- And dependency that introduces the crate in the solution
& " (" & TTY.Emph (Dep.Versions.Image) & ")");

-- Recurse for further releases

if This.State (Dep.Crate).Has_Release then
Print (Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).To_Set,
Prefix =>
Prefix
-- Indent adding the proper running connector
& (if Omit
then ""
else (if +Dep.Crate = +Last
then No_Branch -- End of this connector
else Branch))); -- "│" over the subtree
& " (" & TTY.Emph (Dep.Versions.Image) & ")"

-- If concise and this has dependencies, print the marker
& Inline_Concise_Marker_If_Needed (Dep)
);

-- Recurse for further releases if not conise and printed

if (not Concise or else not Printed.Contains (Label (Dep)))
and then This.State (Dep.Crate).Has_Release
and then not Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).Is_Empty
then
Print
(Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).To_Set,
Prefix =>
Prefix
-- Indent adding the proper running connector
& (if Omit
then ""
else (if +Dep.Crate = +Last
then No_Branch -- End of this connector
else Branch))); -- "│" over the subtree
end if;

Printed.Include (Label (Dep));
end if;
end loop;
end Print;
Expand Down
4 changes: 3 additions & 1 deletion src/alire/alire-solutions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ package Alire.Solutions is
procedure Print_Tree (This : Solution;
Root : Alire.Releases.Release;
Prefix : String := "";
Print_Root : Boolean := True);
Print_Root : Boolean := True;
Concise : Boolean := not Detailed);
-- Print the solution in tree form. If Print_Root, Root is printed too;
-- otherwise the tree is a forest starting at Root direct dependencies.
-- If Concise, print each unique dependency only once.

procedure Print_Versions (This : Solution;
Root : Roots.Root);
Expand Down
42 changes: 42 additions & 0 deletions testsuite/tests/with/tree-concise/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Test the concise mode of the --tree switch. Repeating dependencies are
substituted by a "..." ellipsis.
"""

import os
import re
from drivers.alr import run_alr, alr_with, init_local_crate
from drivers.asserts import assert_eq, assert_match

# Prepare a crate in which dependencies appear twice, so their dependencies in
# turn can be elided.

init_local_crate("yyy")
alr_with("hello")
os.chdir("..")
init_local_crate("xxx")
alr_with("hello")
alr_with("yyy", path="../yyy")

# Check the concise tree
assert_eq("""\
xxx=0.1.0-dev
+-- hello=1.0.1 (*)
| +-- libhello=1.0.0 (^1.0)
+-- yyy=0.1.0-dev (*)
+-- hello=1.0.1 (*) ...\
""",
run_alr("with", "--tree").out.strip())

# Check the regular tree
assert_match(".*" + re.escape("""\
xxx=0.1.0-dev
+-- hello=1.0.1 (*)
| +-- libhello=1.0.0 (^1.0)
+-- yyy=0.1.0-dev (*)
+-- hello=1.0.1 (*)
+-- libhello=1.0.0 (^1.0)\
"""),
run_alr("-v", "with", "--tree", quiet=False).out.strip())

print("SUCCESS")
5 changes: 5 additions & 0 deletions testsuite/tests/with/tree-concise/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: python-script
build_mode: both
indexes:
basic_index:
in_fixtures: true
Loading