@@ -6,10 +6,10 @@ Extensions
66Available Extensions
77====================
88
9- pyApp.org Supplied
10- ------------------
9+ pyApp Developed
10+ ---------------
1111
12- These are extensions supplied by ` pyApp `.
12+ Extensions available for use:
1313
1414- `pyapp.aiobotocore <https://github.com/pyapp-org/pyapp.aiobotocore >`_ -
1515 Factory for `Async AWS client library <https://github.com/aio-libs/aiobotocore >`_
@@ -21,12 +21,147 @@ These are extensions supplied by `pyApp`.
2121 Factory for `SQLALchemy <https://www.sqlalchemy.org >`_
2222
2323
24- These extensions are in development.
24+ Extensions in beta:
2525
2626- `pyapp-messaging <https://github.com/pyapp-org/pyapp-messaging >`_ -
2727 Abstract messaging framework for interacting with Pub/Sub and Message Queues.
2828
29+ Extensions in development:
30+
2931- `pyapp.boto3 <https://github.com/pyapp-org/pyapp.boto3 >`_ -
3032 Factory for `AWS client library <https://boto3.amazonaws.com/v1/documentation/api/latest/index.html >`_
3133- `pyapp.smtp <https://github.com/pyapp-org/pyapp.SMTP >`_ -
3234 Interface to `smtplib <https://docs.python.org/3/library/smtplib.html >`_
35+
36+ .. note ::
37+ The development status of these projects may have changed from when this
38+ documentation was generated, see the repository (or PyPi) of the extension
39+ package for up to date status.
40+
41+ Developing an Extension
42+ =======================
43+
44+ An extension is a standard Python package that exports a known entry point that
45+ pyApp uses to identify extensions. This entry point will reference a class with
46+ known attributes that pyApp recognises.
47+
48+ A Basic Project
49+ ---------------
50+
51+ An extensions consists of a standard Python project structure eg::
52+
53+ ├┬ my_extension
54+ │├ __init__.py
55+ │└ __version__.py
56+ ├ README.rst
57+ ├ setup.cfg
58+ └ setup.py
59+
60+
61+ The contents of which are:
62+
63+ ``my_extension/__init__.py ``
64+ The package init file, this file contains the extension entry point. While a
65+ package must container an Extension class every attribute on the class is optional.
66+
67+ .. code-block :: python
68+
69+ # Pull in the version
70+ from .__version__ import __version__
71+
72+
73+ class Extension :
74+ """
75+ My pyApp Extension
76+ """
77+
78+ default_settings = " .default_settings"
79+ checks = " .checks"
80+
81+ @ staticmethod
82+ def register_commands (root ):
83+ """
84+ Register custom commands with pyApp.
85+ """
86+
87+ @ staticmethod
88+ def ready ():
89+ """
90+ Method called once pyApp has configured environment
91+ """
92+
93+
94+ ``my_extension/__version__.py ``
95+ The package version; defining the version in a separate file simplifies the
96+ process of obtaining the version during the package build process.
97+
98+ .. code-block :: python
99+
100+ __version__ = " 1.0"
101+
102+
103+ ``README.rst ``
104+ While not strictly necessary a README document is *highly recommended * and is
105+ included in the package as the long description.
106+
107+ .. code-block :: rst
108+
109+ ##################
110+ My pyApp Extension
111+ ##################
112+
113+ Information about my extension
114+
115+
116+ ``setup.cfg ``
117+ Defines the metadata and configuration used to build a package, this is also
118+ where the entry point used identify you extension is defined.
119+
120+ .. code-block :: ini
121+
122+ [metadata]
123+ name = my-extension
124+ author = Author
125+ 126+ description = Blurb about my extension
127+ long-description = file: README.rst
128+ url = https://github.com/author/my-extension
129+ platforms = any
130+ license = BSD-3-Clause
131+
132+ [options]
133+ python_requires = >=3.6
134+ packages = find:
135+ setup_requires =
136+ setuptools >=38.3
137+ install_requires =
138+ pyapp >=4.3.0
139+
140+ [options.entry_points]
141+ # Used by pyApp to recognise my_extension
142+ pyapp.extensions =
143+ my-extension = my_extension:Extension
144+
145+
146+ ``setup.py ``
147+ Script that trigger ``setuptools `` to build a package. This example takes
148+ advantage of the version in a separate file to extract the version number.
149+
150+ .. code-block :: python
151+
152+ from pathlib import Path
153+ from setuptools import setup
154+
155+ HERE = Path(__file__ ).parent
156+
157+ about = {}
158+ with (HERE / " my_extension/__version__.py" ).open() as f:
159+ exec (f.read(), about)
160+
161+ setup(version = about[" __version__" ])
162+
163+
164+ .. tip ::
165+ A gotcha when building extensions is attempting to access settings to early
166+ this is the reason for the ``ready `` event on the Extension class. Once ready
167+ has been called settings are setup and ready for use.
0 commit comments