pyloader


Namepyloader JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttp://k0s.org/hg/pyloader
SummaryLoad python attributes from a string
upload_time2024-05-27 23:19:43
maintainerNone
docs_urlNone
authorJeff Hammel
requires_pythonNone
licenseMPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pyloader
===========

Load python attributes from strings

JSON Format
-----------

pyloader uses a JSON-serializable format for the canonical
(serializable) form of python objects::

 {'foo': # (arbitrary) object name,
  {'args': ['positional', 'arguments'],
   'kwargs': {'keyword': 'arguments},
   'path': 'dotted.or.file.path:ObjectName'},
  'bar': ... } # etc 

Objects are instantiated like::

 ObjectName(*args, **kwargs)

In the case that the object is not to be instantiated (e.g. a
standalone function, ``args`` and ``kwargs`` will either not be
present or will be None (``null`` in JSON).


INI Format
----------

pyloader also features an INI format which is translated to the JSON
Format but adds a few convenience features.  A simple object is
expressed as::

 [foo:dotted.or.file.path:ObjectName]
 . = positional, arguments
 keyword = arguments

``.`` expresses positional arguments which is a comma-separated
list. The remaining (key, value) pairs become keyword arguments. The
section name contains the object name (e.g. ``foo``) followed by a
``:`` followed by a loading path.  Like JSON, a dotted path or a file
path may be used. In addition, other (pluggable) loading paths are
available:

- override loader: you can use a section name like ``[foo:bar]`` to
  override variables from the ``bar`` object with variables from
  ``foo``::

   [foo:bar]
   . = cats, dogs
   type = count

   [bar:%(here)s/some/path.py:MyObject]
   . = elephants
   type = concatenate

  The above results in a JSON blob for foo like::

   {'foo': {'args': ['elephants', 'cats', 'dogs'],
            'kwargs': {'type': 'concatenate'},
            'path': '/location/of/ini/file/some/path.py:MyObject'}}

  ``args`` is extended. ``kwargs`` will be overridden.

- wrappers: in addition to the override pattern, you can also wrap an
  object::

   [foo:bar:baz]

  This will create an object, ``foo`` which wraps the object ``baz`` in
  by the pattern given by ``bar``.  In this case, ``bar`` is provided
  a special variable, `%(app)s`.

  You can also do::

   [foo:bar:hi,hello,x=1,y=2:%(here)/objects.py:MyClass]


In addition, .ini files may include other .ini files.  This allows for
encapsulation of intent of specific .ini files::

   [include:%(here)s/some/file.ini]

INI files have a few convenience variables:

- %(here)s : the location of the directory the .ini file lives in
- %(object)s : used for wrappers

Additional variables may be provided by the consumer.

Summary of .ini decorator syntax
--------------------------------

1. ``[foo:%(here)s/objects.py:MyClass]``: create object ``foo`` of type
   ``MyClass`` using arguments given from the section

2. ``[foo:bar]``: create object ``foo`` using the pattern from section
   ``bar`` but overriding any arguments in the ``bar`` section with
   those from this section 

3. ``[foo:bar:%(here)s/objects.py:MyClass]``: create object ``foo``
   which is an instance of ``MyClass`` wrapped in the object created by
   the ``bar`` pattern. ``bar`` is passed a special argument,
   ``%(object)s`` which is the instance of the wrapped object (the
   ``MyClass`` instance). Internally, the wrapped object is known by
   the whole section name (``foo:bar:%(here)s/objects.py:MyClass``). The 
   arguments in this section apply to ``MyClass(...)``

4. ``[foo:bar:app=%(object)s,value=1:%(here)s/objects.py:MyClass]``:
   the same as 3. but override the values in the ``bar`` section with
   ``app=%(object)s`` and ``value=1``

Section Name Syntax
-------------------

- *[name:resource]* : create an object named *name* , where resource
  is either a section name or a *path* as described in `JSON Format`_ .
  In the case where *resouce* is another section name, the options
  will overide the options given in the *resource* section and a new
  object named *name* will be created.  In the case where *section* is
  a path, an object will be created as given by the *path* with the
  given options.
- *[name:decorator:resource]* : create an object named *name* where
  the object given by *resource* is passed to *decorator*. Overrides
  and loading is as described for *[name:reource]* . An anonymous
  object is created of the whole section name for the wrapped
  object. So this form results in two sections for the `JSON Format`_ .
  *decorator* is a section in the same namespace as *name*.
- *[name:decorator:overrides:resource]* : similar to
  *[name:decorator:resource]* , but apply *overides* to the
  *decorator* section.  *overrides* is a string of the format
  ``foo,bar,fleem=5``.

----

Jeff Hammel
http://k0s.org/




            

Raw data

            {
    "_id": null,
    "home_page": "http://k0s.org/hg/pyloader",
    "name": "pyloader",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Jeff Hammel",
    "author_email": "k0scist@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/bd/ca9f114e7c5de6849d0930bc6207c5b2feaf4059efb749dda637016eedaf/pyloader-0.1.6.tar.gz",
    "platform": null,
    "description": "pyloader\n===========\n\nLoad python attributes from strings\n\nJSON Format\n-----------\n\npyloader uses a JSON-serializable format for the canonical\n(serializable) form of python objects::\n\n {'foo': # (arbitrary) object name,\n  {'args': ['positional', 'arguments'],\n   'kwargs': {'keyword': 'arguments},\n   'path': 'dotted.or.file.path:ObjectName'},\n  'bar': ... } # etc \n\nObjects are instantiated like::\n\n ObjectName(*args, **kwargs)\n\nIn the case that the object is not to be instantiated (e.g. a\nstandalone function, ``args`` and ``kwargs`` will either not be\npresent or will be None (``null`` in JSON).\n\n\nINI Format\n----------\n\npyloader also features an INI format which is translated to the JSON\nFormat but adds a few convenience features.  A simple object is\nexpressed as::\n\n [foo:dotted.or.file.path:ObjectName]\n . = positional, arguments\n keyword = arguments\n\n``.`` expresses positional arguments which is a comma-separated\nlist. The remaining (key, value) pairs become keyword arguments. The\nsection name contains the object name (e.g. ``foo``) followed by a\n``:`` followed by a loading path.  Like JSON, a dotted path or a file\npath may be used. In addition, other (pluggable) loading paths are\navailable:\n\n- override loader: you can use a section name like ``[foo:bar]`` to\n  override variables from the ``bar`` object with variables from\n  ``foo``::\n\n   [foo:bar]\n   . = cats, dogs\n   type = count\n\n   [bar:%(here)s/some/path.py:MyObject]\n   . = elephants\n   type = concatenate\n\n  The above results in a JSON blob for foo like::\n\n   {'foo': {'args': ['elephants', 'cats', 'dogs'],\n            'kwargs': {'type': 'concatenate'},\n            'path': '/location/of/ini/file/some/path.py:MyObject'}}\n\n  ``args`` is extended. ``kwargs`` will be overridden.\n\n- wrappers: in addition to the override pattern, you can also wrap an\n  object::\n\n   [foo:bar:baz]\n\n  This will create an object, ``foo`` which wraps the object ``baz`` in\n  by the pattern given by ``bar``.  In this case, ``bar`` is provided\n  a special variable, `%(app)s`.\n\n  You can also do::\n\n   [foo:bar:hi,hello,x=1,y=2:%(here)/objects.py:MyClass]\n\n\nIn addition, .ini files may include other .ini files.  This allows for\nencapsulation of intent of specific .ini files::\n\n   [include:%(here)s/some/file.ini]\n\nINI files have a few convenience variables:\n\n- %(here)s : the location of the directory the .ini file lives in\n- %(object)s : used for wrappers\n\nAdditional variables may be provided by the consumer.\n\nSummary of .ini decorator syntax\n--------------------------------\n\n1. ``[foo:%(here)s/objects.py:MyClass]``: create object ``foo`` of type\n   ``MyClass`` using arguments given from the section\n\n2. ``[foo:bar]``: create object ``foo`` using the pattern from section\n   ``bar`` but overriding any arguments in the ``bar`` section with\n   those from this section \n\n3. ``[foo:bar:%(here)s/objects.py:MyClass]``: create object ``foo``\n   which is an instance of ``MyClass`` wrapped in the object created by\n   the ``bar`` pattern. ``bar`` is passed a special argument,\n   ``%(object)s`` which is the instance of the wrapped object (the\n   ``MyClass`` instance). Internally, the wrapped object is known by\n   the whole section name (``foo:bar:%(here)s/objects.py:MyClass``). The \n   arguments in this section apply to ``MyClass(...)``\n\n4. ``[foo:bar:app=%(object)s,value=1:%(here)s/objects.py:MyClass]``:\n   the same as 3. but override the values in the ``bar`` section with\n   ``app=%(object)s`` and ``value=1``\n\nSection Name Syntax\n-------------------\n\n- *[name:resource]* : create an object named *name* , where resource\n  is either a section name or a *path* as described in `JSON Format`_ .\n  In the case where *resouce* is another section name, the options\n  will overide the options given in the *resource* section and a new\n  object named *name* will be created.  In the case where *section* is\n  a path, an object will be created as given by the *path* with the\n  given options.\n- *[name:decorator:resource]* : create an object named *name* where\n  the object given by *resource* is passed to *decorator*. Overrides\n  and loading is as described for *[name:reource]* . An anonymous\n  object is created of the whole section name for the wrapped\n  object. So this form results in two sections for the `JSON Format`_ .\n  *decorator* is a section in the same namespace as *name*.\n- *[name:decorator:overrides:resource]* : similar to\n  *[name:decorator:resource]* , but apply *overides* to the\n  *decorator* section.  *overrides* is a string of the format\n  ``foo,bar,fleem=5``.\n\n----\n\nJeff Hammel\nhttp://k0s.org/\n\n\n\n",
    "bugtrack_url": null,
    "license": "MPL",
    "summary": "Load python attributes from a string",
    "version": "0.1.6",
    "project_urls": {
        "Homepage": "http://k0s.org/hg/pyloader"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99bdca9f114e7c5de6849d0930bc6207c5b2feaf4059efb749dda637016eedaf",
                "md5": "f5f24602f1898ce0cd2cf6a2d17f93b3",
                "sha256": "21ac2ad09c4b7f4bd16a4685c5c45c2bcde6044d99700f67b0484ec844438577"
            },
            "downloads": -1,
            "filename": "pyloader-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "f5f24602f1898ce0cd2cf6a2d17f93b3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9741,
            "upload_time": "2024-05-27T23:19:43",
            "upload_time_iso_8601": "2024-05-27T23:19:43.515611Z",
            "url": "https://files.pythonhosted.org/packages/99/bd/ca9f114e7c5de6849d0930bc6207c5b2feaf4059efb749dda637016eedaf/pyloader-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-27 23:19:43",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyloader"
}
        
Elapsed time: 0.22986s