Metadata-Version: 2.1
Name: xmod
Version: 1.0.1
Summary: Create and recursively fill a temporary directory
Home-page: https://github.com/rec/xmod
Author: Tom Ritchford
Author-email: tom@swirly.com
License: MIT
Keywords: testing,modules
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Dist: dek

🌱 - xmod: Extend a module with any Python object - 🌱
=========================================================================

Give your module the awesome power of an object, or maybe just save a
little typing, with ``xmod``.

Ever wanted to call a module directly, or index it?
Or just sick of seeing ``from foo import foo`` in your examples?

``xmod`` is a tiny library that solves both these issues in one line of code,
by extending a module with the methods and members of a Python object.

This is extremely handy for modules that primarily do one thing.

EXAMPLE: Make a module callable like a function

.. code-block:: python

    # In your_module.py
    import xmod

    A_CONSTANT = 23

    @xmod
    def a_function(*args, **kwargs):
        print('a function!')
        return args, kwargs


    # Test at the command line
    >>> import your_module

    >>> your_module(2, 3, a=5)
    a function!
    (2, 3), {'a': 5}

    >>> assert your_module.A_CONSTANT == 23

EXAMPLE: Make a module look like an object

.. code-block:: python

    # In your_module.py
    import xmod

    A_CONSTANT = 23

    xmod(list(), __name__)

    # Test at the command line
    >>> import your_module

    >>> assert your_module == [] and your_module.A_CONSTANT == 23

    >>> your_module.extend(range(3))

    >>> print(your_module)
    [0, 1, 2]

API
---

``xmod.xmod(extension=None, name=None, properties=None, omit=None)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(`xmod.py, 95-180 <https://github.com/rec/xmod/blob/master/xmod.py#L95-L180>`_)

Extend the system module at ``name`` with any Python object.

The original module is replaced in ``sys.modules`` by a proxy class
which delegates attributes, first to the extension, and then to the
original module.

``xmod`` can also be used as a decorator, both with and without
parameters.

ARGUMENTS
  extension
    The object whose methods and properties extend the namespace.
    This includes magic methods like __call__ and __getitem__.

  name
    The name of this symbol in ``sys.modules``.  If this is ``None``
    then ``xmod`` will use ``extension.__module__``.

    This only needs to be be set if ``extension`` is _not_ a function or
    class defined in the module that's being extended.

    If the ``name`` argument is given, it should almost certainly be
    ``__name__``.

  properties
    There is little need to use this argument.

    Properties in this list are copied directly from the module into the
    custom class - they do not get overridden by the extension.

    If ``properties`` is None, it defaults to ``xmod.MODULE_PROPERTIES``
    which seems to work well.

  omit
    There is little need to use this argument.

    A list of methods _not_ to delegate from the proxy to the extension.
    if ``omit`` is None, it defaults to ``xmod.OMIT``, which seems to work
    well.

(automatically generated by `doks <https://github.com/rec/doks/>`_ on 2020-07-18T16:31:24.145016)


