fedej / poetry-grpc-plugin

gRPC Poetry plugin
MIT License
20 stars 4 forks source link

Error: The command "protoc-gen-mypy" is either misspelled or could not be found. #16

Open ghost opened 2 years ago

ghost commented 2 years ago

Invoking the protoc compiler results in the following error:

The command "protoc-gen-mypy" is either misspelled or could not be found. --mypy_out: protoc-gen-mypy: Plugin failed with status code 1.

This happens for both the "poetry protoc" as well as the "poetry update" (in combination with the "[tool.poetry-grpc-plugin]" table) commands.

I installed poetry with pipx and added poetry-grpc-plugin via pipx inject.

My System:

fedej commented 2 years ago

I haven't used pipx myself, I'll try to reproduce. I suspect pipx inject installs the package in the virtualenv differently to what adding it via poetry does

fedej commented 1 year ago

Hi @Elijahh177, apologies for the long delay. I've installed both poetry and the plugin using pipx and it's working as expected for me. Can you share more details on how your (virtual)environment is set up? I'm currently unable to reproduce. Thanks

ghost commented 1 year ago

Hey @fedej, It seems that the following lines are not triggered correctly:

https://github.com/fedej/poetry-grpc-plugin/blob/abcb5d05221d7f1dd68659c51a61274a4ef9adc5/poetry_grpc_plugin/plugins.py#L43-L48

When I'm adding the protoc-gen-mypy executable manually to the system path, everything is working fine.

I would provide more information, but didn't found a way to debug poetry plugins with VSCode.

ghost commented 1 year ago

I've reinstalled poetry and reinstalled the plugin with poetry self add poetry-grpc-plugin and the same error message appears.

@fedej do you know a way to attach the VSCode debugger to the poetry resp. poetry-grpc-plugin process?

fedej commented 1 year ago

I'm not using VSCode, so I'm not aware of how that works. I have some free time later on today and will check VSCode out as well as why that piece of code is not executing. As an alternative to debugging, and a good idea in general, I can add more debug logging to improve troubleshooting.

fedej commented 1 year ago

@Elijahh177 I wasn't able to find a clean way to debug directly from VSCode. The only thing that worked is manually adding breakpoints to the python files from the poetry environment. I've added a few more logging statements and created a new release. These logs should show up with -vvv e.g: poetry -vvv update or poetry -vvv protoc

Let me know if that doesn't help

fedej commented 1 year ago

@Elijahh177 is this still a problem?

davireis commented 1 year ago

FWIW, I am in windows and faced the same problem. Tested with -vvv and verified that the virtualenv was being added correctly to the PATH, nonetheless protoc.main still wasn't picking protoc-gen-mypy.

What worked was to run poetry run poetry update, which added the virtualenv path earlier.

ghost commented 1 year ago

@Elijahh177 is this still a problem?

Yes it's still a problem.

ghost commented 1 year ago

@fedej I switched my projects to PDM, since it allows for much easier user scripting.

You just have to add something like this to your pyproject.toml and your *.proto files will compile after every install:

[tool.pdm.dev-dependencies]
dev = [
    "grpcio-tools>=1.54.2",
]

[tool.pdm.scripts]
post_install = "python -m grpc_tools.protoc --proto_path=src --python_out=src --pyi_out=src --grpc_python_out=src src/path/to/proto/interface.proto"
fedej commented 10 months ago

@fedej I switched my projects to PDM, since it allows for much easier user scripting.

You just have to add something like this to your pyproject.toml and your *.proto files will compile after every install:

[tool.pdm.dev-dependencies]
dev = [
    "grpcio-tools>=1.54.2",
]

[tool.pdm.scripts]
post_install = "python -m grpc_tools.protoc --proto_path=src --python_out=src --pyi_out=src --grpc_python_out=src src/path/to/proto/interface.proto"

@Elijahh177 I'm glad you were able to unblock yourself.

At this point it may be too little too late, but I changed how the plugin adds to stuff to PATH and I believe the problem should be fixed now. I'll release a new version shortly.