Merge branch 'release/3.23.2' into master

This commit is contained in:
Roman Mogylatov 2020-07-23 20:49:32 -04:00
commit bed547cc91
3 changed files with 103 additions and 76 deletions

View File

@ -7,6 +7,10 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_ follows `Semantic versioning`_
3.23.2
------
- Fix ``Flask`` tutorial code issues, typos and change some wording.
3.23.1 3.23.1
------ ------
- Fix an issue with creating ``Dependency`` provider with ``abc.ABCMeta``. - Fix an issue with creating ``Dependency`` provider with ``abc.ABCMeta``.

View File

@ -75,22 +75,30 @@ Initial project layout::
Now it's time to install ``Flask`` and ``Dependency Injector``. Now it's time to install ``Flask`` and ``Dependency Injector``.
Put next lines into the ``requirements.txt`` file:: Put next lines into the ``requirements.txt`` file:
.. code-block:: bash
dependency-injector dependency-injector
flask flask
Now let's install it:: Now let's install it:
.. code-block:: bash
pip install -r requirements.txt pip install -r requirements.txt
And check that installation is successful:: And check that installation is successful:
.. code-block:: bash
python -c "import dependency_injector; print(dependency_injector.__version__)" python -c "import dependency_injector; print(dependency_injector.__version__)"
python -c "import flask; print(flask.__version__)" python -c "import flask; print(flask.__version__)"
You should see something like:: You should see something like:
.. code-block:: bash
(venv) $ python -c "import dependency_injector; print(dependency_injector.__version__)" (venv) $ python -c "import dependency_injector; print(dependency_injector.__version__)"
3.22.0 3.22.0
@ -116,7 +124,7 @@ Put next into the ``views.py``:
Ok, we have the view. Ok, we have the view.
Now let's create the heart of our application - the container. Container will keep all of the Now let's create the main part of our application - the container. Container will keep all of the
application components and their dependencies. First two providers we need to add are application components and their dependencies. First two providers we need to add are
the ``Flask`` application provider and the view provider. the ``Flask`` application provider and the view provider.
@ -142,8 +150,8 @@ Put next into the ``containers.py``:
Finally we need to create the Flask application factory. It is traditionally called Finally we need to create the Flask application factory. It is traditionally called
``create_app()``. It will create the container. Then it will use the container to create ``create_app()``. It will create the container. Then it will use the container to create
the Flask application. Last step is to configure the routing - we will assign ``index_view`` from the the Flask application. Last step is to configure the routing - we will assign ``index_view`` from
container to handle user requests to the root ``/`` if our web application. the container to handle user requests to the root ``/`` of our web application.
Put next into the ``application.py``: Put next into the ``application.py``:
@ -173,13 +181,17 @@ Put next into the ``application.py``:
Ok. Now we're ready to say "Hello, World!". Ok. Now we're ready to say "Hello, World!".
Do next in the terminal:: Do next in the terminal:
.. code-block:: bash
export FLASK_APP=githubnavigator.application export FLASK_APP=githubnavigator.application
export FLASK_ENV=development export FLASK_ENV=development
flask run flask run
The output should be something like:: The output should be something like:
.. code-block:: bash
* Serving Flask app "githubnavigator.application" (lazy loading) * Serving Flask app "githubnavigator.application" (lazy loading)
* Environment: development * Environment: development
@ -205,14 +217,16 @@ It will help us to add all needed static files in few clicks.
Add ``bootstrap-flask`` to the ``requirements.txt``: Add ``bootstrap-flask`` to the ``requirements.txt``:
.. code-block:: .. code-block:: bash
:emphasize-lines: 3 :emphasize-lines: 3
dependency-injector dependency-injector
flask flask
bootstrap-flask bootstrap-flask
and run in the terminal:: and run in the terminal:
.. code-block:: bash
pip install --upgrade -r requirements.txt pip install --upgrade -r requirements.txt
@ -276,7 +290,7 @@ the ``githubnavigator`` package. We also will need two files there:
Create ``templates`` folder and put two empty files into it ``base.html`` and ``index.html``: Create ``templates`` folder and put two empty files into it ``base.html`` and ``index.html``:
.. code-block:: .. code-block:: bash
:emphasize-lines: 3-5 :emphasize-lines: 3-5
./ ./
@ -442,7 +456,7 @@ We will use `PyGithub <https://github.com/PyGithub/PyGithub>`_ library for worki
Let's add it to the ``requirements.txt``: Let's add it to the ``requirements.txt``:
.. code-block:: .. code-block:: bash
:emphasize-lines: 4 :emphasize-lines: 4
dependency-injector dependency-injector
@ -450,7 +464,9 @@ Let's add it to the ``requirements.txt``:
bootstrap-flask bootstrap-flask
pygithub pygithub
and run in the terminal:: and run in the terminal:
.. code-block:: bash
pip install --upgrade -r requirements.txt pip install --upgrade -r requirements.txt
@ -509,7 +525,7 @@ We will use YAML.
Create an empty file ``config.yml`` in the root root of the project: Create an empty file ``config.yml`` in the root root of the project:
.. code-block:: .. code-block:: bash
:emphasize-lines: 11 :emphasize-lines: 11
./ ./
@ -525,7 +541,9 @@ Create an empty file ``config.yml`` in the root root of the project:
├── config.yml ├── config.yml
└── requirements.txt └── requirements.txt
and put next into it:: and put next into it:
.. code-block:: yaml
github: github:
request_timeout: 10 request_timeout: 10
@ -535,7 +553,7 @@ file. Let's add it to the requirements file.
Edit ``requirements.txt``: Edit ``requirements.txt``:
.. code-block:: .. code-block:: bash
:emphasize-lines: 5 :emphasize-lines: 5
dependency-injector dependency-injector
@ -544,7 +562,9 @@ Edit ``requirements.txt``:
pygithub pygithub
pyyaml pyyaml
and install it:: and install it:
.. code-block:: bash
pip install --upgrade -r requirements.txt pip install --upgrade -r requirements.txt
@ -617,7 +637,7 @@ Now it's time to add ``SearchService``. It will:
Create empty file ``services.py`` in the ``githubnavigator`` package: Create empty file ``services.py`` in the ``githubnavigator`` package:
.. code-block:: .. code-block:: bash
:emphasize-lines: 9 :emphasize-lines: 9
./ ./
@ -758,7 +778,7 @@ Now let's inject the ``SearchService`` dependency into the ``index`` view.
Edit ``containers.py``: Edit ``containers.py``:
.. code-block:: python .. code-block:: python
:emphasize-lines: 32-38 :emphasize-lines: 32-35
"""Application containers module.""" """Application containers module."""
@ -890,7 +910,7 @@ Finally let's update the config.
Edit ``config.yml``: Edit ``config.yml``:
.. code-block:: .. code-block:: yaml
:emphasize-lines: 3-5 :emphasize-lines: 3-5
github: github:
@ -913,7 +933,7 @@ We will use `pytest <https://docs.pytest.org/en/stable/>`_ and
Edit ``requirements.txt``: Edit ``requirements.txt``:
.. code-block:: .. code-block:: bash
:emphasize-lines: 6-7 :emphasize-lines: 6-7
dependency-injector dependency-injector
@ -924,14 +944,15 @@ Edit ``requirements.txt``:
pytest-flask pytest-flask
pytest-cov pytest-cov
And let's install it:: And let's install it:
.. code-block:: bash
pip install -r requirements.txt pip install -r requirements.txt
Create empty file ``tests.py`` in the ``githubnavigator`` package: Create empty file ``tests.py`` in the ``githubnavigator`` package:
.. code-block:: .. code-block:: bash
:emphasize-lines: 10 :emphasize-lines: 10
./ ./
@ -1024,13 +1045,15 @@ and put next into it:
assert response.status_code == 200 assert response.status_code == 200
assert b'Results found: 0' in response.data assert b'Results found: 0' in response.data
Now let's run it and check the coverage:: Now let's run it and check the coverage:
.. code-block:: bash
py.test githubnavigator/tests.py --cov=githubnavigator py.test githubnavigator/tests.py --cov=githubnavigator
You should see: You should see:
.. code-block:: .. code-block:: bash
platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
plugins: flask-1.0.0, cov-2.10.0 plugins: flask-1.0.0, cov-2.10.0
@ -1064,8 +1087,8 @@ We are done.
It this tutorial we've build ``Flask`` application following dependency injection principle. It this tutorial we've build ``Flask`` application following dependency injection principle.
We've used ``Dependency Injector`` as a dependency injection framework. We've used ``Dependency Injector`` as a dependency injection framework.
The heart of this application is the container. It keeps all the application components and their The main part of this application is the container. It keeps all the application components and
dependencies in one place: their dependencies in one place:
.. code-block:: python .. code-block:: python

View File

@ -1,6 +1,6 @@
"""Dependency injector top-level package.""" """Dependency injector top-level package."""
__version__ = '3.23.1' __version__ = '3.23.2'
"""Version number that follows semantic versioning. """Version number that follows semantic versioning.
:type: str :type: str