Skip to content

Commit

Permalink
Fix smart file resolver for images
Browse files Browse the repository at this point in the history
  • Loading branch information
17o2 authored and laurierloi committed Jan 19, 2023
1 parent b9527a8 commit 97207e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Tweak:

@dataclass
class Image:
gv_dir: InitVar[Path] # Directory of .gv file injected as context during parsing
# Attributes of the image object <img>:
src: str
scale: Optional[ImageScale] = None
Expand All @@ -82,7 +81,7 @@ class Image:
caption: Optional[MultilineHypertext] = None
# See also HTML doc at https://graphviz.org/doc/info/shapes.html#html

def __post_init__(self, gv_dir):
def __post_init__(self):

if self.fixedsize is None:
# Default True if any dimension specified unless self.scale also is specified.
Expand All @@ -98,10 +97,10 @@ def __post_init__(self, gv_dir):
# because Graphviz requires both when fixedsize=True.
if self.height:
if not self.width:
self.width = self.height * aspect_ratio(gv_dir.joinpath(self.src))
self.width = self.height * aspect_ratio(self.src)
else:
if self.width:
self.height = self.width / aspect_ratio(gv_dir.joinpath(self.src))
self.height = self.width / aspect_ratio(self.src)


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from wireviz.DataClasses import Metadata, Options, Tweak
from wireviz.Harness import Harness
from wireviz.wv_helper import expand, get_single_key_and_value, is_arrow, open_file_read
from wireviz.wv_helper import expand, get_single_key_and_value, is_arrow, open_file_read, smart_file_resolve


def parse_text(yaml_str: str, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = ('html','png','svg','tsv'), image_paths: List = []) -> Any:
Expand Down Expand Up @@ -82,7 +82,6 @@ def parse(yaml_data: Dict, file_out: (str, Path) = None, return_types: (None, st
# The Image dataclass might need to open an image file with a relative path.
image = attribs.get('image')
if isinstance(image, dict):
image['gv_dir'] = Path(file_out if file_out else '').parent # Inject context # TODO: remove
image_path = image['src']
if image_path and not Path(image_path).is_absolute(): # resolve relative image path
image['src'] = smart_file_resolve(image_path, image_paths)
Expand Down

0 comments on commit 97207e6

Please sign in to comment.