Add prefix to import path when referencing generated modules [Python, flatc 24.3.25]
Imagine, we have the following schema file:
namespace mydata;
table Data {
value:string;
size:uint;
}
table Element {
data:Data;
}
root_type Element;
Running flatc --python -o . example.fbs --python-typing generates a directory mydata/ with an __init__.py, a Data.py and a Element.py.
As the Element references the Data table, it imports the class from that file:
# mydata/Element.py
import flatbuffers
from flatbuffers.compat import import_numpy
from typing import Any
from mydata.Data import Data
from typing import Optional
...
Is there a way, to modify the import statement from mydata.Data import Data to, e.g. from mylibray.mydata.Data import Data, without modifying the original schema files?
I did not find any direct way how to achieve this and ended up with modifying the source code of the generator to fit my needs.
¯\_(⊙~⊙)_/¯
Without that I would be screwed as I need to work with many schemes and I have not control over the namespaces within them.
If you are also that desperate, take a look at the return values of the functions GenPackageReference (line ~1105) and NestedFlatbufferType (line ~1105) in the src/idl_gen_python.cpp. I hope I didn't miss anything.
This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.
not-stale
This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.
This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.