mvn-tree-visualizer 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mvn-tree-visualizer might be problematic. Click here for more details.

@@ -1,5 +1,6 @@
1
1
  import argparse
2
2
  from pathlib import Path
3
+ from typing import NoReturn
3
4
 
4
5
  from .diagram import create_diagram
5
6
  from .get_dependencies_in_one_file import merge_files
@@ -7,7 +8,7 @@ from .outputs.html_output import create_html_diagram
7
8
  from .outputs.json_output import create_json_output
8
9
 
9
10
 
10
- def cli():
11
+ def cli() -> NoReturn:
11
12
  parser = argparse.ArgumentParser(
12
13
  prog="mvn-tree-visualizer",
13
14
  description="Generate a dependency diagram from a file.",
@@ -50,12 +51,19 @@ def cli():
50
51
  help="Keep the dependency tree file after generating the diagram. Default is False.",
51
52
  )
52
53
 
54
+ parser.add_argument(
55
+ "--show-versions",
56
+ action="store_true",
57
+ help="Show dependency versions in the diagram. Applicable to both HTML and JSON output formats.",
58
+ )
59
+
53
60
  args = parser.parse_args()
54
61
  directory: str = args.directory
55
62
  output_file: str = args.output
56
63
  filename: str = args.filename
57
64
  keep_tree: bool = args.keep_tree
58
65
  output_format: str = args.format
66
+ show_versions: bool = args.show_versions
59
67
 
60
68
  dir_to_create_files = Path(output_file).parent
61
69
 
@@ -73,9 +81,9 @@ def cli():
73
81
  )
74
82
 
75
83
  if output_format == "html":
76
- create_html_diagram(dependency_tree, output_file)
84
+ create_html_diagram(dependency_tree, output_file, show_versions)
77
85
  elif output_format == "json":
78
- create_json_output(dependency_tree, output_file)
86
+ create_json_output(dependency_tree, output_file, show_versions)
79
87
 
80
88
  print(f"Diagram generated and saved to {output_file}")
81
89
  print("You can open it in your browser to view the dependency tree.")
@@ -83,4 +91,4 @@ def cli():
83
91
 
84
92
 
85
93
  if __name__ == "__main__":
86
- cli()
94
+ cli()
@@ -1,13 +1,14 @@
1
+ import os
2
+
3
+
1
4
  def create_diagram(
2
5
  keep_tree: bool = False,
3
6
  intermediate_filename: str = "dependency_tree.txt",
4
- ):
7
+ ) -> str:
5
8
  with open(intermediate_filename, "r") as file:
6
- dependency_tree = file.read()
9
+ dependency_tree: str = file.read()
7
10
 
8
11
  if not keep_tree:
9
- import os
10
-
11
12
  os.remove(intermediate_filename)
12
-
13
+
13
14
  return dependency_tree
@@ -1,11 +1,13 @@
1
1
  import os
2
+ from pathlib import Path
3
+ from typing import Union
2
4
 
3
5
 
4
- def merge_files(output_file: str, root_dir: str = ".", target_filename: str = "maven_dependency_file"):
6
+ def merge_files(output_file: Union[str, Path], root_dir: str = ".", target_filename: str = "maven_dependency_file") -> None:
5
7
  with open(output_file, "w", encoding="utf-8") as outfile:
6
8
  for dirpath, _, filenames in os.walk(root_dir):
7
9
  for fname in filenames:
8
10
  if fname == target_filename:
9
- file_path = os.path.join(dirpath, fname)
11
+ file_path: str = os.path.join(dirpath, fname)
10
12
  with open(file_path, "r", encoding="utf-8") as infile:
11
13
  outfile.write(infile.read())
@@ -1,49 +1,65 @@
1
1
  from pathlib import Path
2
+ from typing import List, Set, Tuple
3
+
2
4
  from jinja2 import BaseLoader, Environment
5
+
3
6
  from ..TEMPLATE import HTML_TEMPLATE
4
7
 
5
- def create_html_diagram(dependency_tree: str, output_filename: str):
6
- mermaid_diagram = _convert_to_mermaid(dependency_tree)
8
+
9
+ def create_html_diagram(dependency_tree: str, output_filename: str, show_versions: bool = False) -> None:
10
+ mermaid_diagram: str = _convert_to_mermaid(dependency_tree, show_versions)
7
11
  template = Environment(loader=BaseLoader).from_string(HTML_TEMPLATE)
8
- rendered = template.render(diagram_definition=mermaid_diagram)
9
- parent_dir = Path(output_filename).parent
12
+ rendered: str = template.render(diagram_definition=mermaid_diagram)
13
+ parent_dir: Path = Path(output_filename).parent
10
14
  if not parent_dir.exists():
11
15
  parent_dir.mkdir(parents=True, exist_ok=True)
12
16
  with open(output_filename, "w") as f:
13
17
  f.write(rendered)
14
18
 
15
- def _convert_to_mermaid(dependency_tree: str) -> str:
19
+
20
+ def _convert_to_mermaid(dependency_tree: str, show_versions: bool = False) -> str:
16
21
  # generate a `graph LR` format for Mermaid
17
- lines = dependency_tree.strip().split("\n")
18
- mermaid_lines = set()
19
- previous_dependency = []
22
+ lines: List[str] = dependency_tree.strip().split("\n")
23
+ mermaid_lines: Set[str] = set()
24
+ previous_dependency: List[Tuple[str, int]] = []
20
25
  for line in lines:
21
26
  if not line:
22
27
  continue
23
28
  if line.startswith("[INFO] "):
24
29
  line = line[7:] # Remove the "[INFO] " prefix
25
- parts = line.split(":")
30
+ parts: List[str] = line.split(":")
26
31
  if len(parts) < 3:
27
32
  continue
28
33
  if len(parts) == 4:
29
34
  group_id, artifact_id, app, version = parts
30
- mermaid_lines.add(f"\t{artifact_id};")
35
+ if show_versions:
36
+ node_label: str = f"{artifact_id}:{version}"
37
+ mermaid_lines.add(f"\t{node_label};")
38
+ else:
39
+ node_label: str = artifact_id
40
+ mermaid_lines.add(f"\t{artifact_id};")
31
41
  if previous_dependency: # Re initialize the list if it wasn't empty
32
42
  previous_dependency = []
33
- previous_dependency.append((artifact_id, 0)) # The second element is the depth
43
+ previous_dependency.append((node_label, 0)) # The second element is the depth
34
44
  else:
35
- depth = len(parts[0].split(" ")) - 1
45
+ depth: int = len(parts[0].split(" ")) - 1
36
46
  if len(parts) == 6:
37
47
  dirty_group_id, artifact_id, app, ejb_client, version, dependency = parts
38
48
  else:
39
49
  dirty_group_id, artifact_id, app, version, dependency = parts
50
+
51
+ if show_versions:
52
+ node_label: str = f"{artifact_id}:{version}"
53
+ else:
54
+ node_label: str = artifact_id
55
+
40
56
  if previous_dependency[-1][1] < depth:
41
- mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
42
- previous_dependency.append((artifact_id, depth))
57
+ mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {node_label};")
58
+ previous_dependency.append((node_label, depth))
43
59
  else:
44
60
  # remove all dependencies that are deeper or equal to the current depth
45
61
  while previous_dependency and previous_dependency[-1][1] >= depth:
46
62
  previous_dependency.pop()
47
- mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
48
- previous_dependency.append((artifact_id, depth))
63
+ mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {node_label};")
64
+ previous_dependency.append((node_label, depth))
49
65
  return "graph LR\n" + "\n".join(mermaid_lines)
@@ -1,9 +1,11 @@
1
1
  import json
2
+ from typing import Any, Dict, List, Tuple
2
3
 
3
- def create_json_output(dependency_tree: str, output_filename: str):
4
- lines = dependency_tree.strip().split("\n")
5
- tree = {}
6
- node_stack = [] # Stack to keep track of nodes and their depth
4
+
5
+ def create_json_output(dependency_tree: str, output_filename: str, show_versions: bool = False) -> None:
6
+ lines: List[str] = dependency_tree.strip().split("\n")
7
+ tree: Dict[str, Any] = {}
8
+ node_stack: List[Tuple[Dict[str, Any], int]] = [] # Stack to keep track of nodes and their depth
7
9
 
8
10
  for line in lines:
9
11
  if not line:
@@ -11,33 +13,43 @@ def create_json_output(dependency_tree: str, output_filename: str):
11
13
  if line.startswith("[INFO] "):
12
14
  line = line[7:] # Remove the "[INFO] " prefix
13
15
 
14
- parts = line.split(":")
16
+ parts: List[str] = line.split(":")
15
17
  if len(parts) < 3:
16
18
  continue
17
19
 
18
20
  # Root node
19
21
  if len(parts) == 4:
20
22
  group_id, artifact_id, _, version = parts
21
- node = {"id": f"{group_id}:{artifact_id}:{version}", "children": []}
23
+ if show_versions:
24
+ node_id: str = f"{group_id}:{artifact_id}:{version}"
25
+ else:
26
+ node_id: str = f"{group_id}:{artifact_id}"
27
+ node: Dict[str, Any] = {"id": node_id, "children": []}
22
28
  tree = node
23
29
  node_stack = [(node, 0)] # Reset stack with root node at depth 0
24
30
  # Child node
25
31
  else:
26
32
  # This depth calculation is based on the mermaid logic's whitespace parsing
27
- depth = len(parts[0].split(" ")) - 1
33
+ depth: int = len(parts[0].split(" ")) - 1
28
34
 
29
35
  if len(parts) == 6:
30
36
  _, artifact_id, _, _, version, _ = parts
31
37
  else:
32
38
  _, artifact_id, _, version, _ = parts
33
39
 
34
- node = {"id": f"{artifact_id}:{version}", "children": []}
40
+ if show_versions:
41
+ node_id: str = f"{artifact_id}:{version}"
42
+ else:
43
+ node_id: str = artifact_id
44
+
45
+ node: Dict[str, Any] = {"id": node_id, "children": []}
35
46
 
36
47
  # Go up the stack to find the correct parent
37
48
  while node_stack and node_stack[-1][1] >= depth:
38
49
  node_stack.pop()
39
50
 
40
51
  if node_stack:
52
+ parent_node: Dict[str, Any]
41
53
  parent_node, _ = node_stack[-1]
42
54
  parent_node["children"].append(node)
43
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mvn-tree-visualizer
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A simple command line tool to visualize the dependency tree of a Maven project in a graphical format.
5
5
  Project-URL: source, https://github.com/dyka3773/mvn-tree-visualizer
6
6
  Author-email: Iraklis Konsoulas <dyka3773@gmail.com>
@@ -12,6 +12,7 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.13
14
14
  Classifier: Topic :: Software Development :: Build Tools
15
+ Classifier: Typing :: Typed
15
16
  Requires-Python: >=3.13
16
17
  Requires-Dist: jinja2>=3.1.6
17
18
  Description-Content-Type: text/markdown
@@ -22,11 +23,14 @@ Description-Content-Type: text/markdown
22
23
 
23
24
  A simple command-line tool to visualize the dependency tree of a Maven project in a graphical and interactive format.
24
25
 
25
- This tool was born out of the frustration of not being able to easily visualize the dependency tree of a Maven project. The `mvn dependency:tree` command is great, but the output can be hard to read, especially for large projects. This tool aims to solve that problem by providing a simple way to generate an interactive diagram of the dependency tree.
26
+ This tool was born out of the frustration of not being able to easily visualize the dependency tree of a Maven project. The `mvn dependency:tree` command is great, but the output can be hard to read, especially for large projects. This tool aims to solve that problem by providing a simple way to generate an interactive diagram or a structured JSON output of the dependency tree.
26
27
 
27
28
  ## Features
28
29
 
29
- * **Interactive Diagrams:** Generates an interactive HTML diagram of your dependency tree using Mermaid.js.
30
+ * **Multiple Output Formats:**
31
+ * **HTML:** Generates an interactive HTML diagram of your dependency tree using Mermaid.js.
32
+ * **JSON:** Creates a structured JSON representation of the dependency tree, perfect for scripting or integration with other tools.
33
+ * **Version Display:** Show or hide dependency versions in both HTML and JSON outputs using the `--show-versions` flag.
30
34
  * **Easy to Use:** A simple command-line interface that gets the job done with minimal configuration.
31
35
  * **File Merging:** Automatically finds and merges multiple `maven_dependency_file` files from different subdirectories.
32
36
  * **Customizable Output:** Specify the output file name and location.
@@ -45,17 +49,36 @@ This tool was born out of the frustration of not being able to easily visualize
45
49
  2. **Visualize the dependency tree:**
46
50
  Use the `mvn-tree-visualizer` command to generate the diagram.
47
51
 
52
+ **For an HTML diagram:**
48
53
  ```bash
49
- mvn_tree_visualizer --filename "maven_dependency_file" --output "diagram.html"
54
+ mvn_tree_visualizer --filename "maven_dependency_file" --output "diagram.html" --format html
50
55
  ```
51
56
 
52
- 3. **View the diagram:**
53
- Open the generated `diagram.html` file in your web browser to view the interactive dependency tree.
57
+ **For a JSON output:**
58
+ ```bash
59
+ mvn_tree_visualizer --filename "maven_dependency_file" --output "dependencies.json" --format json
60
+ ```
61
+
62
+ **With version information displayed:**
63
+ ```bash
64
+ mvn_tree_visualizer --filename "maven_dependency_file" --output "diagram.html" --show-versions
65
+ ```
66
+
67
+ **JSON output with versions:**
68
+ ```bash
69
+ mvn_tree_visualizer --filename "maven_dependency_file" --output "dependencies.json" --format json --show-versions
70
+ ```
71
+
72
+ 3. **View the output:**
73
+ * Open the generated `diagram.html` file in your web browser to view the interactive dependency tree.
74
+ * Use the `dependencies.json` file in your scripts or other tools.
54
75
 
55
76
  ## Options
56
77
 
57
78
  * `--filename`: The name of the file containing the Maven dependency tree. Defaults to `maven_dependency_file`.
58
- * `--output`: The name of the output HTML file. Defaults to `diagram.html`.
79
+ * `--output`: The name of the output file. Defaults to `diagram.html`.
80
+ * `--format`: The output format. Can be `html` or `json`. Defaults to `html`.
81
+ * `--show-versions`: Show dependency versions in the diagram. Applicable to both HTML and JSON output formats.
59
82
  * `--directory`: The directory to scan for the Maven dependency file(s). Defaults to the current directory.
60
83
  * `--keep-tree`: Keep the intermediate `dependency_tree.txt` file after generating the diagram. Defaults to `False`.
61
84
  * `--help`: Show the help message and exit.
@@ -68,4 +91,4 @@ Please read our [CONTRIBUTING.md](CONTRIBUTING.md) file for more details.
68
91
 
69
92
  ## License
70
93
 
71
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
94
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,13 @@
1
+ mvn_tree_visualizer/TEMPLATE.py,sha256=WIQfSNBygUZVkBrERq7QzqouGURA0NYVqUUm-11wMvo,2499
2
+ mvn_tree_visualizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ mvn_tree_visualizer/__main__.py,sha256=yIQFAdWjthKAFbSzzRuz5_YGlK0c6BnR2ypjNRDq180,82
4
+ mvn_tree_visualizer/cli.py,sha256=Pygjrz87rge2Bfpy1ePucjER8PL2ZP1fBJCRax4otqo,2761
5
+ mvn_tree_visualizer/diagram.py,sha256=8If6rNbyBZlM_BkQwpGTE3W3bHHxcJ_5MMBc2NnJZWM,313
6
+ mvn_tree_visualizer/get_dependencies_in_one_file.py,sha256=1UQUWny5t5QLbE2HOkK_BXSIU3BP7Qjx8mo6yEhMFi4,580
7
+ mvn_tree_visualizer/outputs/html_output.py,sha256=QwUZRzNUCKrpdOq6BHadIJSU47W_1Kat-ouzwue-olA,2857
8
+ mvn_tree_visualizer/outputs/json_output.py,sha256=49X02e3gNoKzBj2FYGKOwuyaX0s5pxWIQUZPruCTbTQ,2064
9
+ mvn_tree_visualizer-1.2.0.dist-info/METADATA,sha256=ZJNzw2z2zRItzBof4tFGrotsBL7SBumgaranNor4BWc,4603
10
+ mvn_tree_visualizer-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ mvn_tree_visualizer-1.2.0.dist-info/entry_points.txt,sha256=Mu3QZhrlvbYuCxqmluVGi2efgKjkQY6T8Opf-vdb7hU,68
12
+ mvn_tree_visualizer-1.2.0.dist-info/licenses/LICENSE,sha256=4zi6unpe17RUDMBu7ebh14jdbyvyeT-UA3n8Zl7aW74,1075
13
+ mvn_tree_visualizer-1.2.0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- mvn_tree_visualizer/TEMPLATE.py,sha256=WIQfSNBygUZVkBrERq7QzqouGURA0NYVqUUm-11wMvo,2499
2
- mvn_tree_visualizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- mvn_tree_visualizer/__main__.py,sha256=yIQFAdWjthKAFbSzzRuz5_YGlK0c6BnR2ypjNRDq180,82
4
- mvn_tree_visualizer/cli.py,sha256=P3v27Axod-aYkhtnoAh06RnScUTR2k9QZ3vVGkolHg8,2451
5
- mvn_tree_visualizer/diagram.py,sha256=elUQHCFu9DPeCpcLkjlRg-xl-fAEn8TvMWpIho1vo0E,312
6
- mvn_tree_visualizer/get_dependencies_in_one_file.py,sha256=sX669Lo3gsv-dTvaf4PNSQMTp3Gx3CKwqBmJQFiQF04,504
7
- mvn_tree_visualizer/outputs/html_output.py,sha256=rCD55g8aUdYiPs2Mkd9VB0dBKvMZu0Va3uYGZkJxO20,2295
8
- mvn_tree_visualizer/outputs/json_output.py,sha256=v9aRPaCDMG-zyVdg82YPhPRyFCNLaWXPcdRmnpzuajg,1554
9
- mvn_tree_visualizer-1.1.0.dist-info/METADATA,sha256=VmIy1sZ1XHWlqnXJwzFKuG1Z3yxqZ2YV7OlEPaNvIuM,3470
10
- mvn_tree_visualizer-1.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- mvn_tree_visualizer-1.1.0.dist-info/entry_points.txt,sha256=Mu3QZhrlvbYuCxqmluVGi2efgKjkQY6T8Opf-vdb7hU,68
12
- mvn_tree_visualizer-1.1.0.dist-info/licenses/LICENSE,sha256=4zi6unpe17RUDMBu7ebh14jdbyvyeT-UA3n8Zl7aW74,1075
13
- mvn_tree_visualizer-1.1.0.dist-info/RECORD,,