From 3740b6f011e31c7369c76a5445e67de3c05f9bf6 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Thu, 26 May 2022 11:06:06 +0800 Subject: [PATCH] feat: new supported output formats --- README.md | 20 +-- compose_viz/__init__.py | 2 +- compose_viz/cli.py | 22 ++- compose_viz/graph.py | 2 +- compose_viz/viz_formats.py | 45 ++++++ examples/voting-app/compose-viz.svg | 210 ++++++++++++++++++++++++++++ pyproject.toml | 4 +- 7 files changed, 277 insertions(+), 28 deletions(-) create mode 100644 compose_viz/viz_formats.py create mode 100644 examples/voting-app/compose-viz.svg diff --git a/README.md b/README.md index 508f715..20f913a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## About The Project -`compose-viz` is a compose file visualization tool that supports [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) and allows you to gernerate graph in [DOT](https://graphviz.org/doc/info/lang.html) format or `.png`. +`compose-viz` is a compose file visualization tool that supports [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) and allows you to gernerate graph in several formats. If you are looking for a compose file vizualization tool, and you are using one of the [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) implementations (e.g. [docker-compose](https://github.com/docker/compose)/[podman-compose](https://github.com/containers/podman-compose)), then `compose-viz` is a great choice for you. @@ -70,7 +70,7 @@ If you are looking for a compose file vizualization tool, and you are using one #### Graphviz -If you want to generate PNG (which is the default option), you need to install [Graphviz](https://graphviz.org/download/). +You need to install [Graphviz](https://graphviz.org/download/) to generate graphs. ### Installation @@ -93,9 +93,9 @@ cpv docker-compose.yml And this is what the result looks like: -![compose-viz.png](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.png) +![compose-viz.svg](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.svg) -Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.png). +Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app). ### Usage @@ -103,12 +103,12 @@ Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main ### Options -| Option | Description | -| ------------------------ | ------------------------------------------------------------------------------ | -| `-o, --output-path` | Output path for the generated visualization file. [default: ./compose-viz.png] | -| `-m, --format [PNG,DOT]` | Output format for the generated visualization file. [default: PNG] | -| `-v, --version` | Show the version of compose-viz. | -| `--help` | Show help and exit. | +| Option | Description | +| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `-o, --output-filename` | Output filename for the generated visualization file. [default: compose-viz] | +| `-m, --format` | Output format for the generated visualization file. See [supported formats](https://github.com/compose-viz/compose-viz/blob/main/compose_viz/viz_formats.py). [default: png] | +| `-v, --version` | Show the version of compose-viz. | +| `--help` | Show help and exit. |

(back to top)

diff --git a/compose_viz/__init__.py b/compose_viz/__init__.py index 467be58..606db7b 100644 --- a/compose_viz/__init__.py +++ b/compose_viz/__init__.py @@ -1,2 +1,2 @@ __app_name__ = "compose_viz" -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/compose_viz/cli.py b/compose_viz/cli.py index e028d70..ffb10bd 100644 --- a/compose_viz/cli.py +++ b/compose_viz/cli.py @@ -1,4 +1,3 @@ -from enum import Enum from typing import Optional import typer @@ -6,12 +5,7 @@ import typer from compose_viz import __app_name__, __version__ from compose_viz.graph import Graph from compose_viz.parser import Parser - - -class VisualizationFormats(str, Enum): - png = "PNG" - dot = "DOT" - +from compose_viz.viz_formats import VizFormats app = typer.Typer( invoke_without_command=True, @@ -30,14 +24,14 @@ def _version_callback(value: bool) -> None: @app.callback() def compose_viz( input_path: str, - output_path: str = typer.Option( - "./compose-viz.png", - "--output-path", + output_filename: str = typer.Option( + "compose-viz", + "--output-filename", "-o", - help="Output path for the generated visualization file.", + help="Output filename for the generated visualization file.", ), - format: VisualizationFormats = typer.Option( - "PNG", + format: VizFormats = typer.Option( + "png", "--format", "-m", help="Output format for the generated visualization file.", @@ -57,7 +51,7 @@ def compose_viz( if compose: typer.echo(f"Successfully parsed {input_path}") - Graph(compose, output_path).render(format) + Graph(compose, output_filename).render(format) raise typer.Exit() diff --git a/compose_viz/graph.py b/compose_viz/graph.py index 57e34f5..32c5569 100644 --- a/compose_viz/graph.py +++ b/compose_viz/graph.py @@ -93,4 +93,4 @@ class Graph: for depends_on in service.depends_on: self.add_edge(service.name, depends_on, "depends_on") - self.dot.render(outfile=self.filename, format=format, cleanup=cleanup) + self.dot.render(outfile=f"{self.filename}.{format}", format=format, cleanup=cleanup) diff --git a/compose_viz/viz_formats.py b/compose_viz/viz_formats.py new file mode 100644 index 0000000..e81b832 --- /dev/null +++ b/compose_viz/viz_formats.py @@ -0,0 +1,45 @@ +from enum import Enum + + +class VizFormats(str, Enum): + png = "png" + dot = "dot" + jpeg = "jpeg" + json = "json" + svg = "svg" + + bmp = "bmp" + canon = "canon" + cmap = "cmap" + cmapx = "cmapx" + cmapx_np = "cmapx_np" + dot_json = "dot_json" + emf = "emf" + emfplus = "emfplus" + eps = "eps" + fig = "fig" + gif = "gif" + gv = "gv" + imap = "imap" + imap_np = "imap_np" + ismap = "ismap" + jpe = "jpe" + jpg = "jpg" + json0 = "json0" + metafile = "metafile" + mp = "mp" + pdf = "pdf" + pic = "pic" + plain = "plain" + plain_ext = "plain-ext" + pov = "pov" + ps = "ps" + ps2 = "ps2" + tif = "tif" + tiff = "tiff" + tk = "tk" + vml = "vml" + xdot = "xdot" + xdot1_2 = "xdot1.2" + xdot1_4 = "xdot1.4" + xdot_json = "xdot_json" diff --git a/examples/voting-app/compose-viz.svg b/examples/voting-app/compose-viz.svg new file mode 100644 index 0000000..f16a8ee --- /dev/null +++ b/examples/voting-app/compose-viz.svg @@ -0,0 +1,210 @@ + + + + + + + + + +redis + + + +redis +(redis:alpine) + + + +frontend + +net:frontend + + + +redis->frontend + + + + + +0.0.0.06379 + +0.0.0.0:6379 + + + +0.0.0.06379->redis + + + +6379 + + + +db + + + +db +(postgres:9.4) + + + +backend + +net:backend + + + +db->backend + + + + + +db-data + +db-data + + + +db->db-data + + + +/var/lib/postgresql/data + + + +vote + + + +vote +(dockersamples/examplevotingapp_vote:before) + + + +vote->redis + + + + + +vote->frontend + + + + + +0.0.0.05000 + +0.0.0.0:5000 + + + +0.0.0.05000->vote + + + +80 + + + +result + + + +result +(dockersamples/examplevotingapp_result:before) + + + +result->db + + + + + +result->backend + + + + + +0.0.0.05001 + +0.0.0.0:5001 + + + +0.0.0.05001->result + + + +80 + + + +worker + + + +worker +(dockersamples/examplevotingapp_worker) + + + +worker->frontend + + + + + +worker->backend + + + + + +visualizer + + + +visualizer +(dockersamples/visualizer) + + + +/var/run/docker.sock + +/var/run/docker.sock + + + +visualizer->/var/run/docker.sock + + + +/var/run/docker.sock + + + +0.0.0.08080 + +0.0.0.0:8080 + + + +0.0.0.08080->visualizer + + + +8080 + + + diff --git a/pyproject.toml b/pyproject.toml index 43a2b36..4ba3c53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "compose-viz" -version = "0.1.1" -description = "A compose file visualization tool that supports compose-spec and allows you to gernerate graph in DOT format or PNG." +version = "0.1.2" +description = "A compose file visualization tool that supports compose-spec and allows you to gernerate graph in several formats." authors = ["Xyphuz Wu "] readme = "README.md" license = "MIT"