From 28d4894ebc7eaaeb67db4716d39e9f4189e4174d Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Wed, 26 Jun 2024 12:46:34 -0400 Subject: [PATCH] split into class graph and inspector --- src/umlizer/cli.py | 52 +------------------------------------------- src/umlizer/utils.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/umlizer/cli.py b/src/umlizer/cli.py index 790abf6..9ba24e9 100644 --- a/src/umlizer/cli.py +++ b/src/umlizer/cli.py @@ -1,9 +1,6 @@ """Main module template with example functions.""" from __future__ import annotations -import os -import subprocess - from pathlib import Path import typer @@ -13,58 +10,11 @@ from typing_extensions import Annotated from umlizer import __version__, class_graph, inspector +from umlizer.utils import dot2svg, make_absolute app = typer.Typer() -def dot2svg(target: Path) -> None: - """ - Run the `dot` command to convert a Graphviz file to SVG format. - - Parameters - ---------- - target : str - The target Graphviz file to be converted. - """ - command = f'dot -Tsvg {target} -o {target}.svg' - try: - result = subprocess.run( - command, - shell=True, - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - print(result.stdout.decode()) - except subprocess.CalledProcessError as e: - print(f'Error occurred: {e.stderr.decode()}') - - -def make_absolute(relative_path: Path) -> Path: - """ - Convert a relative Path to absolute, relative to the current cwd. - - Parameters - ---------- - relative_path : Path - The path to be converted to absolute. - - Returns - ------- - Path - The absolute path. - """ - # Get current working directory - current_directory = Path(os.getcwd()) - - # Return absolute path - return ( - current_directory / relative_path - if not relative_path.is_absolute() - else relative_path - ) - - @app.callback(invoke_without_command=True) def main( ctx: Context, diff --git a/src/umlizer/utils.py b/src/umlizer/utils.py index 7e95940..071b8c9 100644 --- a/src/umlizer/utils.py +++ b/src/umlizer/utils.py @@ -1,7 +1,10 @@ """A set of utilitary tools.""" import inspect +import os import re +import subprocess +from pathlib import Path from typing import Any import typer @@ -54,3 +57,51 @@ def raise_error(message: str, exit_code: int = 1) -> None: red_text = typer.style(message, fg=typer.colors.RED, bold=True) typer.echo(red_text, err=True, color=True) raise typer.Exit(exit_code) + + +def make_absolute(relative_path: Path) -> Path: + """ + Convert a relative Path to absolute, relative to the current cwd. + + Parameters + ---------- + relative_path : Path + The path to be converted to absolute. + + Returns + ------- + Path + The absolute path. + """ + # Get current working directory + current_directory = Path(os.getcwd()) + + # Return absolute path + return ( + current_directory / relative_path + if not relative_path.is_absolute() + else relative_path + ) + + +def dot2svg(target: Path) -> None: + """ + Run the `dot` command to convert a Graphviz file to SVG format. + + Parameters + ---------- + target : str + The target Graphviz file to be converted. + """ + command = f'dot -Tsvg {target} -o {target}.svg' + try: + result = subprocess.run( + command, + shell=True, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + print(result.stdout.decode()) + except subprocess.CalledProcessError as e: + print(f'Error occurred: {e.stderr.decode()}')