[python] Add python_package and --prefix argument
What language does this apply to? Python generation
Describe the problem you are trying to solve.
The problem is that python generated files are generated in global import scope, using package as python package. This requires path mangling, presents a lot of issues when using protos in libraries, and creates potential risks of collision.
Describe the solution you'd like
- It would be great to have a
python_packageoption as for java, go and other languages. - It'd be really helpful to have a compiler config, something like
--python=package_prefix=my.package.protos.
Describe alternatives you've considered
- Modifying the generated sources — one can modify the sources using AST, but that is a bad decision.
- Changing the proto package — can not be done to dependencies, as that will break the code (eg protovalidate).
Also, absence of the feature allows developers to create generator plugins with bad generating decisions. For instance, one of the most popular 3d-party plugins, mypy-protobuf, brings the package structure all over the place, which makes modification through AST extremely hard.
The issue described here seems related to https://github.com/protocolbuffers/protobuf/issues/1491, which is related to a larger theme of "Python users need a well-lit path for using protobufs in open-source."
What we can recommend (and what more closely corresponds to Google's assumptions), as described in https://github.com/protocolbuffers/protobuf/issues/1491#issuecomment-263772124, is that we generally keep the proto files and the generated files in the same directory. Outside of Google, it's not uncommon to want to keep all the generated code into a separate directory and have code that are able to use relative imports. We can't easily support this due to what Josh described in https://github.com/protocolbuffers/protobuf/issues/1491#issuecomment-263924909.
Having a prefix might be a good solution, but it should be a file option, not a compiler flag. It would be nice if the option is at a directory level so an "organization" can specify a common prefix.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
Still active.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
Active. +1
Would also appreciate that feature.