Skip to content

Commit

Permalink
Merge pull request #336 from reagento/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zhPavel authored Sep 2, 2024
2 parents 2e67d8e + a4a8fbf commit c014783
Show file tree
Hide file tree
Showing 211 changed files with 4,649 additions and 3,032 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
just-version: 1.14.0

- name: Setup environment to run tox
env:
UV_SYSTEM_PYTHON: 1
run:
just setup-runner

Expand All @@ -52,15 +54,14 @@ jobs:
fail-fast: true
matrix:
python_version:
- { setup: '3.8', tox: 'py38', cov: true }
- { setup: '3.9', tox: 'py39', cov: true }
- { setup: '3.10', tox: 'py310', cov: true }
- { setup: '3.11', tox: 'py311', cov: true }
- { setup: '3.12', tox: 'py312', cov: true }
- { setup: 'pypy3.8', tox: 'pypy38', cov: false }
- { setup: '3.12.3', tox: 'py312', cov: true } # (1)
- { setup: 'pypy3.9', tox: 'pypy39', cov: false }
- { setup: 'pypy3.10', tox: 'pypy310', cov: false }

# (1): 3.12.4 contains backwards-incompatible changes of ForwardRef._evaluate()
os: ['ubuntu-latest']

steps:
Expand All @@ -77,6 +78,8 @@ jobs:
just-version: 1.14.0

- name: Setup environment to run tox
env:
UV_SYSTEM_PYTHON: 1
run:
just setup-runner

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test_all_oses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
UV_SYSTEM_PYTHON: 1

jobs:
testing:
name: Testing (${{ matrix.python_version.tox }}, ${{ matrix.os }})
Expand All @@ -19,7 +22,6 @@ jobs:
fail-fast: false
matrix:
python_version:
- { setup: '3.8', tox: 'py38' }
- { setup: '3.9', tox: 'py39' }
- { setup: '3.10', tox: 'py310' }
- { setup: '3.11', tox: 'py311' }
Expand All @@ -44,6 +46,8 @@ jobs:
just-version: 1.14.0

- name: Setup environment to run tox
env:
UV_SYSTEM_PYTHON: 1
run:
just setup-runner

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ An extremely flexible and configurable data model conversion library.

Install
```bash
pip install adaptix==3.0.0b7
pip install adaptix==3.0.0b8
```

Use for model loading and dumping.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/bench_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def filtered_hubs(self) -> Iterable[HubDescription]:
return BENCHMARK_HUBS

def filtered_envs(self) -> Iterable[EnvDescription]:
if self.env_include:
if self.env_include and self.env_exclude:
wild_envs = set(self.env_exclude) - {env_description.key for env_description in BENCHMARK_ENVS}
if wild_envs:
raise ValueError(f"Unknown envs {wild_envs}")
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmarks/pybench/bench_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from typing import Any, Callable, Iterable
from typing import Any


@dataclass
Expand Down
17 changes: 9 additions & 8 deletions benchmarks/benchmarks/pybench/director_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import subprocess
import sys
from argparse import ArgumentParser, Namespace
from collections.abc import Iterable, Mapping, Sequence
from copy import copy
from dataclasses import dataclass
from functools import cached_property
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
from typing import Any, Callable, Optional, TypeVar, Union

import pyperf
from pyperf._cli import format_checks
Expand Down Expand Up @@ -51,7 +52,7 @@ class BenchSchema:
@dataclass(frozen=True)
class PlotParams:
title: str
fig_size: Tuple[float, float] = (8, 4.8)
fig_size: tuple[float, float] = (8, 4.8)
label_padding: float = 0
trim_after: Optional[float] = None
label_format: str = ".1f"
Expand All @@ -73,7 +74,7 @@ def __init__(
self.data_dir = data_dir
self.env_spec = env_spec
self.all_schemas = schemas
self.id_to_schema: Dict[str, BenchSchema] = {self.get_id(schema): schema for schema in schemas}
self.id_to_schema: dict[str, BenchSchema] = {self.get_id(schema): schema for schema in schemas}
self._base_check_params = check_params

def add_arguments(self, parser: ArgumentParser) -> None:
Expand Down Expand Up @@ -183,7 +184,7 @@ def get_warnings(self, schema: BenchSchema) -> Optional[Sequence[str]]:
return [*warnings, *self_warnings]

def _check_yourself(self, schema: BenchSchema, bench: pyperf.Benchmark, check_params: CheckParams) -> Sequence[str]:
lines: List[str] = []
lines: list[str] = []
stdev = bench.stdev()
mean = bench.mean()
rate = stdev / mean
Expand Down Expand Up @@ -264,7 +265,7 @@ def run_benchmarks(
for schema in schemas
}

benchmarks_to_run: List[str]
benchmarks_to_run: list[str]
if exclude is not None:
benchmarks_to_run = [
self.accessor.get_local_id(schema)
Expand Down Expand Up @@ -331,7 +332,7 @@ def launch_benchmark(
self,
bench_name: str,
entrypoint: str,
params: List[Any],
params: list[Any],
extra_args: Iterable[str] = (),
) -> None:
subprocess.run(
Expand Down Expand Up @@ -452,7 +453,7 @@ def __init__(
self.data_dir = data_dir
self.env_spec = env_spec
self.plot_params = plot_params
self.schemas: List[BenchSchema] = list(schemas)
self.schemas: list[BenchSchema] = list(schemas)
self.check_params = check_params

def add(self, *schemas: BenchSchema) -> None:
Expand Down Expand Up @@ -538,7 +539,7 @@ def make_bench_checker(self, accessor: BenchAccessor) -> BenchChecker:
return BenchChecker(accessor)

def _validate_schemas(self, accessor: BenchAccessor):
local_id_set: Set[str] = set()
local_id_set: set[str] = set()
for schema in self.schemas:
local_id = accessor.get_local_id(schema)
if local_id in local_id_set:
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/benchmarks/pybench/parametrization.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import itertools
from typing import Any, Dict, Iterable, Iterator, Mapping, Optional, TypeVar
from collections.abc import Iterable, Iterator, Mapping
from typing import Any, Optional, TypeVar

P = TypeVar("P", bound="Parametrizer")


class Parametrizer:
def __init__(self, *, product: Optional[Mapping[str, Iterable[Any]]] = None) -> None:
self._product: Dict[str, Iterable[Any]] = {} if product is None else dict(product)
self._product: dict[str, Iterable[Any]] = {} if product is None else dict(product)

def product(self: P, variants: Mapping[str, Iterable[Any]]) -> P:
self._product.update(variants)
return self

def __iter__(self) -> Iterator[Dict[str, Any]]:
def __iter__(self) -> Iterator[dict[str, Any]]:
for case_values in itertools.product(*self._product.values()):
yield dict(zip(self._product.keys(), case_values))

Expand Down
41 changes: 41 additions & 0 deletions docs/changelog/changelog_body.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
----------------------------------------------------


.. _v3.0.0b8:

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

.. _v3.0.0b8-Features:

Features
--------

- Add new :func:`.datetime_by_timestamp` and :func:`.date_by_timestamp` provider factories. `#281 <https://github.com/reagento/adaptix/issues/281>`__
- Add :func:`.datetime_by_format` to public API. `#286 <https://github.com/reagento/adaptix/issues/286>`__
- Add :func:`.type_tools.exec_type_checking` function
to deal with cyclic references by executing ``if TYPE_CHECKING:`` constructs. `#288 <https://github.com/reagento/adaptix/issues/288>`__
- Add support for bytes inside literal, for example ``Literal[b"abc"]``. `#318 <https://github.com/reagento/adaptix/issues/318>`__
- The library shows a hint if one class is a model and the other is not.
- Traceback of ``CannotProvide`` is hidden (it is raised when loader, dumper, or converter can not be created).
It simplifies error messages to users.
You can show traceback by disabling ``hide_traceback`` parameter of ``Retort``.

.. _v3.0.0b8-Breaking Changes:

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

- Drop support of Python 3.8.
- ``TypedDictAt38Warning`` is removed.

.. _v3.0.0b8-Other:

Other
-----

- Refactor internal provider routing system. It becomes more simple and readable.
Also, internal caching is added.
This led to a 40% speedup in loader generation for medium models
and up to 4x speedup for large models with many recursive types.

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


.. _v3.0.0b7:

`3.0.0b7 <https://github.com/reagento/adaptix/tree/v3.0.0b7>`__ -- 2024-06-10
Expand Down
2 changes: 1 addition & 1 deletion docs/common/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Just use pip to install the library

.. code-block:: text
pip install adaptix==3.0.0b7
pip install adaptix==3.0.0b8
Integrations with 3-rd party libraries are turned on automatically,
Expand Down
4 changes: 2 additions & 2 deletions docs/conversion/extended-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Using default value for fields
================================

By default, all fields of the destination model must be linked to something
even field is not required (has a default value).
even if field is not required (has a default value).

.. hint::

Expand All @@ -82,7 +82,7 @@ via :func:`.conversion.allow_unlinked_optional` and :func:`.conversion.forbid_un

.. literalinclude:: /examples/conversion/extended_usage/using_default_value_for_fields.py

Each parameter of these functions are predicate defining the target scope of the policy.
Each parameter of these functions is predicate defining the target scope of the policy.
You can use them without arguments to apply new policies to all fields.

.. dropdown:: Redefine policy globally (for all fields)
Expand Down
2 changes: 1 addition & 1 deletion docs/conversion/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Also, it works for nested models.
.. literalinclude:: /examples/conversion/tutorial/nested.py

Furthermore, there is :func:`.conversion.convert` that can directly convert one model to another,
but it is quite limited and can not configured, so it won't be considered onwards.
but it is quite limited and can not be configured, so it won't be considered onwards.

.. dropdown:: Usage of :func:`.conversion.convert`

Expand Down
3 changes: 1 addition & 2 deletions docs/custom_ext/bench_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from typing import Dict
from zipfile import ZipFile

import plotly
Expand Down Expand Up @@ -45,7 +44,7 @@ class CustomBenchUsedDistributions(SphinxMacroDirective):
required_arguments = 0

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

for hub_description in BENCHMARK_HUBS:
with ZipFile(RELEASE_DATA / f"{hub_description.key}.zip") as release_zip:
Expand Down
2 changes: 1 addition & 1 deletion docs/custom_ext/macros.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tomllib
from abc import ABC, abstractmethod
from collections.abc import Iterable
from pathlib import Path
from textwrap import dedent, indent
from typing import Iterable

from docutils.statemachine import StringList
from sphinx.util import docutils
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/benchmarks/gh_issues_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import List, Optional
from typing import Optional


class IssueState(str, Enum):
Expand Down Expand Up @@ -100,9 +100,9 @@ class Issue:
state_reason: Optional[StateReason]
title: str
user: Optional[SimpleUser]
labels: List[Label]
labels: list[Label]
assignee: Optional[SimpleUser]
assignees: Optional[List[SimpleUser]]
assignees: Optional[list[SimpleUser]]
locked: bool
active_lock_reason: Optional[str]
comments: int
Expand All @@ -120,4 +120,4 @@ class Issue:

@dataclass
class GetRepoIssuesResponse:
data: List[Issue]
data: list[Issue]
3 changes: 1 addition & 2 deletions docs/examples/benchmarks/simple_structures_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import List


@dataclass
Expand All @@ -14,4 +13,4 @@ class Review:
class Book:
id: int
name: str
reviews: List[Review] # contains 100 items
reviews: list[Review] # contains 100 items
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List, Optional
from typing import Optional

from adaptix.conversion import allow_unlinked_optional, get_converter

Expand All @@ -17,7 +17,7 @@ class BookDTO:
price: int
author: str
collection_id: Optional[int] = None
bookmarks_ids: List[str] = field(default_factory=list)
bookmarks_ids: list[str] = field(default_factory=list)


convert_book_to_dto = get_converter(
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/conversion/extended_usage/link_constant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import Optional

from adaptix import P
from adaptix.conversion import get_converter, link_constant
Expand All @@ -18,7 +18,7 @@ class BookDTO:
price: int
author: str
collection_id: Optional[int]
bookmarks_ids: List[str]
bookmarks_ids: list[str]


convert_book_to_dto = get_converter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from typing import Iterable, List, Sequence

from adaptix import P, Retort, name_mapping

Expand All @@ -9,9 +9,9 @@
class Document:
key: str

redirects: List[str]
edition_keys: List[str]
lcc_list: List[str]
redirects: list[str]
edition_keys: list[str]
lcc_list: list[str]


def create_plural_stripper(
Expand Down
Loading

0 comments on commit c014783

Please sign in to comment.