Skip to content

Wrong import when generating in subdirectory/subpackage #16

@AntoineDuComptoirDesPharmacies

Description

Hi,

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

  • Our ".avsc" files are in the "statistic" namespace.
  • We want to generate the classes in the package "api.events.statistic"

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 :

  • Directory api/events/statistic is created (Super!)
  • Classes are correctly generated in the associated directory (Super!)
  • Imports are broken (Oops...)

"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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions