Skip to content

Commit

Permalink
add a new image for chap 13
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed Feb 17, 2020
1 parent 0dee6a0 commit 6a1ea21
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ count-todos:
ls *.asciidoc | xargs grep -c TODO | sed s/:/\\t/

diagrams: html
./render-diagrams.py
./render-diagrams.py $(CHAP)
55 changes: 33 additions & 22 deletions chapter_13_dependency_injection.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,41 @@ Because Python is not a "pure" OO language, Python developers aren't necessarily
used to the concept of needing to "compose" a set of objects into a working
application. We just pick our entrypoint and run code from top to bottom.],
and we'll do a bit of "Manual DI" (dependency injection without a
frameworkfootnote:[Mark Seeman calls this https://blog.ploeh.dk/2012/11/06/WhentouseaDIContainer/[Pure DI], or sometimes "Vanilla DI".]).
frameworkfootnote:[Mark Seeman calls this https://blog.ploeh.dk/2012/11/06/WhentouseaDIContainer/[Pure DI], or sometimes "Vanilla DI".]),
and it will all turn out something like <<bootstrap_diagram>>.


[bootstrap_diagram]]
.Bootstrapper between entrypoints and message bus
image::images/apwp_1303.png[]
[role="image-source"]
----
Flask + Redis
|
| call
V
Bootstraper: prepares handlers with correct dependencies injected in
| (test bootstrapper will use fakes, prod one will use reals)
|
| pass injected handlers to
V
Messagebus
|
| dispatches events and commands to injected handlers
|
V
[ditaa, apwp_1303]
+---------------+
| Entrpyoints |
| (Flask/Redis) |
+---------------+
|
| call
V
/--------------\
| | prepares handlers with correct dependencies injected in
| Bootstrapper | (test bootstrapper will use fakes, prod one will use real)
| |
\--------------/
|
| pass injected handlers to
V
/---------------\
| Message Bus |
+---------------+
|
| dispatches events and commands to injected handlers
|
V
----

TODO: betterify diagram? or just get rid of, in favour of the first?




=== Preparing Handlers: Manual DI with Closures and Partials

Expand Down Expand Up @@ -745,7 +756,7 @@ of setup and sensible defaults into a single place.
**********************************************************************
Change all the handlers to being classes as per <<di_with_classes>>,
and amend the bootstrapper's DI code as appropriate. This will let you
know if you prefer the functional or the class-based approach, when
know if you prefer the functional or the class-based approach, when
it comes to your own projects.
**********************************************************************

Expand Down Expand Up @@ -996,14 +1007,14 @@ And, erm, that's it really.
There are two possible things you could do for practice regarding adapters:
1. Try swapping out our notifications from email to, for example, SMS
1. Try swapping out our notifications from email to, for example, SMS
notifications using Twilio, or Slack notifications. Can you find
a good equivalent to Mailhog for integration testing?
2. In a similar way to what we did moving from `send_mail` to a `Notifications`
class, try refactoring our `redis_eventpublisher` which is currently just
a `Callable` to some sort of more formal adapter / base class / protocol.
******************************************************************************


Expand Down
Binary file added images/apwp_1303.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions render-diagrams.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import sys
import tempfile
import subprocess
from pathlib import Path
Expand All @@ -7,16 +8,24 @@
IMAGES_DIR = Path(__file__).absolute().parent / 'images'


def main():
def all_chapter_names():
for fn in sorted(Path(__file__).absolute().parent.glob('*.html')):
chapter_name = fn.name.replace('.html', '')
if chapter_name == 'book':
continue
print('Rendering images for', chapter_name)
yield chapter_name

def main(paths):
if paths:
chapter_names = [p.replace('.html', '').replace('.asciidoc', '') for p in paths]
else:
chapter_names = all_chapter_names()
for chapter_name in chapter_names:
render_images(chapter_name)


def render_images(chapter_name):
print('Rendering images for', chapter_name)
raw_contents = Path(f'{chapter_name}.html').read_text()
parsed_html = html.fromstring(raw_contents)

Expand Down Expand Up @@ -68,4 +77,4 @@ def render_image(source, image_id):


if __name__ == '__main__':
main()
main(sys.argv[1:])

0 comments on commit 6a1ea21

Please sign in to comment.