mvn-tree-visualizer 1.0.3b3__py3-none-any.whl → 1.0.3b4__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.
- dependency_diagram_template.j2 → mvn_tree_visualizer/TEMPLATE.py +2 -2
- mvn_tree_visualizer/__init__.py +0 -0
- mvn_tree_visualizer/__main__.py +4 -0
- mvn_tree_visualizer/cli.py +71 -0
- mvn_tree_visualizer/diagram.py +74 -0
- mvn_tree_visualizer/get_dependencies_in_one_file.py +11 -0
- {mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/METADATA +1 -1
- mvn_tree_visualizer-1.0.3b4.dist-info/RECORD +11 -0
- mvn_tree_visualizer-1.0.3b3.dist-info/RECORD +0 -6
- {mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/WHEEL +0 -0
- {mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/entry_points.txt +0 -0
- {mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/licenses/LICENSE +0 -0
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from .diagram import create_diagram
|
|
5
|
+
from .get_dependencies_in_one_file import merge_files
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def cli():
|
|
9
|
+
parser = argparse.ArgumentParser(
|
|
10
|
+
prog="mvn-tree-visualizer",
|
|
11
|
+
description="Generate a dependency diagram from a file.",
|
|
12
|
+
)
|
|
13
|
+
parser.add_argument(
|
|
14
|
+
"directory",
|
|
15
|
+
type=str,
|
|
16
|
+
nargs="?",
|
|
17
|
+
default=".",
|
|
18
|
+
help="The directory to scan for the Maven dependency file(s). Default is the current directory.",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"-o",
|
|
23
|
+
"--output",
|
|
24
|
+
type=str,
|
|
25
|
+
default="diagram.html",
|
|
26
|
+
help="The output file for the generated diagram. Default is 'diagram.html'.",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"-f",
|
|
31
|
+
"--filename",
|
|
32
|
+
type=str,
|
|
33
|
+
default="maven_dependency_file",
|
|
34
|
+
help="The name of the file to read the Maven dependencies from. Default is 'maven_dependency_file'.",
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--keep-tree",
|
|
38
|
+
type=bool,
|
|
39
|
+
default=False,
|
|
40
|
+
help="Keep the dependency tree file after generating the diagram. Default is False.",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
args = parser.parse_args()
|
|
44
|
+
directory: str = args.directory
|
|
45
|
+
output_file: str = args.output
|
|
46
|
+
filename: str = args.filename
|
|
47
|
+
keep_tree: bool = args.keep_tree
|
|
48
|
+
|
|
49
|
+
dir_to_create_files = Path(output_file).parent
|
|
50
|
+
|
|
51
|
+
dir_to_create_intermediate_files = Path(dir_to_create_files)
|
|
52
|
+
|
|
53
|
+
merge_files(
|
|
54
|
+
output_file=dir_to_create_intermediate_files / "dependency_tree.txt",
|
|
55
|
+
root_dir=directory,
|
|
56
|
+
target_filename=filename,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
create_diagram(
|
|
60
|
+
keep_tree=keep_tree,
|
|
61
|
+
intermediate_filename="dependency_tree.txt",
|
|
62
|
+
output_filename=output_file,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
print(f"Diagram generated and saved to {output_file}")
|
|
66
|
+
print("You can open it in your browser to view the dependency tree.")
|
|
67
|
+
print("Thank you for using mvn-tree-visualizer!")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
cli()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from jinja2 import BaseLoader, Environment
|
|
4
|
+
|
|
5
|
+
from .TEMPLATE import HTML_TEMPLATE
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _convert_to_mermaid(dependency_tree: str) -> str:
|
|
9
|
+
# generate a `graph LR` format for Mermaid
|
|
10
|
+
lines = dependency_tree.strip().split("\n")
|
|
11
|
+
mermaid_lines = set()
|
|
12
|
+
|
|
13
|
+
previous_dependency = []
|
|
14
|
+
|
|
15
|
+
for line in lines:
|
|
16
|
+
if not line or line.startswith("[INFO]"):
|
|
17
|
+
continue
|
|
18
|
+
parts = line.split(":")
|
|
19
|
+
|
|
20
|
+
if len(parts) < 3:
|
|
21
|
+
continue
|
|
22
|
+
|
|
23
|
+
if len(parts) == 4:
|
|
24
|
+
group_id, artifact_id, app, version = parts
|
|
25
|
+
mermaid_lines.add(f"\t{artifact_id};")
|
|
26
|
+
|
|
27
|
+
if previous_dependency: # Re initialize the list if it wasn't empty
|
|
28
|
+
previous_dependency = []
|
|
29
|
+
|
|
30
|
+
previous_dependency.append((artifact_id, 0)) # The second element is the depth
|
|
31
|
+
else:
|
|
32
|
+
depth = len(parts[0].split(" ")) - 1
|
|
33
|
+
|
|
34
|
+
if len(parts) == 6:
|
|
35
|
+
dirty_group_id, artifact_id, app, ejb_client, version, dependency = parts
|
|
36
|
+
else:
|
|
37
|
+
dirty_group_id, artifact_id, app, version, dependency = parts
|
|
38
|
+
|
|
39
|
+
if previous_dependency[-1][1] < depth:
|
|
40
|
+
mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
|
|
41
|
+
previous_dependency.append((artifact_id, depth))
|
|
42
|
+
else:
|
|
43
|
+
# remove all dependencies that are deeper or equal to the current depth
|
|
44
|
+
while previous_dependency and previous_dependency[-1][1] >= depth:
|
|
45
|
+
previous_dependency.pop()
|
|
46
|
+
|
|
47
|
+
mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
|
|
48
|
+
previous_dependency.append((artifact_id, depth))
|
|
49
|
+
|
|
50
|
+
mermaid_diagram = f"graph LR\n{'\n'.join(sorted(mermaid_lines))}"
|
|
51
|
+
return mermaid_diagram
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def create_diagram(keep_tree: bool = False, intermediate_filename: str = "dependency_tree.txt", output_filename: str = "diagram.html"):
|
|
55
|
+
with open(intermediate_filename, "r") as file:
|
|
56
|
+
dependency_tree = file.read()
|
|
57
|
+
|
|
58
|
+
mermaid_diagram = _convert_to_mermaid(dependency_tree)
|
|
59
|
+
|
|
60
|
+
template = Environment(loader=BaseLoader).from_string(HTML_TEMPLATE)
|
|
61
|
+
rendered = template.render(diagram_definition=mermaid_diagram)
|
|
62
|
+
|
|
63
|
+
parent_dir = Path(output_filename).parent
|
|
64
|
+
|
|
65
|
+
if not parent_dir.exists():
|
|
66
|
+
parent_dir.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
|
|
68
|
+
with open(output_filename, "w") as f:
|
|
69
|
+
f.write(rendered)
|
|
70
|
+
|
|
71
|
+
if not keep_tree:
|
|
72
|
+
import os
|
|
73
|
+
|
|
74
|
+
os.remove(intermediate_filename)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def merge_files(output_file: str, root_dir: str = ".", target_filename: str = "maven_dependency_file"):
|
|
5
|
+
with open(output_file, "w", encoding="utf-8") as outfile:
|
|
6
|
+
for dirpath, _, filenames in os.walk(root_dir):
|
|
7
|
+
for fname in filenames:
|
|
8
|
+
if fname == target_filename:
|
|
9
|
+
file_path = os.path.join(dirpath, fname)
|
|
10
|
+
with open(file_path, "r", encoding="utf-8") as infile:
|
|
11
|
+
outfile.write(infile.read())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mvn-tree-visualizer
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3b4
|
|
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>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mvn_tree_visualizer/TEMPLATE.py,sha256=oQa_84GV-DGvHfPpOor7ALkZwfGvk1wvCrQKCBsuOeg,2560
|
|
2
|
+
mvn_tree_visualizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
mvn_tree_visualizer/__main__.py,sha256=1UA2dYHkOCbajDc7rQyKB8N1hP9POnbajya_JpIh28k,86
|
|
4
|
+
mvn_tree_visualizer/cli.py,sha256=sMl1yeCQGwWswiC5xVEOdy1nXhF9Vx5DnoqfHuq02_U,2036
|
|
5
|
+
mvn_tree_visualizer/diagram.py,sha256=PCuR96pBH2JUOZ2RsYKRwMzG7c58CKdNJvk6t0FxuL0,2603
|
|
6
|
+
mvn_tree_visualizer/get_dependencies_in_one_file.py,sha256=d0ldXC0sYvDKLXozD0JgHsMcID_gN4xjeCUdk5TCiV4,515
|
|
7
|
+
mvn_tree_visualizer-1.0.3b4.dist-info/METADATA,sha256=YVQ_d3TKC1vq91ZKxJCZOX5NuUDFO1h9Ri1HaOyVv4E,1972
|
|
8
|
+
mvn_tree_visualizer-1.0.3b4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
mvn_tree_visualizer-1.0.3b4.dist-info/entry_points.txt,sha256=Mu3QZhrlvbYuCxqmluVGi2efgKjkQY6T8Opf-vdb7hU,68
|
|
10
|
+
mvn_tree_visualizer-1.0.3b4.dist-info/licenses/LICENSE,sha256=c_8ezHwcOG8McIzdj7ZPgkqN1RuUMfP0hlmd6gX4gR0,1096
|
|
11
|
+
mvn_tree_visualizer-1.0.3b4.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
dependency_diagram_template.j2,sha256=BEE4OfnnhiFk7Bvz_5mmNcQTbB1gKJanusbArDt1yco,2535
|
|
2
|
-
mvn_tree_visualizer-1.0.3b3.dist-info/METADATA,sha256=tZZCDCmiHdi9DnQmy28-cySriPmHiRoAgSFquPkZu-c,1972
|
|
3
|
-
mvn_tree_visualizer-1.0.3b3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
-
mvn_tree_visualizer-1.0.3b3.dist-info/entry_points.txt,sha256=Mu3QZhrlvbYuCxqmluVGi2efgKjkQY6T8Opf-vdb7hU,68
|
|
5
|
-
mvn_tree_visualizer-1.0.3b3.dist-info/licenses/LICENSE,sha256=c_8ezHwcOG8McIzdj7ZPgkqN1RuUMfP0hlmd6gX4gR0,1096
|
|
6
|
-
mvn_tree_visualizer-1.0.3b3.dist-info/RECORD,,
|
|
File without changes
|
{mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{mvn_tree_visualizer-1.0.3b3.dist-info → mvn_tree_visualizer-1.0.3b4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|