SRserves85 / avro-to-python

Light tool for compiling avro schema files (.avsc) to python classes
MIT License
25 stars 19 forks source link

Wrong import when generating in subdirectory/subpackage #16

Open AntoineDuComptoirDesPharmacies opened 2 years ago

AntoineDuComptoirDesPharmacies commented 2 years ago

Hi,

We are currently trying your library to generate Python classes from ".avsc" files prior application start.

What we did :

reader = AvscReader(directory="/events") # ".avsc" files are located in "events" directory
reader.read()
writer = AvroWriter(reader.file_tree)
writer.write(root_dir='api/events')

What happen :

"api/events/statistic/init.py" contains this :

""" init file for file imports at namespace level """
from statistic.UserLink import UserLink

from statistic.SaleOfferStatistic import SaleOfferStatistic

Instead of this :

""" init file for file imports at namespace level """
from api.events.statistic.UserLink import UserLink

from api.events.statistic.SaleOfferStatistic import SaleOfferStatistic

Records imports look like this :

# -*- coding: utf-8 -*-

""" avro python class for file: SaleOfferStatistic """

import json
from helpers import default_json_serialize, todict
from typing import Union
from statistic.UserLink import UserLink

Instead of this :

# -*- coding: utf-8 -*-

""" avro python class for file: SaleOfferStatistic """

import json
from api.events.helpers import default_json_serialize, todict
from typing import Union
from api.events.statistic.UserLink import UserLink

We tried to set pip="api.events" in the write method in order to get the correct import prefix but it broke the directory where classes should be generated.

Is there something that we are doing bad ? How can we accomplish this generation.

Thanks in advance for your help ! Yours faithfully, Antoine