Skip to content

Schemas #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
436bb1a
Add single container prototype
rmk135 Feb 22, 2021
5121b5c
Add multiple containers prototype
rmk135 Feb 22, 2021
3c3c6de
Add integration tests
rmk135 Feb 23, 2021
73d9c97
Implement from_*() methods and add tests
rmk135 Feb 24, 2021
b882c7c
Prototype inline injections
rmk135 Feb 25, 2021
6f41372
Add integration test for inline providers
rmk135 Feb 25, 2021
70e105d
Refactor integration tests
rmk135 Feb 25, 2021
a78edf4
Add integration test for reordered schema
rmk135 Feb 25, 2021
19786d3
Remove unused imports from tests
rmk135 Feb 25, 2021
8cac34b
Refactor schema module
rmk135 Feb 25, 2021
2a3b670
Update tests to match latest schemas
rmk135 Feb 26, 2021
2e4d6d9
Add mypy_boto3_s3 to the test requirements
rmk135 Mar 6, 2021
b457f54
Add boto3 to the test requirements
rmk135 Mar 6, 2021
b347efc
Add set_provides for Callable, Factory, and Singleton providers
rmk135 Mar 6, 2021
41cf1bd
Fix warnings in tests
rmk135 Mar 6, 2021
ce36033
Add typing stubs for Callable, Factory, and Singleton .set_provides()…
rmk135 Mar 6, 2021
bcc0b2a
Fix singleton children to have optional provides
rmk135 Mar 6, 2021
47f8c6e
Implement provider to provider resolving
rmk135 Mar 6, 2021
35a6f47
Fix pypy3 tests
rmk135 Mar 6, 2021
dbc6393
Implement boto3 session use case and add tests
rmk135 Mar 6, 2021
0fab16d
Implement lazy initialization and improve copying for Callable, Facto…
rmk135 Mar 7, 2021
5ccee19
Fix Python 2 tests
rmk135 Mar 7, 2021
fad03f2
Add region name for boto3 integration example
rmk135 Mar 7, 2021
7407758
Remove f-strings from set_provides()
rmk135 Mar 7, 2021
9202ad0
Fix schema flake8 errors
rmk135 Mar 7, 2021
3e03b93
Implement lazy initialization and improve copying for Delegate provider
rmk135 Mar 7, 2021
aa9fbb3
Implement lazy initialization and improve copying for Object provider
rmk135 Mar 8, 2021
a80e027
Speed up wiring tests
rmk135 Mar 8, 2021
ee44c8f
Implement lazy initialization and improve copying for FactoryAggregat…
rmk135 Mar 8, 2021
f7fcb22
Implement lazy initialization and improve copying for Selector provider
rmk135 Mar 8, 2021
17ecd6c
Implement lazy initialization and improve copying for Dependency prov…
rmk135 Mar 9, 2021
f180f49
Implement lazy initialization and improve copying for Resource provider
rmk135 Mar 9, 2021
bb473ab
Implement lazy initialization and improve copying for Configuration p…
rmk135 Mar 9, 2021
cec342c
Implement lazy initialization and improve copying for ProvidedInstanc…
rmk135 Mar 9, 2021
b8078f9
Implement lazy initialization and improve copying for AttributeGetter…
rmk135 Mar 9, 2021
773a7d8
Implement lazy initialization and improve copying for ItemGetter prov…
rmk135 Mar 10, 2021
052413d
Implement lazy initialization and improve copying for MethodCaller pr…
rmk135 Mar 10, 2021
344b4ec
Update changelog
rmk135 Mar 10, 2021
a7de2dc
Fix typing in wiring module
Mar 17, 2021
702df96
Fix wiring module loader uninstallation issue
rmk135 Mar 17, 2021
d725806
Fix provided instance providers error handing in asynchronous mode
rmk135 Mar 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/main/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_

Development version
-------------------
- Implement providers' lazy initialization.
- Improve providers' copying.
- Improve typing in wiring module.
- Fix wiring module loader uninstallation issue.
- Fix provided instance providers error handing in asynchronous mode.

4.30.0
------
- Remove restriction to wire a dynamic container.
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ fastapi
pydantic
numpy
scipy
boto3
mypy_boto3_s3

-r requirements-ext.txt
6,106 changes: 3,742 additions & 2,364 deletions src/dependency_injector/containers.c

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/dependency_injector/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import (
Generic,
Type,
Expand Down Expand Up @@ -34,6 +35,7 @@ class Container:
def __init__(self) -> None: ...
def __deepcopy__(self, memo: Optional[Dict[str, Any]]) -> Provider: ...
def __setattr__(self, name: str, value: Union[Provider, Any]) -> None: ...
def __getattr__(self, name: str) -> Provider: ...
def __delattr__(self, name: str) -> None: ...
def set_providers(self, **providers: Provider): ...
def set_provider(self, name: str, provider: Provider) -> None: ...
Expand All @@ -48,6 +50,9 @@ class Container:
def apply_container_providers_overridings(self) -> None: ...
def reset_singletons(self) -> SingletonResetContext[C_Base]: ...
def check_dependencies(self) -> None: ...
def from_schema(self, schema: Dict[Any, Any]) -> None: ...
def from_yaml_schema(self, filepath: Union[Path, str], loader: Optional[Any]=None) -> None: ...
def from_json_schema(self, filepath: Union[Path, str]) -> None: ...
@overload
def resolve_provider_name(self, provider: Provider) -> str: ...
@classmethod
Expand Down
39 changes: 39 additions & 0 deletions src/dependency_injector/containers.pyx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Containers module."""

import json
import sys

try:
import asyncio
except ImportError:
asyncio = None

try:
import yaml
except ImportError:
yaml = None

import six

from . import providers, errors
Expand Down Expand Up @@ -330,6 +336,39 @@ class DynamicContainer(Container):
f'{", ".join(undefined_names)}',
)

def from_schema(self, schema):
"""Build container providers from schema."""
from .schema import build_schema
for name, provider in build_schema(schema).items():
self.set_provider(name, provider)

def from_yaml_schema(self, filepath, loader=None):
"""Build container providers from YAML schema.

You can specify type of loader as a second argument. By default, method
uses ``SafeLoader``.
"""
if yaml is None:
raise errors.Error(
'Unable to load yaml schema - PyYAML is not installed. '
'Install PyYAML or install Dependency Injector with yaml extras: '
'"pip install dependency-injector[yaml]"'
)

if loader is None:
loader = yaml.SafeLoader

with open(filepath) as file:
schema = yaml.load(file, loader)

self.from_schema(schema)

def from_json_schema(self, filepath):
"""Build container providers from JSON schema."""
with open(filepath) as file:
schema = json.load(file)
self.from_schema(schema)

def resolve_provider_name(self, provider):
"""Try to resolve provider name."""
for provider_name, container_provider in self.providers.items():
Expand Down
Loading