kinow / protobuf-uml-diagram

Create UML diagrams from Protobuf compiled .proto files using Python
https://github.com/kinow/protobuf-uml-diagram
Apache License 2.0
69 stars 12 forks source link

TypeError: main() got an unexpected keyword argument 'fullname' #13

Closed georgasa closed 3 years ago

georgasa commented 3 years ago

Hello,

I'm constantly get the following error:

root@eeslave-43-spiderman-ft-node:~/protobuf-uml-diagram-0.6 :( $ protobuf-uml-diagram --proto greeting.proto --output /root/ Traceback (most recent call last): File "/usr/local/bin/protobuf-uml-diagram", line 11, in load_entry_point('protobuf-uml-diagram', 'console_scripts', 'protobuf-uml-diagram')() File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) TypeError: main() got an unexpected keyword argument 'fullname'

root@eeslave-43-spiderman-ft-node:~/protobuf-uml-diagram-0.6 :( $ protobuf-uml-diagram --proto greeting.proto --output /root/ --fullname tolis Traceback (most recent call last): File "/usr/local/bin/protobuf-uml-diagram", line 11, in load_entry_point('protobuf-uml-diagram', 'console_scripts', 'protobuf-uml-diagram')() File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) TypeError: main() got an unexpected keyword argument 'fullname'

something goes wrong with the fullname, although it is supposed to be an optional filed.

Thank you

kinow commented 3 years ago

Hi @georgasa I think you found a legit bug. I've fixed in the linked commit. The unit tests cover most of the code, but not an e2e scenario, which would use click. I'll add a test that should prevent bugs like this happening again.

kinow commented 3 years ago

Should be working now @georgasa , can you please pip install -U protobuf-uml-diagram and test it again? It should install 0.7.

something goes wrong with the fullname, although it is supposed to be an optional filed.

I think I started with that idea, but due to lack of time I implemented only the full name in the diagrams, without making it an optional configuration.

Cheers Bruno

georgasa commented 3 years ago

Hello Bruno,

thank a lot for your prompt reaction. I would like to have some assistance on how to use your tool. Attached the example proto file and the generated file from protoc-gen-go compiler: greetpb.zip

when I'm running the protobuf-uml-diagram. I'm getting the following error:

root@eeslave-43-spiderman-ft-node:~/protobuf-uml-diagram-0.6$ :) $ protobuf-uml-diagram --proto greet.pb.go --output /root/ Traceback (most recent call last): File "/usr/local/bin/protobuf-uml-diagram", line 8, in sys.exit(main()) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in call return self.main(args, kwargs) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(args, kwargs) File "/usr/local/lib/python3.7/site-packages/protobuf_uml_diagram.py", line 226, in main .from_file(proto) \ File "/usr/local/lib/python3.7/site-packages/protobuf_uml_diagram.py", line 179, in from_file self._proto_module = _module(proto_file) File "/usr/local/lib/python3.7/site-packages/protobuf_uml_diagram.py", line 164, in _module return import_module(proto.replace(".proto", "_pb2").replace("/", ".")) File "/usr/local/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 953, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 953, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'greet'**

What am I doing wrong?

Thank you, Apostolos

kinow commented 3 years ago

Hi Apostolos,

What am I doing wrong?

Not much, I would blame the poor documentation, or not being very explicit on how this library works. So sorry.

I created protobuf-uml-diagram to add the diagram to the docs of a Python project. I used the Python protobuf module, which reads compiled $file.proto Python modules.

Here's your diagram:

greet_pb2

To create it, I did the following:

  1. protoc greet.proto --python_out=. which creates the Python module greet_pb2.py
  2. PYTHONPATH=. protobuf-uml-diagram --proto greet_pb2 --output=.

Thinking now, I am wondering if the Python protobuf port has a programmatic way to run protoc. If so, then the input of the command could be either a protobuf Python module, or a protobuf definition .proto file.

Not sure if that's what you were looking for?

Cheers Bruno

georgasa commented 3 years ago

The picture is much clearer now (thank you Bruno). However I still can't reach the desired target (which actually is the picture you sent me!):

[root@eeslave-43-spiderman-ft-node ~]# PYTHONPATH=. protobuf-uml-diagram --proto greeting_pb2 --output=. Traceback (most recent call last): File "/usr/bin/protobuf-uml-diagram", line 11, in load_entry_point('protobuf-uml-diagram==0.7', 'console_scripts', 'protobuf-uml-diagram')() File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 484, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2714, in load_entry_point return ep.load() File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2332, in load return self.resolve() File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2338, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/usr/lib/python2.7/site-packages/protobuf_uml_diagram.py", line 42 def convert(self, value: Text, param: Text, ctx) -> Path: ^ SyntaxError: invalid syntax

Attached the proto and the compiled proto. proto.zip

Thanks, Apostolos

georgasa commented 3 years ago

Also in a pure python3 environment there're some other issues:

[root@tankovic protobuf-uml-diagram]# python3 protobuf_uml_diagram.py --proto proto/greet_pb2 --output=. Traceback (most recent call last): File "protobuf_uml_diagram.py", line 28, in from google.protobuf.descriptor import Descriptor, FieldDescriptor ModuleNotFoundError: No module named 'google' [root@tankovic protobuf-uml-diagram]# pip3 install google WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead. Requirement already satisfied: google in /usr/local/lib/python3.6/site-packages Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.6/site-packages (from google) Requirement already satisfied: soupsieve>1.2; python_version >= "3.0" in /usr/local/lib/python3.6/site-packages (from beautifulsoup4->google)

kinow commented 3 years ago

Hi @georgasa

The picture is much clearer now (thank you Bruno). However I still can't reach the desired target (which actually is the picture you sent me!):

We will get there!

Also in a pure python3 environment there're some other issues:

Was going to say we needed Python 3, but looks like you are on it now.

ModuleNotFoundError: No module named 'google'

The google module that it is complaining is protobuf. They use something called namespace packages (PEP-420), where google is the top level package, with several sub-modules, like google.protobuf.

From your error traceback it looks like you are now using Python 3.6. The namespaces were added in 3.3, so it should work fine. Did you install the latest version with pip? It is supposed to install protobuf too.

Could you try these commands and see if they provide any clue, please?

# it should the location of the installed script, confirm it's in Python 3.6 modules directory (it has 3.6 somewhere in the name I guess?)
$ which protobuf-uml-diagram 

# this command should list all your python modules available using pip/setuptools; confirm protobuf-uml-diagram is there, and check if location is similar to the location from command above
$ pip list

# just to check nothing is wrong with your environment, it should just say "No broken requirements found."
$ pip check
georgasa commented 3 years ago

I created a totally new, fresh CentOS-8 VM with python 3.9.0 and everything now works as a charm! Many many thanks for your precious help Bruno!

image

Regards, Apostolos

kinow commented 3 years ago

Really glad it worked Apostolos. Thanks for your patience!