Skip to content

Commit

Permalink
Merge pull request #273 from reagento/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zhPavel committed Apr 20, 2024
2 parents eb05902 + 700986f commit 6084abe
Show file tree
Hide file tree
Showing 100 changed files with 2,698 additions and 634 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
just setup-runner

- name: Run tests with coverage
if: ${{ matrix.python_version.cov }}
if: ${{ (matrix.python_version.cov && github.event_name == 'pull_request') }}
run:
just inv test-on-ci
--py-target ${{ matrix.python_version.tox }}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/reagento/adaptix/blob/v3.0.0b4/docs/logo/adaptix-with-title-dark.png?raw=true">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/reagento/adaptix/blob/v3.0.0b4/docs/logo/adaptix-with-title-light.png?raw=true">
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/reagento/adaptix/blob/v3.0.0b5/docs/logo/adaptix-with-title-dark.png?raw=true">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/reagento/adaptix/blob/v3.0.0b5/docs/logo/adaptix-with-title-light.png?raw=true">
<img alt="adaptix logo" src="https://raw.githubusercontent.com/reagento/adaptix/v3.0.0b2/docs/logo/adaptix-with-title-light.png?raw=true">
</picture>

Expand All @@ -25,7 +25,7 @@ An extremely flexible and configurable data model conversion library.

Install
```bash
pip install adaptix==3.0.0b4
pip install adaptix==3.0.0b5
```

Use for model loading and dumping.
Expand Down Expand Up @@ -114,7 +114,7 @@ assert (
* Support [dozens](https://adaptix.readthedocs.io/en/latest/loading-and-dumping/specific-types-behavior.html) of types,
including different model kinds:
``@dataclass``, ``TypedDict``, ``NamedTuple``,
[``attrs``](https://www.attrs.org/en/stable/) and [``sqlalchemy``](https://docs.sqlalchemy.org/en/20/)
[``attrs``](https://www.attrs.org/en/stable/), [``sqlalchemy``](https://docs.sqlalchemy.org/en/20/) and [``pydantic``](https://docs.pydantic.dev/latest/).
* Working with self-referenced data types (such as linked lists or trees).
* Saving [path](https://adaptix.readthedocs.io/en/latest/loading-and-dumping/tutorial.html#error-handling)
where an exception is raised (including unexpected errors).
Expand Down
75 changes: 54 additions & 21 deletions docs/changelog/changelog_body.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
----------------------------------------------------


.. _v3.0.0b5:

`3.0.0b5 <https://github.com/reagento/adaptix/tree/v3.0.0b5>`__ -- 2024-04-20
=============================================================================

.. _v3.0.0b5-Features:

Features
--------

- Add support for Pydantic models!

Now you can work with pydantic models like any other:
construct from dict, serialize to dict, convert to any other model, and convert it to any other model.

Also, you can use :func:`.integrations.pydantic.native_pydantic` to delegate loading and dumping to pydantic itself.

- Add support for dumping ``Literal`` inside ``Union``. `#237 <https://github.com/reagento/adaptix/issues/237>`__
- Add support for ``BytesIO`` and ``IO[bytes]``. `#270 <https://github.com/reagento/adaptix/issues/270>`__
- Error messages are more obvious.

.. _v3.0.0b5-Breaking Changes:

Breaking Changes
----------------

- Forbid use of constructs like ``P[SomeClass].ANY`` because it is misleading (you have to use ``P.ANY`` directly).
- Private fields (any field starting with underscore) are skipped at dumping.
See :ref:`private_fields_dumping` for details.

----------------------------------------------------


.. _v3.0.0b4:

`3.0.0b4 <https://github.com/reagento/adaptix/tree/v3.0.0b4>`_ -- 2024-03-30
============================================================================
`3.0.0b4 <https://github.com/reagento/adaptix/tree/v3.0.0b4>`__ -- 2024-03-30
=============================================================================

.. _v3.0.0b4-Features:

Expand Down Expand Up @@ -43,36 +76,36 @@ Bug Fixes

.. _v3.0.0b3:

`3.0.0b3 <https://github.com/reagento/adaptix/tree/v3.0.0b3>`_ -- 2024-03-08
============================================================================
`3.0.0b3 <https://github.com/reagento/adaptix/tree/v3.0.0b3>`__ -- 2024-03-08
=============================================================================

.. _v3.0.0b3-Features:

Features
--------

- :func:`.conversion.link` accepts ``coercer`` parameter. `#256 <https://github.com/reagento/adaptix/issues/256>`_
- Add :func:`.conversion.link_constant` to link constant values and constant factories. `#258 <https://github.com/reagento/adaptix/issues/258>`_
- Add coercer for case when source union is subset of destination union (simple ``==`` check is using). `#242 <https://github.com/reagento/adaptix/issues/242>`_
- No coercer error now contains type information. `#252 <https://github.com/reagento/adaptix/issues/252>`_
- :func:`.conversion.link` accepts ``coercer`` parameter. `#256 <https://github.com/reagento/adaptix/issues/256>`__
- Add :func:`.conversion.link_constant` to link constant values and constant factories. `#258 <https://github.com/reagento/adaptix/issues/258>`__
- Add coercer for case when source union is subset of destination union (simple ``==`` check is using). `#242 <https://github.com/reagento/adaptix/issues/242>`__
- No coercer error now contains type information. `#252 <https://github.com/reagento/adaptix/issues/252>`__
- Add coercer for ``Optional[S] -> Optional[D]`` if ``S`` is coercible to ``D``. `#254 <https://github.com/reagento/adaptix/issues/254>`_

.. _v3.0.0b3-Bug Fixes:

Bug Fixes
---------

- Fix ``SyntaxError`` with lambda in :func:`.coercer`. `#243 <https://github.com/reagento/adaptix/issues/243>`_
- Model dumping now trying to save the original order of fields inside the dict. `#247 <https://github.com/reagento/adaptix/issues/247>`_
- Fix introspection of sqlalchemy models with ``column_property`` (all ColumnElement is ignored excepting Column itself). `#250 <https://github.com/reagento/adaptix/issues/250>`_
- Fix ``SyntaxError`` with lambda in :func:`.coercer`. `#243 <https://github.com/reagento/adaptix/issues/243>`__
- Model dumping now trying to save the original order of fields inside the dict. `#247 <https://github.com/reagento/adaptix/issues/247>`__
- Fix introspection of sqlalchemy models with ``column_property`` (all ColumnElement is ignored excepting Column itself). `#250 <https://github.com/reagento/adaptix/issues/250>`__

----------------------------------------------------


.. _v3.0.0b2:

`3.0.0b2 <https://github.com/reagento/adaptix/tree/v3.0.0b2>`_ -- 2024-02-16
============================================================================
`3.0.0b2 <https://github.com/reagento/adaptix/tree/v3.0.0b2>`__ -- 2024-02-16
=============================================================================

.. _v3.0.0b2-Features:

Expand All @@ -84,15 +117,15 @@ Features
Now, you can generate boilerplate converter function by adaptix.
See :ref:`conversion tutorial <conversion-tutorial>` for details.
- Basic support for sqlalchemy models are added!
- Added enum support inside Literal. `#178 <https://github.com/reagento/adaptix/issues/178>`_
- Added enum support inside Literal. `#178 <https://github.com/reagento/adaptix/issues/178>`__
- Added flags support.

Now adaptix has two different ways to process flags: :func:`.flag_by_exact_value` (by default)
and :func:`.flag_by_member_names`. `#197 <https://github.com/reagento/adaptix/issues/197>`_
- Added defaultdict support. `#216 <https://github.com/reagento/adaptix/issues/216>`_
- Added support of mapping for :func:`.enum_by_name` provider. `#223 <https://github.com/reagento/adaptix/issues/223>`_
and :func:`.flag_by_member_names`. `#197 <https://github.com/reagento/adaptix/issues/197>`__
- Added defaultdict support. `#216 <https://github.com/reagento/adaptix/issues/216>`__
- Added support of mapping for :func:`.enum_by_name` provider. `#223 <https://github.com/reagento/adaptix/issues/223>`__
- Created the correct path (fixing python bug) for processing ``Required`` and ``NotRequired`` with stringified annotations
or ``from __future__ import annotations``. `#227 <https://github.com/reagento/adaptix/issues/227>`_
or ``from __future__ import annotations``. `#227 <https://github.com/reagento/adaptix/issues/227>`__

.. _v3.0.0b2-Breaking Changes:

Expand Down Expand Up @@ -139,14 +172,14 @@ Deprecations
Bug Fixes
---------

- Fixed parameter shuffling on skipping optional field. `#229 <https://github.com/reagento/adaptix/issues/229>`_
- Fixed parameter shuffling on skipping optional field. `#229 <https://github.com/reagento/adaptix/issues/229>`__

----------------------------------------------------


.. _v3.0.0b1:

`3.0.0b1 <https://github.com/reagento/adaptix/tree/v3.0.0b1>`_ -- 2023-12-16
============================================================================
`3.0.0b1 <https://github.com/reagento/adaptix/tree/v3.0.0b1>`__ -- 2023-12-16
=============================================================================

Start of changelog.
4 changes: 2 additions & 2 deletions docs/changelog/template.rst.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

.. _v{{ versiondata.version }}:

`{{ versiondata.version }} <https://github.com/reagento/adaptix/tree/v{{ versiondata.version }}>`_ -- {{ versiondata.date }}
{{ top_underline * ((versiondata.version * 2 + versiondata.date)|length + 52) }}
`{{ versiondata.version }} <https://github.com/reagento/adaptix/tree/v{{ versiondata.version }}>`__ -- {{ versiondata.date }}
{{ top_underline * ((versiondata.version * 2 + versiondata.date)|length + 53) }}
{% endif %}
{% for section, _ in sections.items() %}
{% set underline = underlines[0] %}{% if section %}{{section}}
Expand Down
23 changes: 5 additions & 18 deletions docs/common/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,23 @@ Just use pip to install the library

.. code-block:: text
pip install adaptix==3.0.0b4
pip install adaptix==3.0.0b5
Integrations with 3-rd party libraries are turned on automatically,
but you can install adaptix with `extras <https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras>`_
but you can install adaptix with `extras <https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras>`__
to check that versions are compatible.

There are two variants of extras. The first one checks that the version is the same or newer than the last supported,
the second (strict) additionally checks that the version same or older than the last tested version.

.. list-table::
:header-rows: 1

* - Extras
- Versions bound
* - ``attrs``
- ``attrs >= 21.3.0``
* - ``attrs-strict``
- ``attrs >= 21.3.0, <= 23.2.0``
* - ``sqlalchemy``
- ``sqlalchemy >= 2.0.0``
* - ``sqlalchemy-strict``
- ``sqlalchemy >= 2.0.0, <= 2.0.29``

.. custom-adaptix-extras-table::

Extras are specified inside square brackets, separating by comma.

So, this is valid installation variants:

.. code-block:: text
pip install adaptix[attrs-strict]==3.0.0b4
pip install adaptix[attrs, sqlalchemy-strict]==3.0.0b4
pip install adaptix[attrs-strict]==3.0.0b5
pip install adaptix[attrs, sqlalchemy-strict]==3.0.0b5
2 changes: 1 addition & 1 deletion docs/conversion/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Sometimes you need to add extra data to the source model. For this, you can use

``# mypy: disable-error-code="empty-body"`` on the top of the file is needed
because mypy forbids functions without body.
Also, you can set this option at `mypy config <https://mypy.readthedocs.io/en/stable/config_file.html#example-mypy-ini>`_
Also, you can set this option at `mypy config <https://mypy.readthedocs.io/en/stable/config_file.html#example-mypy-ini>`__
or supress each error individually via ``# type: ignore[empty-body]``.

.. _fields-linking:
Expand Down
33 changes: 11 additions & 22 deletions docs/custom_ext/bench_tools.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import json
from textwrap import dedent
from typing import Dict
from zipfile import ZipFile

import plotly
from docutils import nodes
from docutils.statemachine import StringList
from sphinx.util import docutils
from sphinx.util.docutils import SphinxDirective

from benchmarks.bench_nexus import BENCHMARK_HUBS, KEY_TO_HUB, RELEASE_DATA, Renderer, pyperf_bench_to_measure

from .macros import SphinxMacroDirective, directive
from .utils import file_ascii_hash


Expand Down Expand Up @@ -43,10 +41,10 @@ def run(self):
]


class CustomBenchUsedDistributions(SphinxDirective):
class CustomBenchUsedDistributions(SphinxMacroDirective):
required_arguments = 0

def get_list_table(self) -> str:
def generate_string(self) -> str:
distributions: Dict[str, str] = {}

for hub_description in BENCHMARK_HUBS:
Expand All @@ -58,7 +56,7 @@ def get_list_table(self) -> str:
pyperf_bench_to_measure(release_zip.read(file)).distributions,
)

result = dedent(
return directive(
"""
.. list-table::
:header-rows: 1
Expand All @@ -67,29 +65,20 @@ def get_list_table(self) -> str:
- Used version
- Last version
""",
)
for dist in sorted(distributions.keys()):
version = distributions[dist]
result += dedent(
[
f"""
* - `{dist} <https://pypi.org/project/{dist}/>`_
- ``{version}``
* - `{dist} <https://pypi.org/project/{dist}/>`__
- ``{distributions[dist]}``
- .. image:: https://img.shields.io/pypi/v/{dist}?logo=pypi&label=%20&color=white&style=flat
:target: https://pypi.org/project/{dist}/
:class: only-light
.. image:: https://img.shields.io/pypi/v/{dist}?logo=pypi&label=%20&color=%23242424&style=flat
:target: https://pypi.org/project/{dist}/
:class: only-dark
""",
).replace("\n", "\n ")
return result

def run(self):
list_table = self.get_list_table()
rst = StringList(list_table.split("\n"), source="fake.rst")
node = docutils.nodes.paragraph()
self.state.nested_parse(rst, 0, node)
return node.children
"""
for dist in sorted(distributions.keys())
],
)


def setup(app):
Expand Down
48 changes: 40 additions & 8 deletions docs/custom_ext/macros.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import tomllib
from abc import ABC, abstractmethod
from pathlib import Path
from textwrap import dedent, indent
from typing import Iterable

from docutils.statemachine import StringList
from sphinx.util import docutils
Expand All @@ -21,27 +24,56 @@ def run(self):
return node.children


def directive(header: str, contents: Iterable[str] = ()) -> str:
return dedent(header) + "\n" + "\n".join(indent(dedent(content), " ") for content in contents)


class CustomNonGuaranteedBehavior(SphinxMacroDirective):
required_arguments = 0
has_content = True

def generate_string(self) -> str:
result = dedent(
return directive(
"""
.. admonition:: Non-guaranteed behavior
:class: caution
.. admonition:: Non-guaranteed behavior
:class: caution
""",
self.content,
)
content = indent(
"\n".join(self.content),
" ",


ADAPTIX_PYPROJECT = tomllib.loads(Path(__file__).parent.parent.parent.joinpath("pyproject.toml").read_text())


class CustomAdaptixExtrasTable(SphinxMacroDirective):
required_arguments = 0
has_content = False

def generate_string(self) -> str:
return directive(
"""
.. list-table::
:header-rows: 1
""",
[
"""
* - Extras
- Versions bound
""",
*[
f"""
* - ``{extras}``
- ``{'; '.join(deps)}``
"""
for extras, deps in ADAPTIX_PYPROJECT["project"]["optional-dependencies"].items()
],
],
)
return result + content


def setup(app):
app.add_directive("custom-non-guaranteed-behavior", CustomNonGuaranteedBehavior)
app.add_directive("custom-adaptix-extras-table", CustomAdaptixExtrasTable)

return {
"version": file_ascii_hash(__file__),
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/conversion/tutorial/putting_together.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from uuid import UUID

from adaptix import P
from adaptix._internal.conversion.facade.provider import from_param
from adaptix.conversion import coercer, impl_converter, link
from adaptix.conversion import coercer, from_param, impl_converter, link


@dataclass
Expand Down
Loading

0 comments on commit 6084abe

Please sign in to comment.