Skip to content
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Authors
=======

* David Seddon - https://seddonym.me
* Fabien Marty - https://fabien-marty.dev
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

2.3 (not released yet)
----------------------
* Add --format option to control the output format.
* Add --force-console option to force the use of the console output.

2.2 (2025-12-12)
----------------

Expand Down
52 changes: 51 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ There is currently only one command.
--show-cycle-breakers Identify a set of dependencies that, if removed,
would make the graph acyclic, and display them as
dashed lines.
--format [html|dot] Output format (default to html).
--force-console Force the use of the console output.
--help Show this message and exit.

Draw a graph of the dependencies within any installed Python package or subpackage.
Expand Down Expand Up @@ -119,4 +121,52 @@ within ``django.db.utils``.

Here you can see that two of the dependencies are shown as a dashed line. If these dependencies were to be
removed, the graph would be acyclic. To decide on the cycle breakers, Impulse uses the
`nominate_cycle_breakers method provided by Grimp <https://grimp.readthedocs.io/en/stable/usage.html#ImportGraph.nominate_cycle_breakers>`_.
`nominate_cycle_breakers method provided by Grimp <https://grimp.readthedocs.io/en/stable/usage.html#ImportGraph.nominate_cycle_breakers>`_.

Output formats
**************

By default, Impulse renders the graph as an interactive HTML page and opens it in your browser.
You can change the output format using the ``--format`` option.

**HTML format (default)**

.. code-block:: text

impulse drawgraph django.db --format html

Generates an HTML page with an interactive graph visualization, including download links for SVG and PNG.
This is the default format when no ``--format`` option is specified.

**DOT format**

.. code-block:: text

impulse drawgraph django.db --format dot

Outputs the graph in `DOT format <https://graphviz.org/doc/info/lang.html>`_, which can be used with
Graphviz or other tools that support this format. This is useful for custom rendering or integration
with other systems.

For example, to generate a PNG using Graphviz:

.. code-block:: text

impulse drawgraph django.db --format dot | dot -Tpng -o graph.png

Redirecting output
******************

When you redirect the output to a file or pipe it to another command, Impulse automatically switches
from opening a browser to printing to the console:

.. code-block:: text

impulse drawgraph django.db > graph.html

If you want to force console output even when running interactively (e.g., for scripting purposes),
use the ``--force-console`` flag:

.. code-block:: text

impulse drawgraph django.db --force-console
32 changes: 32 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@ test:
@uv run --with=google-cloud-audit-log impulse drawgraph google.cloud.audit
@uv run impulse drawgraph grimp --show-import-totals
@uv run --with=django impulse drawgraph django.db --show-cycle-breakers
@just test-output-redirection

# Test output redirection (HTML and DOT formats)
test-output-redirection:
#!/usr/bin/env bash
set -euo pipefail

# Create unique temporary files (using -t for macOS compatibility)
html_output=$(mktemp -t impulse_test.XXXXXX.html)
dot_output=$(mktemp -t impulse_test.XXXXXX.dot)
force_console_output=$(mktemp -t impulse_test.XXXXXX.html)
trap 'rm -f "$html_output" "$dot_output" "$force_console_output"' EXIT

echo "Testing HTML output redirection..."
uv run impulse drawgraph grimp > "$html_output"
grep -q '<!DOCTYPE html>' "$html_output"
grep -q 'digraph' "$html_output"
echo "HTML output redirection: OK"

echo "Testing DOT format output..."
uv run impulse drawgraph grimp --format=dot > "$dot_output"
grep -q 'digraph' "$dot_output"
# DOT format should not contain HTML tags
! grep -q '<!DOCTYPE html>' "$dot_output"
echo "DOT format output: OK"

echo "Testing --force-console flag..."
uv run impulse drawgraph grimp --force-console > "$force_console_output"
grep -q '<!DOCTYPE html>' "$force_console_output"
echo "--force-console flag: OK"

echo "All output redirection tests passed!"


# Run tests under all supported Python versions.
Expand Down
Loading