Skip to content

Commit

Permalink
fix: Fix initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jan 18, 2024
1 parent af7b94c commit 87c8570
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ TBD
## Class Diagram

```bash
$ umlizer class --source ./src/umlizer --target ./docs/uml/class_graph --verbose
$ umlizer class --source ./src/umlizer --target ./docs/uml/ --verbose
```
17 changes: 0 additions & 17 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# Release Notes

---

# [0.3.0](https://github.com/osl-incubator/umlizer/compare/0.2.0...0.3.0) (2023-12-22)

### Features

- Separate data.lock per profile and fix small issues ([#8](https://github.com/osl-incubator/umlizer/issues/8)) ([91a8b3d](https://github.com/osl-incubator/umlizer/commit/91a8b3d8b0fa2900fc35e3149352a77d0fd40b2b))

# [0.2.0](https://github.com/osl-incubator/umlizer/compare/0.1.0...0.2.0) (2023-12-15)

### Bug Fixes

- Fix release workflow ([#5](https://github.com/osl-incubator/umlizer/issues/5)) ([8ba1407](https://github.com/osl-incubator/umlizer/commit/8ba1407ea27fb6e1a8712608f7f8af4ee1850475))
- Fix release workflow ([#6](https://github.com/osl-incubator/umlizer/issues/6)) ([38e9d7c](https://github.com/osl-incubator/umlizer/commit/38e9d7c5ce45a83f6d50bdc9e98fcb76b6a34caf))

### Features

- Implement option for passing password as a stdin ([#4](https://github.com/osl-incubator/umlizer/issues/4)) ([4ab5ba8](https://github.com/osl-incubator/umlizer/commit/4ab5ba8ee54e98b6f580dbd3f7659af77e9a72c3))
6 changes: 3 additions & 3 deletions docs/uml/class_graph
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Graph
digraph {
node [rankdir=BT shape=record]
"typing.Annotated" [label="{Annotated|\l|+ _class_getitem_inner()\l}"]
"typing.Annotated" [label="{Annotated|\l|- _class_getitem_inner()\l}"]
"typer.models.Context" [label="{Context|\l|\l}"]
"pathlib.Path" [label="{Path : pathlib.PurePath|+ cwd: object\l+ home: object\l|+ stat()\l+ lstat()\l+ exists()\l+ is_dir()\l+ is_file()\l+ is_mount()\l+ is_symlink()\l+ is_junction()\l+ is_block_device()\l+ is_char_device()\l+ is_fifo()\l+ is_socket()\l+ samefile()\l+ open()\l+ read_bytes()\l+ read_text()\l+ write_bytes()\l+ write_text()\l+ iterdir()\l+ _scandir()\l+ _make_child_relpath()\l+ glob()\l+ rglob()\l+ walk()\l+ absolute()\l+ resolve()\l+ owner()\l+ group()\l+ readlink()\l+ touch()\l+ mkdir()\l+ chmod()\l+ lchmod()\l+ unlink()\l+ rmdir()\l+ rename()\l+ replace()\l+ symlink_to()\l+ hardlink_to()\l+ expanduser()\l}"]
"pathlib.Path" [label="{Path : pathlib.PurePath|+ cwd: \l+ home: \l|+ stat()\l+ lstat()\l+ exists()\l+ is_dir()\l+ is_file()\l+ is_mount()\l+ is_symlink()\l+ is_junction()\l+ is_block_device()\l+ is_char_device()\l+ is_fifo()\l+ is_socket()\l+ samefile()\l+ open()\l+ read_bytes()\l+ read_text()\l+ write_bytes()\l+ write_text()\l+ iterdir()\l- _scandir()\l- _make_child_relpath()\l+ glob()\l+ rglob()\l+ walk()\l+ absolute()\l+ resolve()\l+ owner()\l+ group()\l+ readlink()\l+ touch()\l+ mkdir()\l+ chmod()\l+ lchmod()\l+ unlink()\l+ rmdir()\l+ rename()\l+ replace()\l+ symlink_to()\l+ hardlink_to()\l+ expanduser()\l}"]
"typing.Any" [label="{Any|\l|\l}"]
"pathlib.Path" [label="{Path : pathlib.PurePath|+ cwd: object\l+ home: object\l|+ stat()\l+ lstat()\l+ exists()\l+ is_dir()\l+ is_file()\l+ is_mount()\l+ is_symlink()\l+ is_junction()\l+ is_block_device()\l+ is_char_device()\l+ is_fifo()\l+ is_socket()\l+ samefile()\l+ open()\l+ read_bytes()\l+ read_text()\l+ write_bytes()\l+ write_text()\l+ iterdir()\l+ _scandir()\l+ _make_child_relpath()\l+ glob()\l+ rglob()\l+ walk()\l+ absolute()\l+ resolve()\l+ owner()\l+ group()\l+ readlink()\l+ touch()\l+ mkdir()\l+ chmod()\l+ lchmod()\l+ unlink()\l+ rmdir()\l+ rename()\l+ replace()\l+ symlink_to()\l+ hardlink_to()\l+ expanduser()\l}"]
"pathlib.Path" [label="{Path : pathlib.PurePath|+ cwd: \l+ home: \l|+ stat()\l+ lstat()\l+ exists()\l+ is_dir()\l+ is_file()\l+ is_mount()\l+ is_symlink()\l+ is_junction()\l+ is_block_device()\l+ is_char_device()\l+ is_fifo()\l+ is_socket()\l+ samefile()\l+ open()\l+ read_bytes()\l+ read_text()\l+ write_bytes()\l+ write_text()\l+ iterdir()\l- _scandir()\l- _make_child_relpath()\l+ glob()\l+ rglob()\l+ walk()\l+ absolute()\l+ resolve()\l+ owner()\l+ group()\l+ readlink()\l+ touch()\l+ mkdir()\l+ chmod()\l+ lchmod()\l+ unlink()\l+ rmdir()\l+ rename()\l+ replace()\l+ symlink_to()\l+ hardlink_to()\l+ expanduser()\l}"]
"pathlib.PurePath" -> "pathlib.Path"
}
Binary file modified docs/uml/class_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 25 additions & 8 deletions src/umlizer/class_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ def _get_classicclass_structure(
klass: Type[Any],
) -> dict[str, Union[dict[str, str], list[str]]]:
_methods = _get_methods(klass)
fields = {}

for k in list(klass.__dict__.keys()):
if k.startswith('__') or k in _methods:
continue
value = _get_annotations(klass).get(k, '')
fields[k] = getattr(value, '__value__', str(value))

return {
'fields': {
k: _get_annotations(klass).get(k, object).__name__
for k in list(klass.__dict__.keys())
if not k.startswith('__') and k not in _methods
},
'fields': fields,
'methods': _methods,
}

Expand Down Expand Up @@ -131,15 +134,29 @@ def _get_entity_class_uml(entity: Type[Any]) -> str:
class_name = f'{entity.__name__}'

if base_classes:
class_name += f' : {base_classes}'
class_name += f' ({base_classes})'

# Formatting fields and methods
fields_struct = cast(dict[str, str], class_structure['fields'])
fields = (
'\\l'.join([f'+ {k}: {v}' for k, v in fields_struct.items()]) + '\\l'
'\\l'.join(
[
f'{"-" if k.startswith("_") else "+"} {k}: {v}'
for k, v in fields_struct.items()
]
)
+ '\\l'
)
methods_struct = cast(list[str], class_structure['methods'])
methods = '\\l'.join([f'+ {m}()' for m in methods_struct]) + '\\l'
methods = (
'\\l'.join(
[
f'{"-" if m.startswith("_") else "+"} {m}()'
for m in methods_struct
]
)
+ '\\l'
)

# Combine class name, fields, and methods into the UML node format
uml_representation = '{' + f'{class_name}|{fields}|{methods}' + '}'
Expand Down
32 changes: 31 additions & 1 deletion src/umlizer/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Main module template with example functions."""
from __future__ import annotations

import os

from pathlib import Path

import typer
Expand All @@ -13,6 +15,31 @@
app = typer.Typer()


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 Expand Up @@ -47,12 +74,15 @@ def class_(
typer.Option(
..., help='Target path where the UML graph will be generated.'
),
] = Path('/tmp'),
] = Path('/tmp/'),
verbose: Annotated[
bool, typer.Option(help='Active the verbose mode.')
] = False,
) -> None:
"""Run the command for class graph."""
source = make_absolute(source)
target = make_absolute(target) / 'class_graph'

g = class_graph.create_class_diagram_from_source(source, verbose=verbose)
g.format = 'png'
g.render(target)
Expand Down

0 comments on commit 87c8570

Please sign in to comment.