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

ModuleNotFoundError: No module named 'withrootnotincwd' #46

Closed
supratik21 opened this issue May 13, 2023 · 3 comments
Closed

ModuleNotFoundError: No module named 'withrootnotincwd' #46

supratik21 opened this issue May 13, 2023 · 3 comments
Labels
invalid This doesn't seem right

Comments

@supratik21
Copy link

Dear @lucsorel, @doyou89, @jonykalavera, @jjerphan,

While trying to generate UML content for "withrootnotincwd" module that is provided under /tests/modules/withrootnotincwd, I am encountering a ModuleNotFoundError.

Error below:

py2puml/asserts.py:15: in assert_py2puml_is_stringio
    puml_content = list(py2puml(domain_path, domain_module))
py2puml/py2puml.py:12: in py2puml
    inspect_package(
py2puml/inspection/inspectpackage.py:19: in inspect_package
    domain_item_module: ModuleType = import_module(name)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:783: in exec_module
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    from dataclasses import dataclass
    
>   from withrootnotincwd.point import Point
E   ModuleNotFoundError: No module named 'withrootnotincwd'

tests/modules/withrootnotincwd/segment.py:3: ModuleNotFoundError

Note: This was identified by pytest.

After noticing this error, I tried running py2puml via CLI and encounter the same error:

(venv) supratiks-mbp:py2puml supratiksarkar$ py2puml tests/modules/withrootnotincwd/ tests.modules.withrootnotincwd
Traceback (most recent call last):
  File "/Users/supratiksarkar/Desktop/Prod/venv/bin/py2puml", line 8, in <module>
    sys.exit(run())
  File "/Users/supratiksarkar/Desktop/Prod/venv/lib/python3.8/site-packages/py2puml/cli.py", line 24, in run
    print(''.join(py2puml(args.path, args.module)))
  File "/Users/supratiksarkar/Desktop/Prod/venv/lib/python3.8/site-packages/py2puml/py2puml.py", line 12, in py2puml
    inspect_package(
  File "/Users/supratiksarkar/Desktop/Prod/venv/lib/python3.8/site-packages/py2puml/inspection/inspectpackage.py", line 19, in inspect_package
    domain_item_module: ModuleType = import_module(name)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/supratiksarkar/Desktop/Prod/py2puml/tests/modules/withrootnotincwd/segment.py", line 3, in <module>
    from withrootnotincwd.point import Point
ModuleNotFoundError: No module named 'withrootnotincwd'

In order to fix this error, I invested the segments.py file under test/modules/withrootnotincwd and notice that changing the following line:

from withrootnotincwd.point import Point

to

from .point import Point

fixes the issue.

Output after fixing the file:

(venv) supratiks-mbp:py2puml supratiksarkar$ py2puml tests/modules/withrootnotincwd/ tests.modules.withrootnotincwd
@startuml tests.modules.withrootnotincwd
namespace tests.modules.withrootnotincwd {
  namespace point {}
  namespace segment {}
}
class tests.modules.withrootnotincwd.point.Point {
  x: float
  y: float
}
class tests.modules.withrootnotincwd.segment.Segment {
  a: Point
  b: Point
}
tests.modules.withrootnotincwd.segment.Segment *-- tests.modules.withrootnotincwd.point.Point
footer Generated by //py2puml//
@enduml

(venv) supratiks-mbp:py2puml supratiksarkar$

Can you please take a look at it?

Thank you so much!

@jjerphan
Copy link
Contributor

Hi @supratik21,

Thank you for this report.

I will try to have a look at it when I get some time.

@supratik21
Copy link
Author

Hello @jjerphan,

Thank you for looking into this. I encountered this error while testing py2puml for my application. It'd be extremely helpful if you let me know once you have tested this from your end. Look forward to hearing from you soon.

@lucsorel
Copy link
Owner

lucsorel commented May 14, 2023

hello @supratik21 😃, thank you for your message.

And thank you @jjerphan for giving some feedback.

I investigated and there is no bug, but a misunderstanding:

  • it is true that the following commands yield the error you reported:
# activates the environment to make py2puml available in the virtual environment
source .venv/bin/activate
py2puml tests/modules/withrootnotincwd/ tests.modules.withrootnotincwd

It is because tests.modules.withrootnotincwd is an incorrect Python module path. In this test example, withrootnotincwd is the root module of a test Python project, thus the ModuleNotFoundError: No module named 'withrootnotincwd' error message if you start the CLI call with the tests.modules.withrootnotincwd module path (which does not make sense in this test case).

# activates the environment to make py2puml available in the virtual environment
source .venv/bin/activate
# moves to the appropriate working directory before running the py2puml command
cd tests/modules
py2puml withrootnotincwd withrootnotincwd

Some day, the py2puml command may handle calls like py2puml tests/modules/withrootnotincwd/ withrootnotincwd but it is not a priority because py2puml is meant to be used as development library within a python project, not as a system tool. I acknowledge that this can be misleading 😃

@lucsorel lucsorel closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2023
@lucsorel lucsorel added the invalid This doesn't seem right label May 14, 2023
@lucsorel lucsorel self-assigned this May 14, 2023
@lucsorel lucsorel removed their assignment May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants