Skip to content

Commit

Permalink
Major refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekitdev committed Feb 19, 2024
1 parent d648446 commit ce74be8
Show file tree
Hide file tree
Showing 106 changed files with 3,133 additions and 1,784 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: check

on:
push:
branches:
- main

pull_request:
branches:
- "**"

jobs:
check:
name: Check

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: pipx install poetry

- name: Configure Poetry
run: poetry config virtualenvs.in-project true

- name: Specify the version
run: poetry env use python

- name: Install dependencies
run: poetry install

- name: Run type checks
run: poetry run mypy .
37 changes: 37 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: docs

on:
push:
branches:
- main

jobs:
docs:
name: Docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Poetry
run: pipx install poetry

- name: Configure Poetry
run: poetry config virtualenvs.in-project true

- name: Specify the version
run: poetry env use python

- name: Install dependencies
run: poetry install --with docs

- name: Pull
run: git pull

- name: Deploy the documentation
run: poetry run mkdocs gh-deploy
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: release

on:
push:
tags:
- v*

jobs:
release:
name: Release

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Poetry
run: pipx install poetry

- name: Configure Poetry
run: poetry config virtualenvs.in-project true

- name: Specify the version
run: poetry env use python

- name: Build
run: poetry build

- name: Publish to PyPI
run: poetry publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: test

on:
push:
branches:
- main

pull_request:
branches:
- "**"

jobs:
test:
name: Test

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: pipx install poetry

- name: Configure Poetry
run: poetry config virtualenvs.in-project true

- name: Specify the version
run: poetry env use python

- name: Install dependencies
run: poetry install

- name: Run tests
run: poetry run pytest --cov-report xml

- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: "./coverage.xml"
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: ruff
name: Run the Ruff linter
types_or: [python, pyi]
args: [--fix]
- id: ruff-format
name: Run the Ruff formatter
types_or: [python, pyi]

- repo: https://github.com/python-poetry/poetry
rev: 1.7.1
hooks:
- id: poetry-lock
stages: [push]
name: Run Poetry lock hook
args: [--no-update]
- id: poetry-check
stages: [push]
name: Run Poetry check hook
Empty file added CONTRIBUTING.md
Empty file.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "CHANGELOG.md"
1 change: 1 addition & 0 deletions docs/code_of_conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "CODE_OF_CONDUCT.md"
1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "CONTRIBUTING.md"
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "README.md"
1 change: 1 addition & 0 deletions docs/reference/melody/kit/core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: melody.kit.core
1 change: 1 addition & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "SECURITY.md"
3 changes: 0 additions & 3 deletions melody/bot/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from melody.bot.commands.album import get_album
from melody.bot.commands.artist import get_artist
from melody.bot.commands.search import search_items
from melody.bot.commands.self import get_self
from melody.bot.commands.statistics import get_statistics
from melody.bot.commands.track import get_track
Expand All @@ -10,8 +9,6 @@
"get_album",
# artist
"get_artist",
# search
"search_items",
# self
"get_self",
# statistics
Expand Down
10 changes: 0 additions & 10 deletions melody/bot/commands/search.py

This file was deleted.

2 changes: 1 addition & 1 deletion melody/bot/commands/self.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def get_self(interaction: Interaction[Melody]) -> None:
embed=not_linked_embed(not_linked(discord_id)), ephemeral=True
)

result = at_path(config.images / self.uri.image_name)
result = at_path(config.image.path / self.uri.image_name)

if result is None:
return await interaction.response.send_message(embed=user_embed(self), ephemeral=True)
Expand Down
35 changes: 32 additions & 3 deletions melody/kit.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is the default configuration file for MelodyKit.
# Configuration file is located at `~/.config/melody/kit.toml`.
# You can read more about it here: `https://docs.melodykit.app/dev/config`.
# You can read more about it here: `https://docs.melodykit.app/config`.
# There are some sensitive fields that need to be manually defined:
# - `melody.session_key`
# - `melody.email.name`
Expand All @@ -16,13 +16,32 @@ name = "MelodyKit"
domain = "melodykit.app"
open = "open"

images = "~/.melody/kit/images"

[melody.email]
host = "smtp.gmail.com"
port = 587
support = "[email protected]"

[melody.email.verification]
# allowed formatting: `name`
subject = "{name} verification code"

# allowed formatting: `verification_code`
content = """
Here is your verification code:
{verification_code}
"""

[melody.email.temporary]
# allowed formatting: `name`
subject = "{name} temporary token"
# allowed formatting: `temporary_token`
content = """
Here is your temporary token:
{temporary_token}
"""

[melody.hash]
time_cost = 4
memory_cost = 65536
Expand All @@ -38,6 +57,11 @@ error_correction = "high"
box_size = 10
border = 4

[melody.image]
path = "~/.melody/kit/images"
size_limit = 4096
data_size_limit = 16777216

[melody.log]
level = "info"

Expand All @@ -48,6 +72,11 @@ port = 6379
[melody.secret]
size = 32

[melody.totp]
digits = 6
interval = 30
valid_window = 1

[melody.token]
type = "Bearer"

Expand Down
67 changes: 1 addition & 66 deletions melody/kit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,3 @@
from melody.kit import endpoints, models
from melody.kit.config import Config, ConfigData, get_config, get_default_config
from melody.kit.core import app, config, database, hasher, redis, v1
from melody.kit.database import Database
from melody.kit.enums import AlbumType, EntityType, LogLevel, PrivacyType, Repeat
from melody.kit.errors import (
AuthError,
BadRequest,
Conflict,
Error,
ErrorCode,
ErrorData,
Forbidden,
Gone,
InternalError,
MethodNotAllowed,
NotFound,
PayloadTooLarge,
RateLimited,
Unauthorized,
ValidationError,
)
from melody.kit.uri import URI

__all__ = (
# endpoints
"endpoints",
# models
"models",
# core
"config",
"database",
"redis",
"hasher",
"app",
"v1",
# config
"Config",
"ConfigData",
"get_config",
"get_default_config",
# database
"Database",
# enums
"AlbumType",
"PrivacyType",
"Repeat",
"EntityType",
"LogLevel",
# errors
"Error",
"ErrorCode",
"ErrorData",
"AuthError",
"ValidationError",
"BadRequest",
"Unauthorized",
"Forbidden",
"NotFound",
"MethodNotAllowed",
"Conflict",
"Gone",
"PayloadTooLarge",
"RateLimited",
"InternalError",
# URI
"URI",
)
__all__ = ("endpoints", "models")
Loading

0 comments on commit ce74be8

Please sign in to comment.