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

docker/gen_uml.sh fails if directory name starts with "proto" #47

Open
feedhandler opened this issue Mar 16, 2022 · 1 comment
Open

Comments

@feedhandler
Copy link

Hi,
If proto location is directory starting with "proto" then the gen_uml.sh fails to rename the file
Example

|-- foo.proto
`-- lib
    `-- protobuf
        `-- bar.proto

and foo.proto imports lib/protobuf/bar.proto
Output from dockerrun:

./dockerrun.sh /tmp/tmp.Z9AnkLGBd9 /tmp/tmp.NSd9b8t2DP/
MODULE:
INFO:__main__:Imported: foo_pb2
INFO:__main__:Writing diagram to /out/foo_pb2.png
ERROR:__main__:Failed to import lib_pb2buf/bar.proto
Traceback (most recent call last):
  File "//protobuf_uml_diagram.py", line 240, in <module>
    main()
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "//protobuf_uml_diagram.py", line 234, in main
    .from_file(proto) \
  File "//protobuf_uml_diagram.py", line 187, in from_file
    raise e
  File "//protobuf_uml_diagram.py", line 184, in from_file
    self._proto_module = _module(proto_file)
  File "//protobuf_uml_diagram.py", line 168, in _module
    return import_module(no_extension.replace("/", "."))
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'lib_pb2buf'

The problem is when gen_uml.sh tries to replace .proto extension with _pb2, the regex is not working properly, it changes the "proto" in the directory name, instead of the file extension

I fixed it by changing from

    p="${p/.proto/_pb2}"

to

    p="${p%.proto}_pb2"

Thanks

@kinow
Copy link
Owner

kinow commented Mar 16, 2022

Hi @feedhandler ! Thanks for reporting it. Would you be able to send a pull request with the fix? Not sure if it'd be easy/doable to have a test for that since it requires the directory + running docker. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants