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

Not serializable PosixPath when exporting JSON #657

Closed
tomvdbussche opened this issue Jun 10, 2020 · 3 comments
Closed

Not serializable PosixPath when exporting JSON #657

tomvdbussche opened this issue Jun 10, 2020 · 3 comments

Comments

@tomvdbussche
Copy link

Exporting the JSON (using --export-json) for some projects (e.g. examples/vhdl/run) throws the following exception:

Traceback (most recent call last):
  File "/home/tom/git/vunit/vunit/ui/__init__.py", line 726, in main
    all_ok = self._main(post_run)
  File "/home/tom/git/vunit/vunit/ui/__init__.py", line 761, in _main
    return self._main_export_json(self._args.export_json)
  File "/home/tom/git/vunit/vunit/ui/__init__.py", line 892, in _main_export_json
    json.dump(json_data, fptr, sort_keys=True, indent=4, separators=(",", ": "))
  File "/usr/lib64/python3.8/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib64/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib64/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib64/python3.8/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib64/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib64/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib64/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib64/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PosixPath is not JSON serializable

This is when running on Linux, but it seems to be a problem on Windows as well.

@eine
Copy link
Collaborator

eine commented Jun 26, 2020

Hi @tomvdbussche! Please, can you try replacing https://github.com/VUnit/vunit/blob/master/vunit/ui/__init__.py#L874 with file_name=str(info.location.file_name),? It worked for me on Windows (MSYS2).

However, I'm not sure about pushing that to master or using the absolute path as in https://github.com/VUnit/vunit/blob/master/vunit/ui/__init__.py#L851. Currently, it feels inconsistent that some test paths are absolute and others are relative in the exported JSON. @kraigher, any guess?

@tomvdbussche
Copy link
Author

@eine Can confirm that this does seem to fix the issue on Linux as well!

eine added a commit to eine/vunit that referenced this issue Jul 7, 2020
@eine
Copy link
Collaborator

eine commented Jul 7, 2020

I pushed that fix. We'll revisit the absolute/relative issue if we need it in the future...

@eine eine closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants