<commit_before>"""
CommCare Extensions
===================

This package provides the utilities to register extension points and their implementations
and to call retrieve the results from all the registered implementations.

Create and extension point
--------------------------

::

    from corehq import extensions

    @extensions.extension_point
    def get_things(arg1: int, keyword: bool = False) -> List[str]:
        '''Docs for the extension point'''


Registering an extension point implementation
---------------------------------------------

::

    from xyz import get_things

    @get_things.extend()
    def some_things(arg1, keyword=False):
        return ["thing2", "thing1"]


Extensions may also be limited to specific domains by passing the list
of domains as a keyword argument (it must be a keyword argument).

::

    from xyz import get_things

    @get_things.extend(domains=["cat", "hat"])
    def custom_domain_things(arg1, keyword=False):
        return ["thing3", "thing4"]


Calling an extension point
--------------------------
An extension point is called as a normal function. Results are
returned as a list with any `None` values removed.

::

    from xyz import get_things

    results = get_things(10, True)
"""
from corehq.extensions.interface import CommCareExtensions

extension_manager = CommCareExtensions()
extension_point = extension_manager.extension_point
<commit_msg>more docs<commit_after>"""
CommCare Extensions
===================

This document describes the mechanisms that can be used to extend CommCare's functionality. There are a number
of legacy mechanisms that are used which are not described in this document. This document will focus on
the use of pre-defined *extension points* to add functionality to CommCare.

Where to put custom code
------------------------
The custom code for extending CommCare may be part of the main `commcare-hq` repository or it may have its own
repository. In the case where it is in a separate repository the code may be 'added' to CommCare by cloning the
custom repository into the `extensions` folder in the root of the CommCare source:

::

    /commcare-hq
      /corehq
      /custom
      ...
      /extensions
        /custom_repo
          /custom
            /app1/models.py
            /app2/models.py

The code in the custom repository must be contained within the `custom` namespace package (without an
`__init__.py` file). Using this structure the custom code will be available to CommCare with the same package
structure as it is in the custom repository. In the example above the following import statement will work
in CommCare as well as in the custom code:

::

    from custom.app1 models import *

Extensions Points
-----------------
The `corehq/extensions` package provides the utilities to register extension points and their implementations
and to call retrieve the results from all the registered implementations.

Create and extension point
~~~~~~~~~~~~~~~~~~~~~~~~~~

::

    from corehq import extensions

    @extensions.extension_point
    def get_things(arg1: int, keyword: bool = False) -> List[str]:
        '''Docs for the extension point'''


Registering an extension point implementation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

    from xyz import get_things

    @get_things.extend()
    def some_things(arg1, keyword=False):
        return ["thing2", "thing1"]


Extensions may also be limited to specific domains by passing the list
of domains as a keyword argument (it must be a keyword argument).

::

    from xyz import get_things

    @get_things.extend(domains=["cat", "hat"])
    def custom_domain_things(arg1, keyword=False):
        return ["thing3", "thing4"]


Calling an extension point
~~~~~~~~~~~~~~~~~~~~~~~~~~
An extension point is called as a normal function. Results are
returned as a list with any `None` values removed.

::

    from xyz import get_things

    results = get_things(10, True)
"""

from corehq.extensions.interface import CommCareExtensions

extension_manager = CommCareExtensions()
extension_point = extension_manager.extension_point

{'fraction_non_alphanumeric': 0.12493923189110355, 'fraction_numerical': 0.005104521147301896, 'mean_word_length': 3.382321618743344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7123371', 'n_tokens_mistral': 1075, 'n_tokens_neox': 994, 'n_words': 457}