-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
328 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Prerelease | ||
|
||
on: | ||
push: | ||
branches: [alpha, beta, next] | ||
|
||
jobs: | ||
|
||
compute-new-tag-version: | ||
timeout-minutes: 15 | ||
runs-on: ubuntu-latest | ||
outputs: | ||
fromTag: ${{ steps.fromTag.outputs.tag }} | ||
toTag: ${{ steps.toTag.outputs.tag }} | ||
steps: | ||
- name: checkout code repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: 'Get Previous tag' | ||
id: fromTag | ||
uses: "WyriHaximus/github-action-get-previous-tag@v1" | ||
|
||
- name: Installing python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Installing poetry | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: '1.6.1' | ||
|
||
- name: Install deps | ||
run: poetry install | ||
|
||
- name: Run matic-release | ||
run: poetry run python scripts/release.py --ci | ||
|
||
- name: Publish tag | ||
run: git push --tags | ||
|
||
- name: 'Get lastest tag' | ||
id: toTag | ||
uses: "WyriHaximus/github-action-get-previous-tag@v1" | ||
|
||
generate-release: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- compute-new-tag-version | ||
if: ${{ needs.compute-new-tag-version.outputs.fromTag != needs.compute-new-tag-version.outputs.toTag }} | ||
steps: | ||
- name: checkout code repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up git-cliff | ||
uses: kenji-miyake/setup-git-cliff@v1 | ||
|
||
- name: Run git-cliff | ||
run: | | ||
{ | ||
echo 'CHANGELOG<<EOF' | ||
git cliff --latest | ||
echo EOF | ||
} >> "$GITHUB_ENV" | ||
- name: Create Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
body: ${{ env.CHANGELOG }} | ||
prerelease: true | ||
tag_name: ${{ needs.compute-new-tag-version.outputs.toTag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# TurboBus | ||
|
||
TurboBus is an opinionated implementation of Command Responsibility Segregation pattern in python. | ||
|
||
## Simple usage | ||
Let's see an example using python typings. You can omit all the typing stuffs if you want to. | ||
|
||
**God Mode ⚡** | ||
```python | ||
from dataclasses import dataclass | ||
from typing import TypeAlias | ||
|
||
from turbobus.bus import Command, CommandHandler, CommandBus | ||
from turbobus.decorators import command, injectable | ||
|
||
LogHandlerType: TypeAlias = "ILogHandler" | ||
|
||
@dataclass | ||
class LogCommand(Command[LogHandlerType]): | ||
content: str | ||
|
||
|
||
class ILogHandler(CommandHandler[str]): | ||
... | ||
|
||
|
||
@command(LogCommand) | ||
class LogHandler(ILogHandler): | ||
def execute(self, cmd: LogCommand) -> str: | ||
return cmd.content | ||
|
||
|
||
if __name__ == '__main__': | ||
bus = CommandBus() | ||
|
||
result = bus.execute( | ||
LogCommand('Hello dude!') | ||
) | ||
print(result) # Hello dude | ||
``` | ||
|
||
**Human Mode 🥱** | ||
```python | ||
from dataclasses import dataclass | ||
|
||
from turbobus.bus import Command, CommandHandler | ||
from turbobus.decorators import command, injectable | ||
|
||
@dataclass | ||
class LogCommand(Command): | ||
content | ||
|
||
|
||
class ILogHandler(CommandHandler): | ||
... | ||
|
||
@command(LogCommand) | ||
class LogHandler(ILogHandler): | ||
def execute(self, cmd: LogCommand) -> str: | ||
return cmd.content | ||
|
||
|
||
if __name__ == '__main__': | ||
bus = CommandBus() | ||
|
||
result = bus.execute( | ||
LogCommand('Hello dude!') | ||
) | ||
print(result) # Hello dude | ||
``` | ||
|
||
## Dependency injection | ||
In many cases we're going to need to inject dependencies to our command handler. To accomplish that we have two important tools: `@injectable` decorator and `injecting` function. | ||
|
||
With the injectable decorator we can specify a class that is implementing the functionalities of the dependency. For example: | ||
|
||
```python | ||
from turbobus.decorators import injectable | ||
from log.axioma.log import ILogger | ||
|
||
|
||
class ILogger(ABC): | ||
|
||
@abstractmethod | ||
def logger(self, text: str) -> None: | ||
... | ||
|
||
|
||
@injectable(ILogger) | ||
class Logger: | ||
|
||
def logger(self, text: str) -> None: | ||
print('from logger', text) | ||
|
||
|
||
@command(LogCommand) | ||
@dataclass(kw_only=True) | ||
class LogHandler(ILogHandler): | ||
|
||
logger = injecting(ILogger) | ||
|
||
def execute(self, cmd: LogCommand) -> str: | ||
if self.logger is not None: | ||
self.logger.logger(cmd.content) | ||
|
||
return cmd.content | ||
|
||
``` | ||
|
||
As you can see in the example above, we're defining an abstract class with the logger method. Then we're doing the implementation of the `ILogger` and we're indicating that in the `@injectable(ILogger)`. | ||
|
||
Then, using the `injecting` function, TurboBus is going to map that dependency and inject the instance in the attribute. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[tool.poetry] | ||
name = "turbobus" | ||
version = "1.0.0-alpha.0" | ||
description = "TurboBus is an opinionated implementation of Command Responsibility Segregation pattern in python" | ||
authors = ["Christopher A. Flores <christopher.flores@codexitos.com>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^7.4.2" | ||
matic-release = {git = "https://github.com/fancy-crud/matic-release.git"} | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
from matic_release.axioma.version import Version | ||
from matic_release.capabilities.commit_analyzer import CommitAnalyzer | ||
from matic_release.capabilities.compute_tag import ComputeTag | ||
from matic_release.capabilities.publish_tag import PublishTag | ||
from matic_release.integration.git import GitService | ||
|
||
|
||
args = sys.argv[1:] | ||
git = GitService() | ||
|
||
latest_tag = git.get_latest_tag() | ||
|
||
version = Version(latest_tag) | ||
|
||
commit_analyzer = CommitAnalyzer() | ||
compute_tag = ComputeTag(git, commit_analyzer) | ||
|
||
compute_tag.execute(version) | ||
|
||
|
||
if '--ci' in args: | ||
publish = PublishTag(git) | ||
publish.execute(version) | ||
|
||
print(version.future_tag.value) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.