SystemRDL / PeakRDL-cheader

GNU General Public License v3.0
8 stars 9 forks source link

Peakrdl IPXACT - No module named 'peakrdl.ipxact' #2

Closed nmolinski closed 1 year ago

nmolinski commented 1 year ago

Problem

When running peakrdl_cheader ./docs/rdl/ip_core.rdl --outdir export/c, Peakrdl IPXACT plugin 'Peakrdl-ipxact' cannot be found under peakrdl.ipxact, but can be found under peakrdl_ipxact

  File "<path>/.venv/lib/python3.11/site-packages/peakrdl_cheader/peakcheader.py", line 11, in <module>
    from peakrdl.ipxact import IPXACTImporter # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'peakrdl.ipxact'

In Python Shell, running shows module does not exist under peakrdl.ipxact (with peakrdl-ipxact pip installed):

>>> from importlib.util import find_spec; find_spec("peakrdl.ipxact") or "Does not exist"
"Does not exist"

However, the module name works under peakrdl_ipxact

>>> from importlib.util import find_spec; find_spec("peakrdl_ipxact") or "Does not exist"
ModuleSpec(name='peakrdl_ipxact', loader=<_frozen_importlib_external.SourceFileLoader object at 0x1007a6810>, origin='/<path>/.venv/lib/python3.11/site-packages/peakrdl_ipxact/__init__.py', submodule_search_locations=['/<path>/.venv/lib/python3.11/site-packages/peakrdl_ipxact'])

The module reference can be seen to be peakrdl_ipxact, however, I'm not sure if the main peakrdl at some point had the ipxact under its namespace. I haven't followed the history long enough to know if this was changed, or, if this is difference in environments.

Solution

To maintain backwards compatibility (if desired), a check can be performed on line 11 of peakcheader.py which module should be imported.

# Line 11
import importlib
from importlib.util import find_spec
if find_spec("peakrdl.ipxact"):
    from peakrdl.ipxact import IPXACTImporter # type: ignore
elif find_spec("peakrdl_ipxact"):
    from peakrdl_ipxact import IPXACTImporter # type: ignore
else:
    raise ModuleNotFoundError("Cannot find PeakRDL IPXACT Module")

I'm sure a more pythonic way could be written. If you are busy, I could submit the PR if needed.

Environment:

Python 3.11.2 Pip 22.3.1 Mac M1 running in x86_64 (Rosetta) Environment

Pip List

antlr4-python3-runtime==4.11.1 colorama==0.4.6 git-me-the-url==2.1.0 gitdb==4.0.10 GitPython==3.1.31 hectare==0.2.4 Jinja2==3.1.2 Markdown==3.4.3 MarkupSafe==2.1.2 peakrdl==0.8.0 peakrdl-cheader==0.0.1 peakrdl-html==2.10.0 peakrdl-ipxact==3.4.1 peakrdl-regblock==0.12.0 peakrdl-systemrdl==0.3.0 peakrdl-uvm==2.3.0 pysphere==0.1.7 python-markdown-math==0.8 PyYAML==6.0 smmap==5.0.0 systemrdl-compiler==1.25.6

eddlestar commented 1 year ago

@krcb197 I ran into this issue as well, wondering if you would be open to the workaround suggested above?

krcb197 commented 1 year ago

The import for peakrdl-xact was changed a while ago. I have made a pull request which should address this.

The eagle eyed may notice this project has transferred to the main systemrdl area, with a view that it becomes part of peakrdl properly soon. I have been in discussions with @amykyta3 about some more significant changes to move this project forward.