Skip to content

Commit

Permalink
feat: language independency
Browse files Browse the repository at this point in the history
  • Loading branch information
pheetah committed Jun 25, 2024
1 parent fded145 commit 58240bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
7 changes: 5 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def _compose_and_draw_inner(self, pygraph: AGraph, flow: TokenSequence, name: st
def _draw_architectural_connections(self, pygraph: AGraph, diagram: TokenSequence):
diagram.architecture.draw_connections(pygraph=pygraph)

def draw_epc(self, out_path: str, file_format: list[FileFormat]):
def draw_epc(self, out_path: str, file_format: list[FileFormat], language: str):
cluster = Cluster()
cluster.extract_flows(file_name_list=[file.input_path for file in file_format])
cluster.extract_flows(
file_name_list=[file.input_path for file in file_format],
language=language,
)

main_flows = [flow.tokens for flow in cluster._main_flows]
ARCHG = AGraph(directed=True, compound=True)
Expand Down
4 changes: 2 additions & 2 deletions clusterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def _find_main_flows(self, token: str, index: int, flows: Flows):
if flows.latest_flow is not None:
flows.latest_flow.tokens.append(token)

def extract_flows(self, file_name_list: list[str]):
def extract_flows(self, file_name_list: list[str], language: str):
for file in file_name_list:
parser = Parser()
parsed = parser.parse(file)
parsed = parser.parse(file, language)

flows = Flows()
for index, token_raw in enumerate(parsed):
Expand Down
28 changes: 22 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from typing import Optional

import typer
Expand Down Expand Up @@ -27,8 +28,22 @@ def get_filepaths(directory):
return file_paths


def is_file_allowed(file_name: str, extension: str):
file_extension = re.search(r"\.\w+", file_name)[0]

if file_extension == f".{extension}":
return True

return False


@app.command()
def docupyt(path: Optional[str] = None, out_path: Optional[str] = "_outputs"):
def docupyt(
path: Optional[str] = None,
out_path: Optional[str] = "_outputs",
extension="py",
language="python",
):
if not path:
raise ValueError("Path is required")

Expand All @@ -38,13 +53,14 @@ def docupyt(path: Optional[str] = None, out_path: Optional[str] = "_outputs"):
formats = []

for filepath in get_filepaths(path):
formats.append(
FileFormat(
input_path=filepath,
if is_file_allowed(filepath, extension):
formats.append(
FileFormat(
input_path=filepath,
)
)
)

client.draw_epc(out_path=out_path, file_format=formats)
client.draw_epc(out_path=out_path, file_format=formats, language=language)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions parser/doctree_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def parse(self):


class Parser(IParser):
def parse(self, file_path: str):
def parse(self, file_path: str, language: str):
with open(file_path) as file:
file_str = file.read()
return ctok.tokenize(
file_str,
lang="python",
lang=language,
)

0 comments on commit 58240bb

Please sign in to comment.