- 
                Notifications
    You must be signed in to change notification settings 
- Fork 262
Fix template search path #473
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -70,6 +70,7 @@ class Harness: | |||||||||
| metadata: Metadata | ||||||||||
| options: Options | ||||||||||
| tweak: Tweak | ||||||||||
| source_path: Path | ||||||||||
|  | ||||||||||
| def __post_init__(self): | ||||||||||
| self.connectors = {} | ||||||||||
|  | @@ -697,7 +698,7 @@ def output( | |||||||||
| print("CSV output is not yet supported") | ||||||||||
| # HTML output | ||||||||||
| if "html" in fmt: | ||||||||||
| generate_html_output(filename, bomlist, self.metadata, self.options) | ||||||||||
| generate_html_output(filename, bomlist, self.metadata, self.options, self.source_path) | ||||||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 The splitting into multiple lines is due to  | ||||||||||
| # PDF output | ||||||||||
| if "pdf" in fmt: | ||||||||||
| # TODO: implement PDF output | ||||||||||
|  | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -31,6 +31,7 @@ def parse( | |||||
| output_dir: Union[str, Path] = None, | ||||||
| output_name: Union[None, str] = None, | ||||||
| image_paths: Union[Path, str, List] = [], | ||||||
| source_path = None, | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 | ||||||
| ) -> Any: | ||||||
| """ | ||||||
| This function takes an input, parses it as a WireViz Harness file, | ||||||
|  | @@ -115,6 +116,7 @@ def parse( | |||||
| metadata=Metadata(**yaml_data.get("metadata", {})), | ||||||
| options=Options(**yaml_data.get("options", {})), | ||||||
| tweak=Tweak(**yaml_data.get("tweak", {})), | ||||||
| source_path=source_path | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest reusing the existing  
        Suggested change
       
 | ||||||
| ) | ||||||
| # others | ||||||
| # store mapping of components to their respective template | ||||||
|  | ||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|  | @@ -144,6 +144,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version): | |||
| output_dir=_output_dir, | ||||
| output_name=_output_name, | ||||
| image_paths=list(image_paths), | ||||
| source_path=file | ||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 | ||||
| ) | ||||
|  | ||||
| print() | ||||
|  | ||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -21,14 +21,19 @@ def generate_html_output( | |||||||||
| bom_list: List[List[str]], | ||||||||||
| metadata: Metadata, | ||||||||||
| options: Options, | ||||||||||
| source: Union[str, Path] = None, | ||||||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 | ||||||||||
| ): | ||||||||||
| # load HTML template | ||||||||||
| templatename = metadata.get("template", {}).get("name") | ||||||||||
| template_search_paths = [ Path(filename).parent, Path(__file__).parent / "templates"] | ||||||||||
|  | ||||||||||
| if source is not None: | ||||||||||
| template_search_paths.insert(0, Path(source).parent) | ||||||||||
|  | ||||||||||
| 
      Comment on lines
    
      +28
     to 
      +32
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 | ||||||||||
| if templatename: | ||||||||||
| # if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory | ||||||||||
| templatefile = smart_file_resolve( | ||||||||||
| f"{templatename}.html", | ||||||||||
| [Path(filename).parent, Path(__file__).parent / "templates"], | ||||||||||
| f"{templatename}.html", template_search_paths | ||||||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember inserting  
        Suggested change
       
 My suggestion here does not add the output folder in the list when different because I don't see any use case where that might be useful, but please argue against my suggestion. | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| # fall back to built-in simple template if no template was provided | ||||||||||
|  | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.