SRserves85 / avro-to-python

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

Feature/fix import and update dependencies #17

Closed AntoineDuComptoirDesPharmacies closed 2 years ago

AntoineDuComptoirDesPharmacies commented 2 years ago

Objective of this PR is to give the capability to generate Python classes in a subpackage of an existing application. (See: 16)

It add a new flag that allow to override the default top level package name chosen for classes generation. For information, top level package is currently :

How-to : Using this new flag, it is now possible to generate classes without pip but with a custom top level package. Example :

with pkg_resources.path(api, "event") as event_directory:
        # initialize the reader object
        reader = AvscReader(directory=event_directory)

        # generate the acyclic tree object
        reader.read()

        # initialize the writer object
        writer = AvroWriter(reader.file_tree, top_level_package="api.event")

        # compile python files using 'tests/test_records as the namespace root'
        writer.write(root_dir="."))

Bonus : We updated the package dependencies to use ranges of compatibility instead of fixed value. This is useful in projects where these dependencies are already set to fixed value which is distinct from this library.