Skip to main content

Adorn

Project description

PyPI Status Python Version License

Tests Codecov

pre-commit Black

Features

adorn is a configuration tool for python code.

adorn can currently

  • instantiate an object

  • check that a config can instantiate an object

Example

from adorn.orchestrator.base import Base
from adorn.params import Params
from adorn.unit.complex import Complex
from adorn.unit.constructor_value import ConstructorValue
from adorn.unit.parameter_value import ParameterValue
from adorn.unit.python import Python


@Complex.root()
class Example(Complex):
   pass

@Example.register(None)
class Parent(Example):
    def __init__(self, parent_value: str) -> None:
        super().__init__()
        self.parent_value = parent_value


@Parent.register("child")
class Child(Parent):
    def __init__(self, child_value: int, **kwargs) -> None:
        super().__init__(**kwargs)
        self.child_value = child_value


base = Base(
    [
        ConstructorValue(),
        ParameterValue(),
        Example(),
        Python()
    ]
)

params = Params(
        {
            "type": "child",
            "child_value": 0,
            "parent_value": "abc"
        }
)

# well specified configuration
# we can type check from any level in the
# class hierarchy
assert base.type_check(Example, params) is None
assert base.type_check(Parent, params) is None
assert base.type_check(Child, params) is None

# instantiate
# we can instantiate from any level in the
# class hierarchy
example_obj = base.from_obj(
    Example,
    params
)

assert isinstance(example_obj, Child)


parent_obj = base.from_obj(
    Parent,
    params
)

assert isinstance(parent_obj, Child)


child_obj = base.from_obj(
    Child,
    params
)

assert isinstance(child_obj, Child)

Installation

You can install Adorn via pip from PyPI:

$ pip install adorn

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the Apache 2.0 license, Adorn is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from @cjolowicz’s Hypermodern Python Cookiecutter template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adorn-0.1.5.tar.gz (43.3 kB view hashes)

Uploaded Source

Built Distribution

adorn-0.1.5-py3-none-any.whl (63.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page