glato / emerge

Emerge is a browser-based interactive codebase and dependency visualization tool for many different programming languages. It supports some basic code quality and graph metrics and provides a simple and intuitive way to explore and analyze a codebase by using graph structures.
MIT License
783 stars 46 forks source link

FileNotFoundError: graph_representations_d3_force_graph.js #6

Closed kargaranamir closed 3 years ago

kargaranamir commented 3 years ago

Hi, I got this error when I used d3 in YAML config on my java code.

with open(target_export_file_path, 'w') as file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/amir/emerge_test/export/force-graph-html/resources/js/graph_representations_d3_force_graph.js'

Thanks.

Should the emerge.py and my java code be in the same directory? I can have other output formats when i call emerge.py from another location (its source) but it seems it doesn't work for d3 format when they are not in the same directory.

glato commented 3 years ago

@kargaranamir Thanks for the report, I'll have a look at this. There could be a bug in export.py / D3Exporter when trying to write target_export_file_path. Could you maybe paste you whole YAML config so I could try to reproduce this?

kargaranamir commented 3 years ago

Thanks for your help, I will look forward to hearing from you. When I put my code in the same directory with emerge.py everything is ok (every possible output), but when I call emerge.py from its source in another location I can not get the d3 format and it makes an error (but I can get the other formats if I remove d3).

Config:

---
project_name: 10_water-simulator
loglevel: info
analyses:
- analysis_name: full java check
  source_directory: /home/amir/emerge_test
  only_permit_languages:
  - java
  only_permit_file_extensions:
  - .java
  file_scan:
  - number_of_methods
  - source_lines_of_code
  - dependency_graph
  - fan_in_out
  - louvain_modularity
  entity_scan:
  - dependency_graph
  - inheritance_graph
  - complete_graph
  - source_lines_of_code
  - number_of_methods
  - fan_in_out
  - louvain_modularity
  export:
  - directory: /home/amir/emerge_test/export
  - graphml
  - dot
  - json
  - tabular_file
  - tabular_console_overal
glato commented 3 years ago

@kargaranamir I could reproduce the bug if I try to start emerge with the D3 export option from another directory than the one that emerge was cloned into. The bug seems to be in

files.py -> FileManager -> def copy_force_graph_template_to_export_dir(target_export_path: str)

in the composition of

origin_complete_path = origin_script_dir + origin_emerge_subpath + origin_output_subpath + origin_force_graph_subpath

to prepare the copying of the d3 javascript app template.

origin_complete_path is using origin_script_dir = os.getcwd() and probably the getcwd() leads to this issue. Now as I understand the issue, I'll try to come with a fix in the coming days.

Thanks again for reporting the issue @kargaranamir 👍

glato commented 3 years ago

@kargaranamir Probably the fix was easy, I've just pushed the new version 0.18.3 to dev which should behave correctly now. I've tested this on macOS and Ubuntu with Python 3.9.2 and Python 3.8.2. It seems I can launch from any other directory and the d3 export seems to work fine now. It would be great if you can find some time to pull the new version, retest again and give me feedback about the issue? Thanks!

kargaranamir commented 3 years ago

Thank you so much, I will retest it ASAP and give you feedback if anything was wrong.