Skip to main content

Automation Mojo Extension Package

Project description

Automation Mojo Extension Package

This is a python package that provides a mechanism for extending other python packages. This package is different from other python extension packages in that it uses the python Protocol type to query for a type.

For example, if we want to be able to create instance of object like these from a factory.

class Hey:
    def __str__(self):
        return "Hey"

class Ho:
    def __str__(self):
        return "Ho"


class MyExtTypeProtocol(ExtProtocol):

    ext_protocol_name = "mojo-myextypeprotocol"

    @classmethod
    def give_me_a_hey(cls):
        ...

    @classmethod
    def give_me_a_ho(cls):
        ...

class MyExtTypeFactory(ExtFactory, MyExtTypeProtocol):

    @classmethod
    def give_me_a_hey(cls):
        return Hey

    @classmethod
    def give_me_a_ho(cls):
        return Ho

Then what we do i we register the module where the type is found.

from mojo.extension.extensionconfiguration import ExtensionConfiguration
from mojo.extension.wellknown import ConfiguredSuperFactorySingleton

ExtensionConfiguration.CONFIGURED_FACTORY_MODULES = [
        "myextinst",
        "myexttype"
    ]

Then we get an instance of the super factory singleton.

from mojo.extension.wellknown import ConfiguredSuperFactorySingleton

superfactory = ConfiguredSuperFactorySingleton()

Then when we want to get the type from the extension, we utilize the protocol that was declared and ask for the type using the function on the protocol that will return the type.

hey_type = self._super_factory.get_override_types_by_order(MyExtTypeProtocol.give_me_a_hey)
ho_type = self._super_factory.get_override_types_by_order(MyExtTypeProtocol.give_me_a_ho)

hey = hey_type()
ho = ho_type()

print("")
print(f"{hey}... {ho}... {hey}... {ho}...")

References

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

mojo_extension-0.0.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

mojo_extension-0.0.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mojo_extension-0.0.2.tar.gz.

File metadata

  • Download URL: mojo_extension-0.0.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.10.6 Linux/6.2.0-36-generic

File hashes

Hashes for mojo_extension-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a2263cde16a2cfb1da9b1cd557558f130ed3ed1c71c5bd0aaef70b3dbb159393
MD5 2eb7272287b493ddfb43104f51417917
BLAKE2b-256 17c30ecc25f2af53fd6943dd5f5936c96e0b6359b9848eb72dff0a2341f01b3b

See more details on using hashes here.

File details

Details for the file mojo_extension-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mojo_extension-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.10.6 Linux/6.2.0-36-generic

File hashes

Hashes for mojo_extension-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d997972fc60e8a8e94b5cf3ebcc63b80b7319ff00b7bd6090fc49c0af13e5987
MD5 fd344a7d282e9a5ba44b389df08ab95a
BLAKE2b-256 f0b2d94debb9ad0459bce67c9194a6a4d41a6c448feb358235d53e2e74dc946a

See more details on using hashes here.

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