Skip to content

Commit

Permalink
Update more of the documentation for Asphalt 5
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 22, 2024
1 parent e234c96 commit dd3fcc3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 73 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx_autodoc_typehints",
"sphinx_rtd_theme",
]

templates_path = ["_templates"]
Expand Down
40 changes: 7 additions & 33 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,19 @@ any necessary configuration values for it. The following backends are provided o

Other backends may be provided by other components.

Once you've selected a backend, see its specific documentation to find out what configuration
values you need to provide, if any. Configuration values are expressed as constructor arguments
for the backend class::
Once you've selected a backend, see its specific documentation to find out what
configuration values you need to provide, if any. Configuration values are expressed as
constructor arguments for the backend class::

components:
serialization:
backend: json

This configuration publishes a :class:`~.api.Serializer` resource named
``default`` using the JSON backend. The same can be done directly in Python code as
follows:
This configuration publishes a :class:`~Serializer` resource named ``default`` using the
JSON backend. The same can be done directly in Python code as follows:

.. code-block:: python
class ApplicationComponent(ContainerComponent):
async def start(ctx: Context) -> None:
class ApplicationComponent(Component):
def __init__(self) -> None:
self.add_component('serialization', backend='json')
await super().start()
Multiple serializers
--------------------

If you need to configure multiple serializers, you will need to use multiple instances
of the serialization component::

components:
serialization:
backend: cbor
serialization/msgpack:
resource_name: msgpack
backend: msgpack

The above configuration creates two serializer resources, available under 6 different
combinations:

* :class:`~.api.Serializer` / ``default``
* :class:`~.api.CustomizableSerializer` / ``default``
* :class:`~.serializers.cbor.CBORSerializer` / ``default``
* :class:`~.api.Serializer` / ``msgpack``
* :class:`~.api.CustomizableSerializer` / ``msgpack``
* :class:`~.serializers.msgpack.MsgpackSerializer` / ``msgpack``
46 changes: 21 additions & 25 deletions docs/extending.rst
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
Writing new serializer backends
===============================

If you wish to implement an alternate method of serialization, you can do so by subclassing
the :class:`~asphalt.serialization.api.Serializer` class.
There are three methods implementors must override:
.. py:currentmodule:: asphalt.serialization
* :meth:`~asphalt.serialization.api.Serializer.serialize`
* :meth:`~asphalt.serialization.api.Serializer.deserialize`
* :meth:`~asphalt.serialization.api.Serializer.mimetype`
If you wish to implement an alternate method of serialization, you can do so by
subclassing the :class:`~Serializer` class. There are three methods implementors must
override:

The ``mimetype`` method is a ``@property`` that simply returns the MIME type appropriate for the
serialization scheme. This property is used by certain other components. If you cannot find an
applicable MIME type, you can use ``application/octet-stream``.
* :meth:`~Serializer.serialize`
* :meth:`~Serializer.deserialize`
* :meth:`~Serializer.mimetype`

The ``mimetype`` method is a ``@property`` that simply returns the MIME type appropriate
for the serialization scheme. This property is used by certain other components. If you
cannot find an applicable MIME type, you can use ``application/octet-stream``.

.. note:: Serializers must always serialize to bytes; never serialize to strings!

If you want your serializer to be available as a backend for
:class:`~asphalt.serialization.component.SerializationComponent`, you need to add the corresponding
entry point for it. Suppose your serializer class is named ``AwesomeSerializer``, lives in the
package ``foo.bar.awesome`` and you want to give it the alias ``awesome``, add this line to your
project's ``setup.py`` under the ``entry_points`` argument in the
``asphalt.serialization.serializers`` namespace:

.. code-block:: python
setup(
# (...other arguments...)
entry_points={
'asphalt.serialization.serializers': [
'awesome = foo.bar.awesome:AwesomeSerializer'
]
}
)
:class:`~asphalt.serialization.SerializationComponent`, you need to add the
corresponding entry point for it. Suppose your serializer class is named
``AwesomeSerializer``, lives in the package ``foo.bar.awesome`` and you want to give it
the alias ``awesome``, add this line to your project's ``pyproject.toml`` under the
``entry_points`` argument in the ``asphalt.serialization.serializers`` namespace:

.. code-block:: toml
[project.entry-points."asphalt.serialization.serializers"]
awesome = "foo.bar.awesome:AwesomeSerializer"
5 changes: 3 additions & 2 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Version history
===============

This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
This library adheres to `Semantic Versioning 2.0 <https://semver.org/>`_.

**UNRELEASED**

- Dropped support for Python 3.7
- Dropped support for Python 3.7 and 3.8
- **BACKWARD INCOMPATIBLE** Bumped minimum Asphalt version to 5.0

**6.0.0** (2022-06-04)

Expand Down
26 changes: 13 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ addopts = "-rsx --tb=short"
testpaths = ["tests"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
strict = true
explicit_package_bases = true

Expand All @@ -96,18 +96,18 @@ branch = true
show_missing = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38, py39, py310, py311, py312, py313, pypy3
env_list = ["py39", "py310", "py311", "py312", "py313", "pypy3"]
skip_missing_interpreters = true
minversion = 4.4.3

[testenv]
extras = test
commands = python -m pytest {posargs}
package = editable
[tool.tox.env_run_base]
commands = [["python", "-m", "pytest", { replace = "posargs", extend = true }]]
package = "editable"
extras = ["test"]

[testenv:docs]
extras = doc
commands = sphinx-build -n docs build/sphinx
"""
[tool.tox.env.pyright]
deps = ["pyright"]
commands = [["pyright", "--verifytypes", "asphalt.exceptions"]]

[tool.tox.env.docs]
commands = [["sphinx-build", "-W", "-n", "docs", "build/sphinx", { replace = "posargs", extend = true }]]
extras = ["doc"]

0 comments on commit dd3fcc3

Please sign in to comment.