Skip to content

Commit

Permalink
Simplify flowchart; Remove unused libs (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
kharus authored Jan 27, 2025
1 parent 32ad57c commit 34e8ad5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import asyncio
from dataclasses import dataclass
import os
import sys
from collections.abc import Collection, Sequence

import anyio
import pyrsistent as pyrs
import pyrsistent_extras as pyrse

class FlowchartOutput(pyrs.PRecord):
suffix = pyrs.field(type=str, initial="")
file_extension = pyrs.field(mandatory=True, type=str)

args = pyrs.field(type=Sequence, initial=pyrse.sq())
@dataclass
class FlowchartOutput:
suffix: str
file_extension: str
gdpi: str


flowchart_outputs: Collection[FlowchartOutput] = pyrs.s(
FlowchartOutput(file_extension="png", args=pyrse.sq("-Gdpi=150")),
FlowchartOutput(suffix="-small", file_extension="png", args=pyrse.sq("-Gdpi=72")),
FlowchartOutput(file_extension="svg"),
)
flowchart_outputs = [
FlowchartOutput(suffix="", file_extension="png", gdpi="-Gdpi=150"),
FlowchartOutput(suffix="-small", file_extension="png", gdpi="-Gdpi=72"),
FlowchartOutput(suffix="", file_extension="svg", gdpi=""),
]


async def _dot_file_to_output(
dot_file: str | os.PathLike[str],
output_file: str | os.PathLike[str],
args: Sequence[str],
gdpi: str,
) -> None:
output_file = anyio.Path(output_file)

graphviz_cmd: Sequence[str] = (
pyrse.sq("dot", f"-T{output_file.suffix[1:]}", f"{dot_file}") + pyrse.psequence(args) + pyrse.sq("-o", f"{output_file}")
) # type: ignore
graphviz_cmd = ["dot", f"-T{output_file.suffix[1:]}", f"{dot_file}", gdpi, "-o", f"{output_file}"]

print(f'Calling graphviz with: {" ".join(graphviz_cmd)}', file=sys.stderr)

Expand All @@ -48,13 +46,13 @@ async def flowchart_dot_to_output(

if await dot_file.exists():
match flowchart_output:
case {"suffix": suffix, "file_extension": file_extension, "args": args}:
case FlowchartOutput(suffix=suffix, file_extension=file_extension, gdpi=gdpi):
timestamp_file: str = f"{timestamp}{suffix}.{file_extension}"
output_file: str = f"{output_path / timestamp_file}"

print(f"Drawing {file_extension} from dot file", file=sys.stderr)
print(f"Output file: {output_file}", file=sys.stderr)
await _dot_file_to_output(dot_file, output_file, args)
await _dot_file_to_output(dot_file, output_file, gdpi)

latest_file: anyio.Path = output_path / f"LATEST{suffix}.{file_extension}"
try:
Expand Down
48 changes: 0 additions & 48 deletions natural4-server/natural4_server/task.py

This file was deleted.

5 changes: 0 additions & 5 deletions natural4-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ requires-python = "==3.12.*"


dependencies = [
"aioshutil == 1.5",
"aiostream == 0.5.2",
"anyio == 4.6.0",
"cytoolz == 0.12.3",
"jinja2 == 3.1.4",
"orjson == 3.10.7",
"pypandoc-binary == 1.13",
"pyrsistent == 0.20.0",
"pyrsistent-extras == 0.1.1",
"python-dotenv == 1.0.1",
"sanic-testing == 24.6.0",
"sanic[ext] == 24.6.0",
Expand Down
97 changes: 0 additions & 97 deletions natural4-server/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34e8ad5

Please sign in to comment.