Cookiecutter based tts process
- Wymagania wstępne
- Instalacja pipx
- Instalacja Poetry
- Alternatywa: virtualenv i pip
- Uruchamianie projektu
- Tworzenie pluginów
- Materiały dodatkowe
- Python 3.8+
- pipx (zalecane)
- Poetry (zalecane)
brew install pipx
pipx ensurepath
Dodatkowe (opcjonalne) komendy:
sudo pipx ensurepath --global
sudo pipx ensurepath --prepend
Więcej: Customising your installation
sudo apt update
sudo apt install pipx
pipx ensurepath
sudo dnf install pipx
pipx ensurepath
python3 -m pip install --user pipx
python3 -m pipx ensurepath
Dodatkowe (opcjonalne) komendy:
sudo pipx ensurepath --global
sudo pipx ensurepath --prepend
scoop install pipx
pipx ensurepath
py -m pip install --user pipx
Jeśli pojawi się ostrzeżenie o PATH, uruchom:
.\pipx.exe ensurepath
curl -sSL https://install.python-poetry.org | python3 -
pip install poetry
sudo apt install python3-poetry
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
pip install poetry
Po instalacji sprawdź:
poetry --version
Jeśli nie chcesz używać Poetry:
python -m venv venv
# Linux/macOS:
source venv/bin/activate
# Windows:
venv\Scripts\activate
- Zainstaluj zależności:
poetry install
- Aktywuj środowisko:
poetry shell
- Uruchom projekt zgodnie z instrukcją w sekcji Usage lub Development.
- Utwórz nowy moduł w
process/plugins/
- Zaimplementuj klasę dziedziczącą po
ProcessBase
- Zarejestruj plugin w
PluginRegistry
Szczegóły: Developer Guide
On macOS:
brew install pipx pipx ensurepath
Additional (optional) commands
To allow pipx actions in global scope.
sudo pipx ensurepath --global
To prepend the pipx bin directory to PATH instead of appending it.
sudo pipx ensurepath --prepend
For more details, refer to Customising your installation. On Linux:
Ubuntu 23.04 or above
sudo apt update sudo apt install pipx pipx ensurepath
Fedora:
sudo dnf install pipx pipx ensurepath
Using pip on other distributions:
python3 -m pip install --user pipx python3 -m pipx ensurepath
Additional (optional) commands
To allow pipx actions in global scope.
sudo pipx ensurepath --global
To prepend the pipx bin directory to PATH instead of appending it.
sudo pipx ensurepath --prepend
For more details, refer to Customising your installation. On Windows:
Install via Scoop:
scoop install pipx pipx ensurepath
Install via pip (requires pip 19.0 or later)
py -m pip install --user pipx
It is possible (even most likely) the above finishes with a WARNING looking similar to this:
WARNING: The script pipx.exe is installed in <USER folder>\AppData\Roaming\Python\Python3x\Scripts
which is not on PATH
If so, go to the mentioned folder, allowing you to run the pipx executable directly. Enter the following line (even if you did not get the warning):
.\pipx.exe ensurepath
This will add both the above mentioned path and the %USERPROFILE%.local\bin folder to your search path. Restart your terminal session and verify pipx does run.
Install Poetry
pipx install poetry
Install Poetry (advanced) You can skip this step, if you simply want the latest version and already installed Poetry as described in the previous step. This step details advanced usages of this installation method. For example, installing Poetry from source, having multiple versions installed at the same time etc.
pipx can install different versions of Poetry, using the same syntax as pip:
pipx install poetry==1.8.4
pipx can also install versions of Poetry in parallel, which allows for easy testing of alternate or prerelease versions. Each version is given a unique, user-specified suffix, which will be used to create a unique binary name:
pipx install --suffix=@1.8.4 poetry==1.8.4 poetry@1.8.4 --version
pipx install --suffix=@preview --pip-args=--pre poetry poetry@preview --version
Finally, pipx can install any valid pip requirement spec, which allows for installations of the development version from git, or even for local testing of pull requests:
pipx install --suffix @main git+https://github.com/python-poetry/poetry.git@main pipx install --suffix @pr1234 git+https://github.com/python-poetry/poetry.git@refs/pull/1234/head
Update Poetry
pipx upgrade poetry
Uninstall Poetry
pipx uninstall poetry
This project uses Poetry for dependency management. To install Poetry:
# Method 1: Using the official installer
curl -sSL https://install.python-poetry.org | python3 -
# Method 2: Using pip
pip install poetry
# Method 3: On Ubuntu/Debian
sudo apt install python3-poetry
# Method 1: Using the official installer
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
# Method 2: Using pip
pip install poetry
After installation, verify Poetry is installed correctly:
poetry --version
If you prefer not to install Poetry, you can use traditional virtualenv and pip:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install dependencies from requirements.txt
pip install -r requirements.txt
The Process system is designed to be modular. Here's how to create and set up new modules:
# Create the directory structure
mkdir -p graphql
cd graphql
# Initialize Poetry for the module
poetry init
# Add dependencies
poetry add fastapi uvicorn graphql-core
# Add development dependencies
poetry add --group dev pytest black isort mypy
# Create basic files
touch server.py client.py .env.example
# Navigate to the process directory
cd process
# Create a plugin directory if it doesn't exist
mkdir -p plugins
# Create a new plugin file
touch plugins/my_plugin.py
Example plugin implementation in plugins/my_plugin.py
:
from process.process_base import ProcessBase
from process.plugin_system import register_plugin
class MyPlugin(ProcessBase):
"""Custom processing plugin."""
def process_text(self, text, **options):
"""Process text with custom logic."""
# Implement your processing logic here
processed_text = text.upper() # Example: convert to uppercase
# Create and return a result
return self.create_result(
data=processed_text,
format="text",
metadata={"plugin": "my_plugin"}
)
# Register the plugin
register_plugin("my_plugin", MyPlugin)
# Create the directory structure
mkdir -p my_service
cd my_service
# Initialize Poetry for the module
poetry init
# Add dependencies
poetry add prometheus-client healthcheck
# Create basic files
touch server.py client.py .env.example
Example .env.example
for the new service:
# My Service Environment Variables
MY_SERVICE_HOST=0.0.0.0
MY_SERVICE_PORT=8080
MY_SERVICE_LOG_LEVEL=INFO
MY_SERVICE_PROCESS_HOST=process
MY_SERVICE_PROCESS_PORT=8000
# Monitoring settings
MY_SERVICE_ENABLE_METRICS=true
MY_SERVICE_METRICS_PORT=9101
MY_SERVICE_HEALTH_CHECK_INTERVAL=30
# Core settings
CORE_LOG_LEVEL=INFO
The Process system can be extended with plugins. To create a new plugin:
- Create a new module in the
process/plugins/
directory - Implement a class that inherits from
ProcessBase
- Register the plugin with the
PluginRegistry
See the Developer Guide for detailed instructions.
You can add new service interfaces (e.g., WebSocket) by following the pattern of existing services:
- Create a new directory for your service
- Implement a server that connects to the Process engine
- Implement a client for easy integration
See the Modular Architecture documentation for details.
Each module in the Process system can be tested independently. Here's how to test different components:
# Navigate to the process directory
cd process
# Run tests with Poetry
poetry run pytest
# Or with traditional pytest if not using Poetry
python -m pytest
# Example: Testing the gRPC service
cd grpc
poetry run pytest
# Example: Testing the REST API
cd rest
poetry run pytest
Each service exposes health check and metrics endpoints that can be tested:
# Start the service
cd imap
poetry run python server.py
# In another terminal, test the health endpoint
curl http://localhost:8080/health
# Test the metrics endpoint
curl http://localhost:9101/metrics
Test the entire system with all services running:
# Start all services with Docker Compose
docker-compose up -d
# Run end-to-end tests
cd tests/e2e_tests
python -m pytest
Detailed documentation is available in the docs/
directory:
- Developer Guide - Comprehensive guide for developers
- Modular Architecture - Details on the system architecture
- Environment Variables - List of all configuration options
- API Reference - API documentation for all components
Contributions are welcome! Please see CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.
Projekt korzysta z Poetry do zarządzania zależnościami. Jeśli plik pyproject.toml
nie istnieje, utwórz go poleceniem:
poetry init
Przykładowa zawartość pliku pyproject.toml
dla tego projektu:
[tool.poetry]
name = "tts"
version = "0.1.0"
description = "Cookiecutter based tts process"
authors = ["Twoje Imię <twoj@email.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = ">=3.8,<4.0"
# Dodaj tu zależności projektu, np.:
# numpy = "^1.26.0"
# requests = "^2.31.0"
[tool.poetry.dev-dependencies]
# pytest = "^7.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Po utworzeniu pliku możesz instalować zależności i zarządzać środowiskiem za pomocą poleceń Poetry opisanych wyżej.
# Instalacja zależności (jeśli nie została wykonana automatycznie)
poetry install
- Użycie cookiecutter jako alternatywy Cookiecutter to popularne narzędzie do generowania projektów z szablonów. Możemy stworzyć dedykowany szablon cookiecutter dla projektów TTS. 2.1. Instalacja cookiecutter
pip install cookiecutter
Użycie szablonu z repozytorium GitHub
cookiecutter gh:pyfunc/cookiecutter
lub Użycie lokalnego szablonu
cookiecutter path/to/cookiecutter-tts-project/
# Ustaw uprawnienia wykonywania dla skryptów
chmod +x hooks/pre_gen_project.py
chmod +x hooks/post_gen_project.py
# Uruchomienie serwisów w kontenerach
make up
{% if cookiecutter.components.mcp %} Aby uruchomić serwer MCP:
cd mcp
poetry run python mcp_server.py
{% endif %}
- Modularny system z wieloma komponentami
- Wsparcie dla różnych protokołów komunikacyjnych (gRPC, REST, WebRTC, MCP, MQTT, WebSocket)
- Integracja z Model Context Protocol (MCP)
- Narzędzia zapewnienia jakości kodu (Black, isort, Flake8, mypy)
- Automatyczna konfiguracja pre-commit hooks
- Comprehensive Makefile for common tasks
- Konfiguracja Docker i docker-compose (opcjonalnie)
- Konfiguracja projektu znajduje się w pliku
cookiecutter.json
.
Wygenerowany projekt używa spójnego systemu zmiennych środowiskowych z prefiksami dla każdego komponentu:
CORE_*
- Ustawienia rdzenia frameworkaPROCESS_*
- Ustawienia silnika ProcessGRPC_*
- Ustawienia usługi gRPCREST_*
- Ustawienia usługi REST APIMCP_*
- Ustawienia usługi MCPMQTT_*
- Ustawienia usługi MQTTWEBSOCKET_*
- Ustawienia usługi WebSocketLANGCHAIN_*
- Ustawienia integracji LangChain
Można używać jednego pliku .env
dla całego projektu lub oddzielnych plików dla każdego komponentu:
# Kopiowanie przykładowych plików środowiskowych
cp .env.example .env
# Lub dla poszczególnych komponentów
cp process/.env.example process/.env
cp grpc/.env.example grpc/.env
cp rest/.env.example rest/.env
cp mcp/.env.example mcp/.env
cp mqtt/.env.example mqtt/.env
cp websocket/.env.example websocket/.env
Szczegółowa dokumentacja zmiennych środowiskowych znajduje się w pliku docs/environment_variables.md
.
make test