Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7759cc2
ISSUE #148 - Initial package structure
vladyslav-fenchak Feb 17, 2022
9b02ca8
Restyled by black
restyled-commits Feb 17, 2022
eb4a14c
Restyled by isort
restyled-commits Feb 17, 2022
2affabb
Merge pull request #211 from minos-framework/restyled/issue-148-creat…
vladyslav-fenchak Feb 17, 2022
d79a11e
ISSUE #148
vladyslav-fenchak Feb 17, 2022
15b9331
ISSUE #148
vladyslav-fenchak Feb 17, 2022
5373cc8
ISSUE #148 - Move AIOHTTP REST to minos_rest_aiohttp plugin
vladyslav-fenchak Feb 17, 2022
f0a8ccc
Restyled by black
restyled-commits Feb 17, 2022
d967c74
Restyled by isort
restyled-commits Feb 17, 2022
4502155
Merge pull request #212 from minos-framework/restyled/issue-148-creat…
vladyslav-fenchak Feb 18, 2022
58a398e
ISSUE #148
vladyslav-fenchak Feb 18, 2022
e5b439c
ISSUE #148
vladyslav-fenchak Feb 18, 2022
444fb9f
ISSUE #148
vladyslav-fenchak Feb 18, 2022
f11272d
Merge remote-tracking branch 'origin/0.6.0' into issue-148-create-min…
vladyslav-fenchak Feb 23, 2022
edcd2b3
Merge remote-tracking branch 'origin/0.6.0' into issue-148-create-min…
Mar 8, 2022
21b276f
ISSUE #148
Mar 8, 2022
d231530
ISSUE #148
Mar 8, 2022
495335d
ISSUE #209
Mar 10, 2022
d3cc6b3
ISSUE #209
Mar 10, 2022
34373ec
ISSUE #209
Mar 10, 2022
75d8fec
ISSUE #209
Mar 10, 2022
96753f8
ISSUE #209
Mar 10, 2022
e1f7198
ISSUE #209
Mar 10, 2022
14c8381
ISSUE #209
Mar 10, 2022
09e6dbb
ISSUE #209
Mar 10, 2022
2ee42d1
ISSUE #209
Mar 10, 2022
9a3cf15
ISSUE #209
Mar 10, 2022
ebb6583
ISSUE #209
Mar 10, 2022
1df7378
ISSUE #209
Mar 10, 2022
ec857eb
ISSUE #209
Mar 11, 2022
f938dd6
ISSUE #209
Mar 11, 2022
79b008c
ISSUE #209
Mar 11, 2022
8a8c468
ISSUE #209
Mar 11, 2022
c0ef33e
ISSUE #209
Mar 11, 2022
71d909d
ISSUE #209
Mar 11, 2022
891b9b0
ISSUE #209
Mar 11, 2022
be21237
ISSUE #209
Mar 11, 2022
503117b
ISSUE #209
Mar 14, 2022
ece7fd1
ISSUE #87
Mar 14, 2022
71e041c
ISSUE #87
Mar 14, 2022
7159015
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 14, 2022
d1a4adf
ISSUE #209
Mar 14, 2022
7a94bd1
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 15, 2022
3c11389
ISSUE #209
Mar 15, 2022
dce7dd5
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 15, 2022
fa49d24
ISSUE #209
Mar 15, 2022
9cd2f7a
ISSUE #209
Mar 15, 2022
3beeef6
ISSUE #209
Mar 15, 2022
1ee63ce
ISSUE #209
Mar 15, 2022
9ef6d0d
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 15, 2022
9a70cfe
ISSUE #209
Mar 15, 2022
24009fc
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 15, 2022
da5aeef
ISSUE #209
Mar 15, 2022
ddba159
ISSUE #209
Mar 15, 2022
64a69aa
ISSUE #209
Mar 15, 2022
12fcfb1
Merge remote-tracking branch 'origin/0.6.0' into issue-209-abstract-r…
Mar 16, 2022
9fb432e
ISSUE #209
Mar 16, 2022
b663538
ISSUE #209
Mar 16, 2022
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
33 changes: 33 additions & 0 deletions .github/workflows/minos-http-aiohttp-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Publish: minos-http-aiohttp"

on:
push:
branches:
- '*.*.x'
paths:
- 'packages/plugins/minos-http-aiohttp/**'

jobs:
deploy:
runs-on: ubuntu-latest
container: python:3.9-buster
defaults:
run:
working-directory: packages/plugins/minos-http-aiohttp

steps:

- name: Check out repository code
uses: actions/checkout@v2

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: make install

- name: Publish package
run: make release
env:
POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
66 changes: 66 additions & 0 deletions .github/workflows/minos-http-aiohttp-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Test: minos-http-aiohttp"

on:
push:
branches:
- main
- '*.*.x'
pull_request:
paths:
- 'packages/plugins/minos-http-aiohttp/**'
- 'packages/core/minos-microservice-networks/**'
- 'packages/core/minos-microservice-common/**'

jobs:
build:
runs-on: ubuntu-latest
container: python:3.9-buster
defaults:
run:
working-directory: packages/plugins/minos-http-aiohttp

services:
postgres:
image: postgres
env:
POSTGRES_USER: minos
POSTGRES_PASSWORD: min0s
POSTGRES_DB: order_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

env:
MINOS_BROKER_QUEUE_HOST: postgres
MINOS_BROKER_HOST: kafka
MINOS_REPOSITORY_HOST: postgres
MINOS_SNAPSHOT_HOST: postgres

steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: make install

- name: Lint package
run: make lint

- name: Test package with coverage
run: make coverage

- name: Publish coverage
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./packages/plugins/minos-http-aiohttp/coverage.xml
fail_ci_if_error: true

- name: Generate documentation
run: make docs

- name: Generate build
run: make dist
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ repos:
files: ^packages/plugins/minos-broker-kafka/
language: system

- id: minos-http-aiohttp-check
pass_filenames: false
entry: make --directory=packages/plugins/minos-http-aiohttp check
name: Check minos-http-aiohttp
files: ^packages/plugins/minos-http-aiohttp/
language: system

- id: minos-discovery-minos-check
pass_filenames: false
entry: make --directory=packages/plugins/minos-discovery-minos check
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Minos is a framework which helps you create [reactive](https://www.reactivemanif
* [#78](https://github.com/minos-framework/minos-python/issues/78) Implement a circuit breaker for `minos-broker-kafka`.
* [#87](https://github.com/minos-framework/minos-python/issues/87) Implement idempotency for `BrokerSubscriber` message processing.
* [#100](https://github.com/minos-framework/minos-python/issues/100) Create the `minos-serializers-avro` plugin.
* [#148](https://github.com/minos-framework/minos-python/issues/148) Create the `minos-rest-aiohttp`.
* [#148](https://github.com/minos-framework/minos-python/issues/148) Create the `minos-http-aiohttp`.
* [#149](https://github.com/minos-framework/minos-python/issues/149) Add `minos-graphql-aiohttp` plugin.
* [#150](https://github.com/minos-framework/minos-python/issues/150) Refactor configuration file and `MinosConfig` accessor.
* [#151](https://github.com/minos-framework/minos-python/issues/151) Expose `OpenAPI` and `AsyncAPI` specifications.
Expand Down Expand Up @@ -1156,6 +1156,7 @@ The plugin packages provide connectors to external technologies like brokers, di

* [minos-broker-kafka](https://minos-framework.github.io/minos-python/packages/plugins/minos-broker-kafka): The `kafka` plugin package.
* [minos-discovery-minos](https://minos-framework.github.io/minos-python/packages/plugins/minos-discovery-minos): The `minos-discovery` plugin package.
* [minos-http-aiohttp](https://minos-framework.github.io/minos-python/packages/plugins/minos-http-aiohttp): The `aiohttp` plugin package.

## Source Code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
)
from .importlib import (
classname,
get_internal_modules,
import_module,
)
from .injectors import (
Expand Down Expand Up @@ -104,6 +105,9 @@
from .pools import (
MinosPool,
)
from .ports import (
Port,
)
from .protocol import (
MinosAvroDatabaseProtocol,
MinosAvroMessageProtocol,
Expand Down
11 changes: 11 additions & 0 deletions packages/core/minos-microservice-common/minos/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ def services(self) -> list[str]:
except MinosConfigException:
return list()

@property
def routers(self) -> list[str]:
"""Get the routers.

:return: A list containing the router class names as string values.
"""
try:
return self._get("routers")
except MinosConfigException:
return list()

@property
def middleware(self) -> list[str]:
"""Get the commands config.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import pkgutil
from types import (
ModuleType,
)
Expand All @@ -13,7 +14,7 @@


# noinspection SpellCheckingInspection
def import_module(module_name: str) -> Union[type, Callable]:
def import_module(module_name: str) -> Union[type, Callable, ModuleType]:
"""Import the given module from a package"""
parts = module_name.rsplit(".", 1)

Expand Down Expand Up @@ -41,3 +42,24 @@ def classname(cls: Union[type, Callable]) -> str:
return cls.__name__
# noinspection PyUnresolvedReferences
return f"{cls.__module__}.{cls.__qualname__}"


def get_internal_modules() -> list[ModuleType]:
"""Get the list of internal ``minos`` modules.

:return: A list of modules.
"""
return _import_submodules("minos") + _import_submodules("minos.plugins")


def _import_submodules(prefix: str) -> list[ModuleType]:
try:
base = importlib.import_module(prefix)
except ModuleNotFoundError:
return list()

modules = list()
for loader, module_name, _ in pkgutil.iter_modules(base.__path__):
module = importlib.import_module(f"{prefix}.{module_name}")
modules.append(module)
return modules
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def __init__(self, config: Config, **kwargs: Union[SetupMixin, Type[SetupMixin],

@cached_property
def injections(self) -> dict[str, SetupMixin]:
"""Get the injections dictionary.
"""Get the injections' dictionary.

:return: A dict of injections..
:return: A dict of injections.
"""
injections = dict()

Expand All @@ -53,7 +53,10 @@ def _fn(raw: Union[SetupMixin, Type[SetupMixin], str]) -> SetupMixin:
return raw

for key, value in self._raw_injections.items():
injections[key] = _fn(value)
try:
injections[key] = _fn(value)
except Exception as exc:
raise ValueError(f"An exception was raised while building injections: {exc!r}")

return injections

Expand All @@ -77,7 +80,7 @@ async def unwire(self) -> None:

@cached_property
def container(self) -> containers.Container:
"""Get the dependencies container.
"""Get the dependencies' container.

:return: A ``Container`` instance.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
)

import logging
import pkgutil
import re
import sys
from asyncio import (
AbstractEventLoop,
)
Expand Down Expand Up @@ -46,6 +43,7 @@
Config,
)
from .importlib import (
get_internal_modules,
import_module,
)
from .injectors import (
Expand Down Expand Up @@ -184,11 +182,7 @@ async def _setup(self) -> None:

@property
def _internal_modules(self) -> list[ModuleType]:
import minos

for loader, module_name, _ in pkgutil.iter_modules(minos.__path__):
loader.find_module(module_name).load_module(module_name)
return [v for k, v in sys.modules.items() if re.fullmatch(r"minos\.\w+", k)]
return get_internal_modules()

async def _destroy(self) -> None:
"""Unwire the injected dependencies and destroys it.
Expand Down
27 changes: 27 additions & 0 deletions packages/core/minos-microservice-common/minos/common/ports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from abc import (
ABC,
abstractmethod,
)

from aiomisc import (
Service,
)


class Port(Service, ABC):
"""Port base class."""

@abstractmethod
async def start(self) -> None:
"""Start the port execution.

:return: This method does not return anything.
"""

@abstractmethod
async def stop(self, err: Exception = None) -> None:
"""Stop the port execution.

:param err: Optional exception that stopped the execution.
:return: This method does not return anything.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def test_services_not_defined(self):
with patch.object(Config, "_get", side_effect=MinosConfigException("")):
self.assertEqual([], self.config.services)

def test_routers(self):
self.assertEqual(["path.to.MyRouter1", "path.to.MyRouter2"], self.config.routers)

def test_routers_not_defined(self):
with patch.object(Config, "_get", side_effect=MinosConfigException("")):
self.assertEqual([], self.config.routers)

def test_middleware(self):
self.assertEqual(["tests.middleware.performance_tracking"], self.config.middleware)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from minos.common import (
MinosImportException,
classname,
get_internal_modules,
import_module,
)

Expand All @@ -27,6 +28,14 @@ def test_classname(self):
self.assertEqual("builtins.int", classname(int))
self.assertEqual("minos.common.exceptions.MinosImportException", classname(MinosImportException))

def test_get_internal_modules(self):
from minos import (
common,
)

observed = get_internal_modules()
self.assertIn(common, observed)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ def test_from_str(self):
injector = DependencyInjector(self.config, lock_pool=classname(FakeLockPool))
self.assertIsInstance(injector.lock_pool, FakeLockPool)

def test_lock_pool(self):
def test_from_type(self):
injector = DependencyInjector(self.config, lock_pool=FakeLockPool)
self.assertIsInstance(injector.lock_pool, FakeLockPool)

def test_raises_building(self):
injector = DependencyInjector(self.config, lock_pool="path.to.LockPool")
with self.assertRaises(ValueError):
injector.injections

def test_another(self):
injector = DependencyInjector(self.config, foo=1)
self.assertEqual(1, injector.foo)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest

from aiomisc import (
Service,
)

from minos.common import (
Port,
)


class TestPort(unittest.TestCase):
def test_is_subclass(self):
self.assertTrue(issubclass(Port, Service))

def test_abstract(self):
# noinspection PyUnresolvedReferences
self.assertEqual({"start", "stop"}, Port.__abstractmethods__)


if __name__ == "__main__":
unittest.main()
3 changes: 3 additions & 0 deletions packages/core/minos-microservice-common/tests/test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ broker:
port: 5432
records: 10
retry: 2
routers:
- path.to.MyRouter1
- path.to.MyRouter2
services:
- tests.services.OrderService
- tests.services.OrderQueryService
Expand Down
Loading