-
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
1 parent
a01d36a
commit 3f27a6e
Showing
21 changed files
with
315 additions
and
170 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
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
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
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
[build-system] | ||
build-backend = "poetry.core.masonry.api" | ||
requires = ["poetry-core>=1"] | ||
requires = [ | ||
"poetry-core>=1", | ||
] | ||
|
||
[tool.poetry] | ||
name = "heartbeat" | ||
version = "0.1.0" | ||
description = "A heart failure detection system" | ||
readme = "README.md" | ||
authors = ["Vassilis Sioros <[email protected]>"] | ||
authors = [ "Vassilis Sioros <[email protected]>" ] | ||
license = "MIT" | ||
homepage = "https://billsioros.github.io/heartbeat" | ||
repository = "https://github.com/billsioros/heartbeat" | ||
keywords = [] | ||
keywords = [ ] | ||
classifiers = [ | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
|
@@ -22,6 +24,9 @@ classifiers = [ | |
"Bug Tracker" = "https://github.com/billsioros/heartbeat/issues" | ||
"Changelog" = "https://github.com/billsioros/heartbeat/releases" | ||
|
||
[tool.poetry.scripts] | ||
manage = "heartbeat.cli.manage:cli" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
pydantic = "^2.8.2" | ||
|
@@ -31,7 +36,8 @@ uvicorn = "^0.30.3" | |
gunicorn = "^22.0.0" | ||
sqlalchemy = "^2.0.31" | ||
psycopg2-binary = "^2.9.9" | ||
alembic = "^1.13.2" | ||
typer = "^0.12.3" | ||
rich = "^13.7.1" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
python-semantic-release = "7.34.6" | ||
|
@@ -114,7 +120,7 @@ select = [ | |
"UP", | ||
"YTT", | ||
] | ||
ignore = [] | ||
ignore = [ ] | ||
|
||
fixable = [ | ||
"A", | ||
|
@@ -162,7 +168,7 @@ fixable = [ | |
"UP", | ||
"YTT", | ||
] | ||
unfixable = [] | ||
unfixable = [ ] | ||
|
||
per-file-ignores = {} | ||
|
||
|
@@ -175,12 +181,12 @@ pydocstyle.convention = "google" | |
[tool.docformatter] | ||
black = true | ||
non-strict = true | ||
non-cap = ["heartbeat"] | ||
non-cap = [ "heartbeat" ] | ||
recursive = true | ||
in-place = true | ||
|
||
[tool.mypy] | ||
files = ["src/api"] | ||
files = [ "src/api" ] | ||
warn_unused_configs = true | ||
warn_return_any = true | ||
ignore_missing_imports = true | ||
|
@@ -199,7 +205,7 @@ upload_to_pypi = false | |
|
||
[tool.vulture] | ||
min_confidence = 95 | ||
paths = ["src/api"] | ||
paths = [ "src/api" ] | ||
|
||
[tool.poe.tasks] | ||
|
||
|
@@ -223,6 +229,10 @@ cmd = "poetry run mypy" | |
help = "Lint your code for errors" | ||
cmd = "poetry run ruff ." | ||
|
||
[tool.poe.tasks.manage] | ||
help = "Manage the application" | ||
cmd = "poetry run manage" | ||
|
||
[tool.bandit] | ||
recursive = true | ||
exclude_dirs = ["tests"] | ||
exclude_dirs = [ "tests" ] |
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
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
Empty file.
Empty file.
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,44 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import typer | ||
|
||
from heartbeat.cli.utils.gui import show_error, show_table | ||
|
||
if TYPE_CHECKING: | ||
from heartbeat.resources.database import Database | ||
|
||
group: typer.Typer = typer.Typer() | ||
|
||
|
||
@group.callback() | ||
def db(): | ||
"""Database related commands.""" | ||
|
||
|
||
@group.command() | ||
def create(ctx: typer.Context): | ||
"""Create the database.""" | ||
db: Database = ctx.obj["database"] | ||
|
||
db.create_database() | ||
|
||
|
||
@group.command() | ||
def show(ctx: typer.Context): | ||
"""List all the tables.""" | ||
db: Database = ctx.obj["database"] | ||
|
||
for model_class, entries in db.list_all_tables(): | ||
show_table(model_class.__name__, entries) | ||
|
||
|
||
@group.command() | ||
def drop(ctx: typer.Context): | ||
"""Drop all the tables.""" | ||
db: Database = ctx.obj["database"] | ||
|
||
answer = typer.prompt(f"Drop all tables in '{db._engine.url}' (yes/no) ?") | ||
|
||
if answer.lower() == "yes": | ||
for error in db.drop_all_tables(): | ||
show_error(error) |
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,43 @@ | ||
import subprocess | ||
import webbrowser | ||
from typing import Optional | ||
|
||
import typer | ||
|
||
from heartbeat.cli.commands.database import group as database | ||
from heartbeat.resources.database import Database | ||
from heartbeat.settings import Settings | ||
|
||
cli: typer.Typer = typer.Typer() | ||
|
||
|
||
@cli.callback(name="heartbeat") | ||
def main(ctx: typer.Context): | ||
"""NotOnMyWatch CLI.""" | ||
|
||
settings = Settings() | ||
database = Database(str(settings.database.uri)) | ||
|
||
ctx.obj = {"settings": settings, "database": database} | ||
|
||
|
||
cli.add_typer(database, name="database") | ||
|
||
|
||
@cli.command() | ||
def serve(port: int = 8000, build: bool = False): | ||
"""Serve the application on localhost.""" | ||
cmd = ["docker-compose", "up", "--force-recreate", "-d"] | ||
if build: | ||
cmd = ["docker-compose", "up", "--force-recreate", "--build", "-d"] | ||
|
||
try: | ||
subprocess.run(cmd) | ||
except subprocess.CalledProcessError as e: | ||
raise typer.Exit(code=e.returncode) | ||
|
||
webbrowser.open(f"http://localhost:{port}") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
Empty file.
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,19 @@ | ||
from collections.abc import Iterable | ||
from typing import Any | ||
|
||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
console: Console = Console() | ||
error_console = Console(stderr=True, style="bold red") | ||
|
||
|
||
def show_table(title: str, rows: Iterable[Any]) -> None: | ||
table = Table(title) | ||
for row in rows: | ||
table.add_row(repr(row)) | ||
console.print(table) | ||
|
||
|
||
def show_error(error: str): | ||
error_console.print(error) |
Oops, something went wrong.