Skip to content

Commit

Permalink
Merge pull request #68 from globality-corp/release/2.13.1
Browse files Browse the repository at this point in the history
Release version 2.13.1
  • Loading branch information
afallou authored Oct 22, 2019
2 parents f7208d3 + 37d1149 commit 112ca32
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.13.0
current_version = 2.13.1
commit = False
tag = False

Expand Down
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
defaults: &defaults
working_directory: ~/repo
docker:
- image: ${AWS_ECR_DOMAIN}/globality-build:2019.23.2
- image: ${AWS_ECR_DOMAIN}/globality-build:2019.41.70
aws_auth:
aws_access_key_id: ${AWS_ACCESS_KEY_ID}
aws_secret_access_key: ${AWS_SECRET_ACCESS_KEY}
Expand All @@ -28,7 +28,7 @@ defaults: &defaults
deploy_defaults: &deploy_defaults
working_directory: ~/repo
docker:
- image: ${AWS_ECR_DOMAIN}/globality-build:2019.23.2
- image: ${AWS_ECR_DOMAIN}/globality-build:2019.41.70
aws_auth:
aws_access_key_id: ${AWS_ACCESS_KEY_ID}
aws_secret_access_key: ${AWS_SECRET_ACCESS_KEY}
Expand Down Expand Up @@ -70,8 +70,8 @@ jobs:
# install dependencies for loading ecs task definitions
command: |
eval $(aws ecr get-login --no-include-email)
globality-build docker-base --repo python-library
globality-build docker --repo python-library
globality-build build-gen local
globality-build docker-build-push --repo python-library
test:
<<: *defaults
Expand Down
2 changes: 1 addition & 1 deletion .globality/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
}
},
"type": "python-library",
"version": "2019.23.2"
"version": "2019.41.70"
}
18 changes: 12 additions & 6 deletions microcosm/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ class Bar:
ON_RESOLVE = "_microcosm_on_resolve_"


def _invoke_hook(hook_name, target):
def _get_hook_name(hook_prefix, target_cls):
return f"{hook_prefix}_{target_cls.__name__}"


def _invoke_hook(hook_prefix, target_component):
"""
Generic hook invocation.
"""
hook_name = _get_hook_name(hook_prefix, target_component.__class__)
try:
for value in getattr(target, hook_name):
for value in getattr(target_component, hook_name):
func, args, kwargs = value
func(target, *args, **kwargs)
func(target_component, *args, **kwargs)
except AttributeError:
# no hook defined
pass
Expand All @@ -59,16 +64,17 @@ def _invoke_hook(hook_name, target):
pass


def _register_hook(hook_name, target, func, *args, **kwargs):
def _register_hook(hook_prefix, target_cls, func, *args, **kwargs):
"""
Generic hook registration.
"""
hook_name = _get_hook_name(hook_prefix, target_cls)
call = (func, args, kwargs)
try:
getattr(target, hook_name).append(call)
getattr(target_cls, hook_name).append(call)
except AttributeError:
setattr(target, hook_name, [call])
setattr(target_cls, hook_name, [call])


def invoke_resolve_hook(target):
Expand Down
20 changes: 20 additions & 0 deletions microcosm/tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ def __init__(self, graph):
self.callbacks = []


@binding("subfoo")
class SubFoo(Foo):
pass


@binding("bar")
def new_foo(graph):
return Foo(graph)


on_resolve(Foo, foo_hook, "baz")
on_resolve(SubFoo, foo_hook, "qux")


class TestHooks:
Expand Down Expand Up @@ -54,6 +60,20 @@ def test_on_resolve_foo_again(self):

assert_that(graph.foo.callbacks, contains("baz"))

def test_on_resolve_foo_subfoo(self):
"""
If we have two components, and one is a subclass of the other's class, we should
still have isolation of the hooks between them
"""
graph = create_object_graph("test")
graph.use("foo")
graph.use("subfoo")
graph.lock()

assert_that(graph.foo.callbacks, contains("baz"))
assert_that(graph.subfoo.callbacks, contains("qux"))

def test_on_resolve_bar_once(self):
"""
Resolving Foo through a separate factory calls the hook.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


project = "microcosm"
version = "2.13.0"
version = "2.13.1"

setup(
name=project,
Expand Down

0 comments on commit 112ca32

Please sign in to comment.