Skip to content

Commit dab81d9

Browse files
authored
Simplify UX of aliBuild deps (#1010)
1 parent c881766 commit dab81d9

File tree

4 files changed

+14
-52
lines changed

4 files changed

+14
-52
lines changed

alibuild_helpers/args.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,8 @@ def doParseArgs():
212212
"with commas."))
213213
deps_parser.add_argument("-e", dest="environment", action="append", default=[],
214214
help="KEY=VALUE binding to add to the environment. May be specified multiple times.")
215-
216-
deps_graph = deps_parser.add_argument_group(title="Customise graph output")
217-
deps_graph.add_argument("--neat", dest="neat", action="store_true",
218-
help="Produce a graph with transitive reduction.")
219-
deps_graph.add_argument("--outdot", dest="outdot", metavar="FILE",
220-
help="Keep intermediate Graphviz dot file in %(metavar)s.")
221-
deps_graph.add_argument("--outgraph", dest="outgraph", metavar="FILE",
222-
help="Store final output PDF file in %(metavar)s.")
215+
deps_parser.add_argument("--output,-o", dest="output", metavar="FILE",
216+
help="Save output to %(metavar)s.")
223217

224218
deps_docker = deps_parser.add_argument_group(title="Use a Docker container", description="""\
225219
If you're planning to build inside a Docker container, e.g. using aliBuild

alibuild_helpers/deps.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#!/usr/bin/env python3
22

3-
from alibuild_helpers.log import debug, error, info, dieOnError
3+
from alibuild_helpers.log import debug, dieOnError
44
from alibuild_helpers.utilities import parseDefaults, readDefaults, getPackageList, validateDefaults
55
from alibuild_helpers.cmd import DockerRunner, execute
6-
from tempfile import NamedTemporaryFile
7-
from os import remove, path
6+
from os import path
7+
import sys
88

99
def doDeps(args, parser):
10-
11-
# Check if we have an output file
12-
if not args.outgraph:
13-
parser.error("Specify a PDF output file with --outgraph")
14-
1510
# Resolve all the package parsing boilerplate
1611
specs = {}
1712
defaultsReader = lambda: readDefaults(args.configDir, args.defaults, parser.error, args.architecture)
@@ -93,28 +88,8 @@ def performCheck(pkg, cmd):
9388

9489
dot += "}\n"
9590

96-
if args.outdot:
97-
fp = open(args.outdot, "w")
91+
if getattr(args, "output", None) and args.output != "-":
92+
fp = open(args.output, "w")
9893
else:
99-
fp = NamedTemporaryFile(delete=False, mode="wt")
94+
fp = sys.stdout
10095
fp.write(dot)
101-
fp.close()
102-
103-
# Check if we have dot in PATH
104-
try:
105-
execute(["dot", "-V"])
106-
except Exception:
107-
dieOnError(True, "Could not find dot in PATH. Please install graphviz and add it to PATH.")
108-
try:
109-
if args.neat:
110-
execute("tred {dotFile} > {dotFile}.0 && mv {dotFile}.0 {dotFile}".format(dotFile=fp.name))
111-
execute(["dot", fp.name, "-Tpdf", "-o", args.outgraph])
112-
except Exception as e:
113-
error("Error generating dependencies with dot: %s: %s", type(e).__name__, e)
114-
else:
115-
info("Dependencies graph generated: %s" % args.outgraph)
116-
if fp.name != args.outdot:
117-
remove(fp.name)
118-
else:
119-
info("Intermediate dot file for Graphviz saved: %s" % args.outdot)
120-
return True

docs/docs/user.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ It is possible to generating a PDF with a dependency graph using the `aliBuild d
371371
tool. Assuming you run it from a directory containing `alidist`, and you have
372372
Graphviz installed on your system, you can simply run:
373373

374-
aliBuild deps O2 --outgraph graph.pdf
374+
aliBuild deps O2 | dot -Tpdf -o graph.pdf
375375

376376
The example above generates a dependency graph for the package `O2`, and saving
377377
the results to a PDF file named `graph.pdf`. This is what the graph looks like:
@@ -389,19 +389,12 @@ By default, `aliBuild deps` runs the usual system checks to exclude packages tha
389389
be taken from the system. If you want to display the full list of dependencies,
390390
you may want to use:
391391

392-
aliBuild deps O2 --no-system --outgraph graph.pdf
392+
aliBuild deps O2 --no-system | dot -Tpdf -o graph.pdf
393393

394-
Additional useful options for `aliBuild deps` include:
394+
As usual you can customise the input of dot using `tred` to produce a graph with
395+
a transitive reduction:
395396

396-
- `--neat`: Produce a graph with transitive reduction, removing edges that are
397-
implied by other paths in the graph. This can make complex dependency graphs
398-
easier to read.
399-
- `--outdot FILE`: Keep the intermediate Graphviz dot file in `FILE`. Useful if
400-
you want to manually modify the graph or generate output in different formats.
401-
402-
For example, to generate a simplified graph and keep the dot file:
403-
404-
aliBuild deps O2 --neat --outdot graph.dot --outgraph graph.pdf
397+
aliBuild deps O2 --no-system | tred | dot -Tpdf -o graph.pdf
405398

406399
Please run `aliBuild deps --help` for further information.
407400

tests/test_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class FakeExit(Exception):
7272
(("sw3", "mydir"), "init" , [("action", "init"), ("workDir", "sw3"), ("referenceSources", "sw3/MIRROR"), ("chdir", "mydir")]),
7373
(("sw", ".") , "clean --chdir mydir2 --work-dir sw4" , [("action", "clean"), ("workDir", "sw4"), ("chdir", "mydir2")]),
7474
(() , "doctor zlib -C mydir -w sw2" , [("action", "doctor"), ("workDir", "sw2"), ("chdir", "mydir")]),
75-
(() , "deps zlib --outgraph graph.pdf" , [("action", "deps"), ("outgraph", "graph.pdf")]),
75+
(() , "deps zlib --output graph.pdf" , [("action", "deps"), ("output", "graph.pdf")]),
7676
(() , "completion bash" , [("action", "completion"), ("shell", "bash")]),
7777
(() , "completion zsh" , [("action", "completion"), ("shell", "zsh")]),
7878
]

0 commit comments

Comments
 (0)