Comments (4)
Hey @o-murphy! Thanks for the report. Can you give more details about the steps you're running and the errors you are seeing?
from protovalidate-python.
I believe I have the same problem.
My source code is structured like
src/my_module/stuff.py
protos/events/v1/some.proto
my buf.gen.yaml:
# buf.gen.yaml
version: v1
plugins:
- plugin: buf.build/protocolbuffers/python:v21.9
out: ./src/my_module
- plugin: buf.build/protocolbuffers/pyi:v21.9
out: ./src/my_module
I generate my python proto files into my module:
buf generate --include-imports protos
This puts the generated python classes and the buf validate files in
src/my_module/events
src/my_module/buf/validate
so if I wanted to importe the validate_pb2.py I need to do
from my_module.buf.validate import expression_pb2
but protovalidate wants from buf.validate import expression_pb2
.
(Disclaimer, to make generated python proto classes work with this module src layout you have to do a sed rewrite trick - I was just hoping that I do not need some other hacks for validation. Also here it would be trickier since I would have to rewrite protovalidate module )
from protovalidate-python.
Got it! Yes this is a known issue (also reported on buf) for protobuf python generation in general. There are some workarounds in that linked thread, but without a rewrite or a sys.path.insert
, you'll need to generate into the root of the python project.
from protovalidate-python.
I want to distribute my project to PyPi, I use protovalidate
as a dependency. I also want to generate *_fb2.py and buf
files and distribute it as a part of my project, so I need to move generated *_fb2.py
files and buf
directory to the top-level package's dir. But in this case I get an import error if I use import protovalidate
in one of the inner modules, cause the protovalidate
tries to import the buf
from the project root dir but not from the package top-level dir. It happen even if I change the import paths in a *_pb2.py
files.
Now I have a temporary sollution: copying the protovalidate
directly to my library and fix the import's in each module of protovalidate
to solve it, for example:
# protovalidate.validator.py
from a7p.buf.validate import expression_pb2 # type: ignore
from a7p.protovalidate.internal import constraints as _constraints
from a7p.protovalidate.internal import extra_func
Can you provide me a way how can I set the top-level of my library to protovalidate module to get the valid import of buf
module?
Look at this project tree please
In my case: pya7p - the project root and the a7p - the package top level dir
from protovalidate-python.
Related Issues (13)
- [Question] How to install? HOT 2
- [BUG] Generated Python code leads to runtime errors HOT 3
- support proto-plus wrapped types HOT 1
- [BUG] Import error (buf/validate/validate.proto: does not exist)
- [BUG] requires-python = ">=3.7" in pyproject.toml is inaccurate
- [BUG]: On import of protovalidate HOT 1
- Support for python <3.11 HOT 3
- Cannot import protovalidate `ModuleNotFoundError: No module named 'buf'` HOT 5
- Consider using a RE2 compliant CEL evaluator
- [BUG] ModuleNotFoundError: No module named 'buf' when importing protovalidate HOT 7
- [BUG] python use python -m grpc_tools.proto gen code get ModuleNotFoundError: No module named 'buf' HOT 3
- Buf doesn't generate protovalidate python files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protovalidate-python.