Skip to content

Commit

Permalink
split into class graph and inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jun 26, 2024
1 parent d0cba79 commit 28d4894
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
52 changes: 1 addition & 51 deletions src/umlizer/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Main module template with example functions."""
from __future__ import annotations

import os
import subprocess

from pathlib import Path

import typer
Expand All @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions src/umlizer/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()}')

0 comments on commit 28d4894

Please sign in to comment.