Skip to content

Commit

Permalink
Feature/rename repo (#3)
Browse files Browse the repository at this point in the history
* feat: rename project

* feat: github actions

* feat: github actions

* feat: github actions

* feat: github actions

* fix: healthcheck template fix

* fix: readme
  • Loading branch information
vonabarak authored Oct 19, 2021
1 parent 398945a commit 1f970f7
Show file tree
Hide file tree
Showing 64 changed files with 211 additions and 203 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Python application
on: push
jobs:

test:
name: Test
runs-on: ubuntu-20.04

services:
redis:
image: redis:6
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
image: postgres:12
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Setup
uses: ExpressApp/[email protected]
with:
python-version: "3.9.6"
poetry-version: "1.1.6"

- name: Run tests
run: |
source .venv/bin/activate
./scripts/test --cov-report=xml
env:
REDIS_DSN: redis://localhost/0
POSTGRES_DSN: postgresql://postgres:postgres@localhost/postgres

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: false
files: ./coverage.xml
flags: unittests

lint:
name: Lint
runs-on: ubuntu-20.04

steps:
- name: Setup
uses: ExpressApp/[email protected]
with:
python-version: "3.9.6"
poetry-version: "1.1.6"

- name: Run lint
run: |
source .venv/bin/activate
./scripts/lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dist/
.pytest_cache/
.mypy_cache/
.idea/

coverage.xml
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Boxv2
# Asyncbox Framework

## Установка

1. Установка

Склонировать репозиторий с исходниками
```bash
git clone https://github.com/ExpressApp/boxv2.git
git clone https://github.com/ExpressApp/asyncbox-framework.git
```
Собрать пакет и установить его
```bash
cd boxv2
cd asyncbox-framework
poetry build
pip install --user dist/boxv2-0.4.0-py3-none-any.whl
pip install --user dist/asyncbox-0.4.0-py3-none-any.whl
```

2. Создание проекта из шаблона

```bash
boxv2 -v -t http://path/to/template -p plugin1 -p plugin2 bot_project_name
asyncbox -v -t http://path/to/template -p plugin1 -p plugin2 bot_project_name
cd bot_project_name
```

Expand All @@ -27,11 +27,11 @@
```bash
poetry install
```
Важно: библиотека boxv2 в созданном проекте будет установлена той версии, которя
Важно: библиотека asyncbox в созданном проекте будет установлена той версии, которя
указана в шаблоне файла pyproject.toml. При необходимости вы можете указать нужную
версию или ветку репозитория следующим образом:
```
boxv2 = { git = "https://github.com/ExpressApp/boxv2.git", branch = "master"}
asyncbox = { git = "https://github.com/ExpressApp/asyncbox.git", branch = "master"}
```
4. Обновление
Expand Down Expand Up @@ -59,11 +59,11 @@
| Путь | Описание
-----------------------------------|:-----------------------------------
| boxv2.plugins.logger | расширенное логирование (Loguru)
| boxv2.plugins.tortoise | БД (PostgreSQL)
| boxv2.plugins.redis | Redis
| boxv2.plugins.sentry | мониторинг ошибок (Sentry)
| boxv2.plugins.prometheus | сбор метрик (Prometheus)
| asyncbox.plugins.logger | расширенное логирование (Loguru)
| asyncbox.plugins.sqlalchemy | БД (PostgreSQL)
| asyncbox.plugins.redis | Redis
| asyncbox.plugins.sentry | мониторинг ошибок (Sentry)
| asyncbox.plugins.prometheus | сбор метрик (Prometheus)
Каждый из плагинов может требовать наличия определённых настроек. В этом случае
необходимо добавить соответствующую настройку в класс AppSettings
Expand Down
3 changes: 3 additions & 0 deletions asyncbox/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from asyncbox.application import get_application

__all__ = ["get_application"]
2 changes: 1 addition & 1 deletion boxv2/__main__.py → asyncbox/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module as an executable magic file."""
from boxv2.main import main
from asyncbox.main import main

main()
8 changes: 4 additions & 4 deletions boxv2/application.py → asyncbox/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from botx import Bot, Collector
from fastapi import FastAPI

from boxv2.endpoints import get_router
from boxv2.plugin import get_plugin_by_path
from boxv2.settings import BaseAppSettings
from boxv2.utils.import_utils import import_object
from asyncbox.endpoints import get_router
from asyncbox.plugin import get_plugin_by_path
from asyncbox.settings import BaseAppSettings
from asyncbox.utils.import_utils import import_object


def get_application(settings: Optional[BaseAppSettings] = None) -> FastAPI:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion boxv2/endpoints.py → asyncbox/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import APIRouter, Depends
from starlette.status import HTTP_202_ACCEPTED

from boxv2.dependencies.status_recipient import get_status_recipient
from asyncbox.dependencies.status_recipient import get_status_recipient


def get_router(bot: Bot) -> APIRouter:
Expand Down
4 changes: 2 additions & 2 deletions boxv2/main.py → asyncbox/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cookiecutter.main import cookiecutter # type: ignore
from loguru import logger

from boxv2.plugin import get_plugin_by_path
from asyncbox.plugin import get_plugin_by_path


@click.command()
Expand Down Expand Up @@ -43,7 +43,7 @@ def render_plugins_template(plugin: str, extra_content: dict[str, Any]) -> None:
temp_dir = Path(mkdtemp())

try:
plugin_class = get_plugin_by_path(f"boxv2.plugins.{plugin}")
plugin_class = get_plugin_by_path(f"asyncbox.plugins.{plugin}")
except ImportError:
logger.warning(f"Plugin `{plugin}` not found.")
return
Expand Down
9 changes: 4 additions & 5 deletions boxv2/plugin.py → asyncbox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastapi import FastAPI
from pydantic import BaseModel, BaseSettings

from boxv2.utils.import_utils import import_object
from asyncbox.utils.import_utils import import_object


class BasePluginSettings(BaseSettings):
Expand Down Expand Up @@ -64,10 +64,9 @@ def get_name(cls) -> str:
"""Get plugin's lowercase name."""
module = inspect.getmodule(cls)
if module is not None:
#
# boxv2.plugins.sqlalchemy.plugin.SQLAlchemyPlugin
# ^
# this part is using as name
# asyncbox.plugins.sqlalchemy.plugin.SQLAlchemyPlugin
# ^
# this part is using as name
return module.__name__.split(".")[-2]
return cls.__name__.lower()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def plugins(message: Message, bot: Bot) -> None:
(plugin.get_name(), (await plugin.healthcheck()).json(indent=2))
for plugin in bot.state.plugins
]
template = "**{name}**\n ```json\n{status}\n``` \n\n"
template = "**{name}**\n ```json\n{status}\n```"
text = "\n\n".join(
[template.format(name=name, status=status) for name, status in names_and_status]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from typing import Any

from boxv2.plugin import BasePlugin
from boxv2.plugins.debug.commands import collector
from asyncbox.plugin import BasePlugin
from asyncbox.plugins.debug.commands import collector


class DebugPlugin(BasePlugin):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from loguru import logger
from loguru._defaults import LOGURU_FORMAT # noqa: WPS436

from boxv2.plugin import BasePlugin, BasePluginSettings
from asyncbox.plugin import BasePlugin, BasePluginSettings

if TYPE_CHECKING:
from loguru import Record # noqa: WPS433 # pragma: no cover
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Any

from boxv2.plugin import BasePlugin
from boxv2.plugins.prometheus.endpoint import router
from boxv2.plugins.prometheus.middleware import PrometheusMiddleware
from asyncbox.plugin import BasePlugin
from asyncbox.plugins.prometheus.endpoint import router
from asyncbox.plugins.prometheus.middleware import PrometheusMiddleware


class PrometheusPlugin(BasePlugin):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from pydantic import RedisDsn

from boxv2.plugin import BasePlugin, BasePluginSettings, HealtCheckData
from boxv2.plugins.redis.repo import RedisRepo
from asyncbox.plugin import BasePlugin, BasePluginSettings, HealtCheckData
from asyncbox.plugins.redis.repo import RedisRepo


class Settings(BasePluginSettings):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pydantic import AnyHttpUrl
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware # type: ignore

from boxv2.plugin import BasePlugin, BasePluginSettings
from boxv2.plugins.sentry.middleware import SentryMiddleware
from asyncbox.plugin import BasePlugin, BasePluginSettings
from asyncbox.plugins.sentry.middleware import SentryMiddleware


class Settings(BasePluginSettings):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

from boxv2.plugin import BasePlugin, BasePluginSettings, HealtCheckData
from boxv2.plugins.sqlalchemy.url_scheme_utils import make_url_async
from asyncbox.plugin import BasePlugin, BasePluginSettings, HealtCheckData
from asyncbox.plugins.sqlalchemy.url_scheme_utils import make_url_async


class Settings(BasePluginSettings):
Expand Down Expand Up @@ -48,7 +48,7 @@ async def healthcheck(self) -> HealtCheckData:
return HealtCheckData(healthy=False, information={"error": str(exc)})
return HealtCheckData(
healthy=True,
info={
information={
"server_version": rows.scalars().one(),
"dsn": self.settings.POSTGRES_DSN,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bot_name": "boxv2-bot",
"bot_display_name": "boxv2 bot",
"bot_name": "asyncbox-bot",
"bot_display_name": "asyncbox bot",
"bot_short_description": "TODO",
"bot_docs_link": "TODO",
"test_cov": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# init config
sys.path.append(str(pathlib.Path(__file__).resolve().parents[3]))

from boxv2.application import get_app_settings # isort:skip
from boxv2.plugins.sqlalchemy.url_scheme_utils import make_url_sync # isort:skip
from asyncbox.application import get_app_settings # isort:skip
from asyncbox.plugins.sqlalchemy.url_scheme_utils import make_url_sync # isort:skip
from app.db.models import Base # isort:skip

postgres_dsn = make_url_sync(get_app_settings().POSTGRES_DSN)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions boxv2/settings.py → asyncbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Config: # noqa: WPS431
env_file = ".env"
json_loads = lambda x: x # noqa: E731,WPS111

NAME = "boxv2"
NAME = "asyncbox"

PLUGINS = ["boxv2.plugins.tortoise"]
PLUGINS = ["asyncbox.plugins.tortoise"]
COLLECTORS: List[str] = []

# base kwargs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bot_name": "boxv2-bot",
"bot_display_name": "boxv2 bot",
"bot_name": "asyncbox-bot",
"bot_display_name": "asyncbox bot",
"bot_short_description": "TODO",
"bot_docs_link": "TODO",
"test_cov": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Main module."""

from boxv2 import get_application # pragma: no cover
from asyncbox import get_application # pragma: no cover

app = get_application() # pragma: no cover
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import List

from boxv2.settings import BaseAppSettings
from asyncbox.settings import BaseAppSettings


class AppSettings(BaseAppSettings):
Expand All @@ -11,7 +11,7 @@ class AppSettings(BaseAppSettings):
NAME = "{{cookiecutter.bot_name}}"
PLUGINS: List[str] = [
{% for plugin in cookiecutter.plugins.plugins_list %}
"boxv2.plugins.{{ plugin }}",
"asyncbox.plugins.{{ plugin }}",
{% endfor %}
]
COLLECTORS: List[str] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = []

[tool.poetry.dependencies]
python = ">=3.9,<3.10"
boxv2 = { git = "https://github.com/ExpressApp/boxv2.git", tag = "0.4.0"}
asyncbox = { git = "https://github.com/ExpressApp/asyncbox-framework.git", tag = "0.4.0"}

[tool.poetry.dev-dependencies]
black = "~20.8b1"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion boxv2/tests/fixtures.py → asyncbox/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from fastapi import FastAPI
from pytest_cov.plugin import StoreReport

from boxv2 import get_application
from asyncbox import get_application


@pytest.fixture(scope="session")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions boxv2/__init__.py

This file was deleted.

Loading

0 comments on commit 1f970f7

Please sign in to comment.