=================================
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
typing in order to query module hierarchies for extensions.
===============================
Declaring an Extension Protocol
===============================
For example, if we want to be able to create instance of object like these from a factory.
.. code:: python
class Hey:
def __str__(self):
return "Hey"
class Ho:
def __str__(self):
return "Ho"
# The following class defines a protocol that defines an extenstion type.
# Extensions
class MyExtTypeProtocol(ExtProtocol):
ext_protocol_name = "mojo-myextypeprotocol"
@classmethod
def give_me_a_hey(cls):
...
@classmethod
def give_me_a_ho(cls):
...
==================================
Implementing an Extension Protocol
==================================
The code below is implementing the extension protocol defined above. When a class
implements an extension protocol, it will inherit from the protocol it is implementing.
By inheriting from the protocol, it pulls in the `ext_protocol_name` variable which
ensures that the derived type is declared to implement a given protocol.
Another important thing to look at in the code below is the class variable `PRECEDENCE`.
The `PRECEDENCE` number indicates to the SuperFactory which extensions to return when
an extension is queried based on precedence of overload and relevance. The higher number
precedence is considered by the SuperFactory to have the most relevance.
.. code:: python
class MyExtTypeFactory(ExtFactory, MyExtTypeProtocol):
PRECEDENCE = 10
@classmethod
def give_me_a_hey(cls):
return Hey
@classmethod
def give_me_a_ho(cls):
return Ho
===================================
Configuration for Custom Extensions
===================================
In order to be able to extend packages, you must tell the `mojo-extension` code where
the root packages are that need to be searched for extension factories. Then what we
do is we register the root modules under which the factory types will be found.
---------------------------------------------------------------
Setting the MJR_CONFIGURED_FACTORY_MODULES Variable from Python
---------------------------------------------------------------
.. code:: python
from mojo.extension.extensionconfiguration import ExtensionConfiguration
from mojo.extension.wellknown import ConfiguredSuperFactorySingleton
ExtensionConfiguration.MJR_CONFIGURED_FACTORY_MODULES = [
"mypkg.factories",
]
---------------------------------------------------------------
Setting the MJR_CONFIGURED_FACTORY_MODULES Environment Variable
---------------------------------------------------------------
.. code::
MJR_CONFIGURED_FACTORY_MODULES=mypkg.a.factories,mypkg.b.factories
----------------------------------------------------------------
Setting the MJR_CONFIGURED_FACTORY_MODULES in the Startup Config
----------------------------------------------------------------
.. code::
[MOJO-EXTENSION]
MJR_CONFIGURED_FACTORY_MODULES=mypkg.a.factories,mypkg.b.factories
========================
Loading Custom Factories
========================
In order to load extension factories, we utilize the `ConfiguredSuperFactorySingleton` singleton
object that is maintained by the `mojo-extension` package. You can get a reference to the super
factory singleton by using code similar to the code below:
.. code:: python
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.
.. code:: python
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
==========
- `User Guide <userguide/userguide.rst>`_
- `Coding Standards <userguide/10-00-coding-standards.rst>`_
Raw data
{
"_id": null,
"home_page": "http://automationmojo.com",
"name": "mojo-extension",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "python",
"author": "Myron Walker",
"author_email": "myron.walker@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8b/3c/7dfd523f01aeffd84756194d672aa12d55a4eac606f601e94d3411e0cf1e/mojo_extension-2.0.4.tar.gz",
"platform": null,
"description": "=================================\nAutomation Mojo Extension Package\n=================================\n\nThis is a python package that provides a mechanism for extending other python packages. This\npackage is different from other python extension packages in that it uses the python Protocol\ntyping in order to query module hierarchies for extensions.\n\n\n===============================\nDeclaring an Extension Protocol\n===============================\n\nFor example, if we want to be able to create instance of object like these from a factory.\n\n.. code:: python\n\n class Hey:\n def __str__(self):\n return \"Hey\"\n\n class Ho:\n def __str__(self):\n return \"Ho\"\n\n \n # The following class defines a protocol that defines an extenstion type.\n # Extensions \n\n class MyExtTypeProtocol(ExtProtocol):\n\n ext_protocol_name = \"mojo-myextypeprotocol\"\n\n @classmethod\n def give_me_a_hey(cls):\n ...\n\n @classmethod\n def give_me_a_ho(cls):\n ...\n\n==================================\nImplementing an Extension Protocol\n==================================\n\nThe code below is implementing the extension protocol defined above. When a class\nimplements an extension protocol, it will inherit from the protocol it is implementing.\nBy inheriting from the protocol, it pulls in the `ext_protocol_name` variable which\nensures that the derived type is declared to implement a given protocol.\n\nAnother important thing to look at in the code below is the class variable `PRECEDENCE`.\nThe `PRECEDENCE` number indicates to the SuperFactory which extensions to return when\nan extension is queried based on precedence of overload and relevance. The higher number\nprecedence is considered by the SuperFactory to have the most relevance.\n\n.. code:: python\n\n class MyExtTypeFactory(ExtFactory, MyExtTypeProtocol):\n\n PRECEDENCE = 10\n\n @classmethod\n def give_me_a_hey(cls):\n return Hey\n \n @classmethod\n def give_me_a_ho(cls):\n return Ho\n\n\n===================================\nConfiguration for Custom Extensions\n===================================\n\nIn order to be able to extend packages, you must tell the `mojo-extension` code where\nthe root packages are that need to be searched for extension factories. Then what we\ndo is we register the root modules under which the factory types will be found.\n\n---------------------------------------------------------------\nSetting the MJR_CONFIGURED_FACTORY_MODULES Variable from Python\n---------------------------------------------------------------\n\n.. code:: python\n\n from mojo.extension.extensionconfiguration import ExtensionConfiguration\n from mojo.extension.wellknown import ConfiguredSuperFactorySingleton\n\n ExtensionConfiguration.MJR_CONFIGURED_FACTORY_MODULES = [\n \"mypkg.factories\",\n ]\n\n---------------------------------------------------------------\nSetting the MJR_CONFIGURED_FACTORY_MODULES Environment Variable\n---------------------------------------------------------------\n\n.. code::\n \n MJR_CONFIGURED_FACTORY_MODULES=mypkg.a.factories,mypkg.b.factories\n\n----------------------------------------------------------------\nSetting the MJR_CONFIGURED_FACTORY_MODULES in the Startup Config\n----------------------------------------------------------------\n\n.. code::\n \n [MOJO-EXTENSION]\n MJR_CONFIGURED_FACTORY_MODULES=mypkg.a.factories,mypkg.b.factories\n\n========================\nLoading Custom Factories\n========================\n\nIn order to load extension factories, we utilize the `ConfiguredSuperFactorySingleton` singleton\nobject that is maintained by the `mojo-extension` package. You can get a reference to the super\nfactory singleton by using code similar to the code below:\n\n.. code:: python\n\n from mojo.extension.wellknown import ConfiguredSuperFactorySingleton\n\n superfactory = ConfiguredSuperFactorySingleton()\n\n\nThen when we want to get the type from the extension, we utilize the protocol that\nwas declared and ask for the type using the function on the protocol that will return\nthe type.\n\n.. code:: python\n\n hey_type = self._super_factory.get_override_types_by_order(MyExtTypeProtocol.give_me_a_hey)\n ho_type = self._super_factory.get_override_types_by_order(MyExtTypeProtocol.give_me_a_ho)\n\n hey = hey_type()\n ho = ho_type()\n\n print(\"\")\n print(f\"{hey}... {ho}... {hey}... {ho}...\")\n\n\n==========\nReferences\n==========\n\n- `User Guide <userguide/userguide.rst>`_\n- `Coding Standards <userguide/10-00-coding-standards.rst>`_\n",
"bugtrack_url": null,
"license": "LICENSE.txt",
"summary": "Automation Mojo Extension Package",
"version": "2.0.4",
"project_urls": {
"Homepage": "http://automationmojo.com",
"Repository": "https://github.com/automationmojo/mojo-extension"
},
"split_keywords": [
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cd2b72319208b6fa55b48d9232b0f6ee9e4da93735397a3b47d0c4ac187ac819",
"md5": "791fa97af3fb4f1448658a87a0d6ff63",
"sha256": "6a8a80736b10880e67b031a0462ee2d6eb0ac25526c8f045a38ef94b36ef4381"
},
"downloads": -1,
"filename": "mojo_extension-2.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "791fa97af3fb4f1448658a87a0d6ff63",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 9332,
"upload_time": "2024-08-11T02:13:43",
"upload_time_iso_8601": "2024-08-11T02:13:43.616547Z",
"url": "https://files.pythonhosted.org/packages/cd/2b/72319208b6fa55b48d9232b0f6ee9e4da93735397a3b47d0c4ac187ac819/mojo_extension-2.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8b3c7dfd523f01aeffd84756194d672aa12d55a4eac606f601e94d3411e0cf1e",
"md5": "cd5f9ed38b8c678e16eee6ef492d79b8",
"sha256": "be0abc391529f64dd8d2a4c23590271528955abc6c86b81cb28ae01843fbc6b6"
},
"downloads": -1,
"filename": "mojo_extension-2.0.4.tar.gz",
"has_sig": false,
"md5_digest": "cd5f9ed38b8c678e16eee6ef492d79b8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 8345,
"upload_time": "2024-08-11T02:13:44",
"upload_time_iso_8601": "2024-08-11T02:13:44.775647Z",
"url": "https://files.pythonhosted.org/packages/8b/3c/7dfd523f01aeffd84756194d672aa12d55a4eac606f601e94d3411e0cf1e/mojo_extension-2.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-11 02:13:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "automationmojo",
"github_project": "mojo-extension",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mojo-extension"
}