Skip to content

Commit dbbf5fd

Browse files
authored
462 Config.from_value() (#465)
* Implement .from_value() method for config provider * Add tests for config.from_value() method * Add example for config.from_value() * Add docs * Update changelog
1 parent bbd623c commit dbbf5fd

File tree

7 files changed

+4972
-4721
lines changed

7 files changed

+4972
-4721
lines changed

docs/main/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Development version
1313
configuration files with ``${ENV_NAME:default}`` format.
1414
See issue `#459 <https://github.com/ets-labs/python-dependency-injector/issues/459>`_.
1515
Thanks to `Maksym Shemet @hbmshemet <https://github.com/hbmshemet>`_ for suggesting the feature.
16+
- Add method ``Configuration.from_value()``.
17+
See issue `#462 <https://github.com/ets-labs/python-dependency-injector/issues/462>`_.
18+
Thanks to Mr. `Slack Clone <https://disqus.com/by/slackclone/>`_ for bringing it up
19+
in the comments for configuration provider docs.
1620

1721
4.32.3
1822
------

docs/providers/configuration.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ Loading from an environment variable
164164
:lines: 3-
165165
:emphasize-lines: 18-20
166166

167+
Loading a value
168+
---------------
169+
170+
``Configuration`` provider can load configuration value using the
171+
:py:meth:`Configuration.from_value` method:
172+
173+
.. literalinclude:: ../../examples/providers/configuration/configuration_value.py
174+
:language: python
175+
:lines: 3-
176+
:emphasize-lines: 14-15
177+
167178
Loading from the multiple sources
168179
---------------------------------
169180

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""`Configuration` provider values loading example."""
2+
3+
from datetime import date
4+
5+
from dependency_injector import containers, providers
6+
7+
8+
class Container(containers.DeclarativeContainer):
9+
10+
config = providers.Configuration()
11+
12+
13+
if __name__ == '__main__':
14+
container = Container()
15+
16+
container.config.option1.from_value(date(2021, 6, 13))
17+
container.config.option2.from_value(date(2021, 6, 14))
18+
19+
assert container.config() == {
20+
'option1': date(2021, 6, 13),
21+
'option2': date(2021, 6, 14),
22+
}
23+
assert container.config.option1() == date(2021, 6, 13)
24+
assert container.config.option2() == date(2021, 6, 14)

0 commit comments

Comments
 (0)