Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary option #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ In Ipython, first,

then, create a cell like,

::

%%plantuml --bin

@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml

The output will be the generated SVG UML diagram using the plantuml binary on your local system. To utilise remote rendering on plantweb omit the `--bin` argument:

::

%%plantuml --jar
Expand Down
20 changes: 19 additions & 1 deletion iplantuml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def _exec_and_get_paths(cmd, file_names):
return [os.path.splitext(f)[0] + ".svg" for f in file_names]


def plantuml_exec_bin(*file_names, **kwargs):
"""
Given a list of UML documents, generate corresponding SVG diagrams.

:param file_names: the filenames of the documents for parsing by PlantUML.
:return: the path to the generated SVG UML diagram.
"""

cmd = ["plantuml",
"-tsvg"] + list(file_names)

return _exec_and_get_paths(cmd, file_names)


def plantuml_exec(*file_names, **kwargs):
"""
Given a list of UML documents, generate corresponding SVG diagrams.
Expand Down Expand Up @@ -80,6 +94,8 @@ def plantuml(line, cell):
"""

parser = argparse.ArgumentParser()
parser.add_argument("-b", "--bin", action="store_true",
help="render using plantuml binary (default is plantweb)")
parser.add_argument("-j", "--jar", action="store_true",
help="render using plantuml.jar (default is plantweb)")
parser.add_argument("-n", "--name", type=str, default=None,
Expand All @@ -89,7 +105,7 @@ def plantuml(line, cell):
args = parser.parse_args(line.split() if line else "")
retain = args.name is not None
base_name = args.name or str(uuid.uuid4())
use_web = not (args.jar or args.plantuml_path)
use_web = not (args.bin or args.jar or args.plantuml_path)

uml_path = base_name + ".uml"
with open(uml_path, 'w') as fp:
Expand All @@ -99,6 +115,8 @@ def plantuml(line, cell):
output = None
if use_web:
output = plantuml_web(uml_path)
elif args.bin:
output = plantuml_exec_bin(uml_path)
else:
plantuml_path = os.path.abspath(args.plantuml_path or PLANTUMLPATH)
output = plantuml_exec(uml_path, plantuml_path=plantuml_path)
Expand Down