{ "info": { "author": "Salvador de la Puente Gonz\u00e1lez", "author_email": "salva@unoyunodiez.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Libraries" ], "description": "``abm`` - Abstract modules\n==========================\n\n Allow loading non Python module formats as modules.\n\nInstall\n-------\n\nUse ``pip`` for installing:\n\n.. code-block:: bash\n\n $ pip install abm\n\nUsage\n-----\n\nOnce installed, you can activate ``abm`` by importing ``abm.activate``:\n\n.. code-block:: python\n\n from abm import activate\n\nNow you can register new loaders by doing:\n\n.. code-block:: python\n\n from abm.loaders import IniLoader\n IniLoader.register()\n\nSince now, you can load ``*.ini`` files as if they were modules:\n\n.. code-block:: ini\n\n # config.ini\n [section]\n option = value\n\n.. code-block:: python\n\n import config\n assert(config['example'] is not None)\n assert(config['example']['option'] is 'value')\n\n.. note:: ``abm.loaders`` package is work in progress.\n The ``abm.loaders`` package is still work in progress and it will gather\n a set of useful loaders for common extensions.\n\n\nWriting a loader\n----------------\n\nExtend the base loader ``AbmLoader`` provided in ``abm.loaders`` and implement\n``create_module`` and ``execute_module`` methods. Provide the ``extension``\nclass member to allow automatic registration:\n\n.. code-block:: python\n\n from configparser import ConfigParser\n from types import ModuleType\n from abm.loaders import AbmLoader\n\n\n class IniLoader(AbmLoader):\n\n extensions = ('.ini', )\n\n def __init__(self, name, path):\n self.file_path = path\n\n def create_module(self, spec):\n module = ConfigModule(spec.name)\n self.init_module_attrs(spec, module)\n return module\n\n def exec_module(self, module):\n module.read(self.file_path)\n return module\n\n\n class ConfigModule(ModuleType, ConfigParser):\n\n def __init__(self, specname):\n ModuleType.__init__(self, specname)\n ConfigParser.__init__(self)\n\n\nLoaders are initialized passing the name of the module in the form:\n\n.. code-block:: python\n\n 'path.to.the.module'\n\nAnd its absolute path.\n\nImplementing ``create_module``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``create_module`` function should produce a module of the correct type. Nothing\nmore. This method is passed with the module specification object used to find\nthe module:\n\n.. code-block:: python\n\n def create_module(self, spec)\n module = ConfigModule(spec.name)\n self.init_module_attrs(spec, module)\n return module\n\nImplementing ``execute_module``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``execute_module`` function should contain the code for loading the contents\nof the module:\n\n.. code-block:: python\n\n def execute_module(self, module):\n module.read(self.file_path)\n return module\n\nA good tip for determining how to implement this method is imagining you\ntrigger a reload of the module: the code syncing the module contents with the\nfile is what you should put here.\n\nHow does it work\n----------------\n\nExtension mechanism work by monkeypatching the ``FileFinder`` class in charge\nof reading Python several format modules from the local file system.\n\nInternally, ``FileFinder`` uses file loaders to read the several formats of\nPython modules identified by their file extension. Although these classes are\npublic, ``FileFinder`` does not expose any extension mechanism to link new\nextensions with new loaders.\n\nIn the spirit of ``sys.path_hooks`` and other extension hooks, activating\n``abm`` will expose a dictionary in ``sys.abm_hooks`` to register new loaders\ndynamically. For instance:\n\n.. code-block:: python\n\n import sys\n from abm.loaders import IniLoader\n from abm.core import activate\n\n activate()\n sys.abm_hooks['.ini'] = IniLoader\n\nIt works by turning the internal instance attribute ``_loaders`` of\n``FileFinder`` instances into a class property. Setting the property will\ndiverge the new value to a different attribute while reading the value will\ncombine the original one with the extensions in ``sys.abm_hooks``.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/delapuente/abm", "keywords": "abstract,module,import", "license": "", "maintainer": "", "maintainer_email": "", "name": "abm", "package_url": "https://pypi.org/project/abm/", "platform": "", "project_url": "https://pypi.org/project/abm/", "project_urls": { "Homepage": "https://github.com/delapuente/abm" }, "release_url": "https://pypi.org/project/abm/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Allow loading non Python module formats as modules", "version": "0.2.0" }, "last_serial": 4348307, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "702c3ea23f53b90decc1bf1a7483e45f", "sha256": "8f257dcf970bc9582b6b6ad634e84d14238cb914853f1b9932130285441711ae" }, "downloads": -1, "filename": "abm-0.1.1.tar.gz", "has_sig": false, "md5_digest": "702c3ea23f53b90decc1bf1a7483e45f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5343, "upload_time": "2018-10-05T09:16:29", "url": "https://files.pythonhosted.org/packages/60/9d/35679a0dc86121d108b301f23b87ee45c561d3dbcff1f05c7a0ae421ceca/abm-0.1.1.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "5d45e7ada7390df22ae3e9af934d8a63", "sha256": "5cd8e4cbfe8e7eea1d61913a673be2467a67fce748656662b2af6fd529a248a1" }, "downloads": -1, "filename": "abm-0.1.4.tar.gz", "has_sig": false, "md5_digest": "5d45e7ada7390df22ae3e9af934d8a63", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6159, "upload_time": "2018-10-05T12:53:19", "url": "https://files.pythonhosted.org/packages/1c/89/47a967d54caf09f93a5296eb9f3097acaae42d0b840eb324af5541a0fb04/abm-0.1.4.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "08d93c58e0256c0ffcb396d98083eb83", "sha256": "0b0bd2825ca72a82ec32577d6ff73c8b4dcbdb111aca3586cb6c4b9fa8eda68b" }, "downloads": -1, "filename": "abm-0.2.0.tar.gz", "has_sig": false, "md5_digest": "08d93c58e0256c0ffcb396d98083eb83", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6216, "upload_time": "2018-10-07T00:33:34", "url": "https://files.pythonhosted.org/packages/ce/2e/50d07ecbda9594c2e275a14f1b34ead17da838951fecc6e92e66b0f683e5/abm-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "08d93c58e0256c0ffcb396d98083eb83", "sha256": "0b0bd2825ca72a82ec32577d6ff73c8b4dcbdb111aca3586cb6c4b9fa8eda68b" }, "downloads": -1, "filename": "abm-0.2.0.tar.gz", "has_sig": false, "md5_digest": "08d93c58e0256c0ffcb396d98083eb83", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6216, "upload_time": "2018-10-07T00:33:34", "url": "https://files.pythonhosted.org/packages/ce/2e/50d07ecbda9594c2e275a14f1b34ead17da838951fecc6e92e66b0f683e5/abm-0.2.0.tar.gz" } ] }