feat: Add CLI for PyServe with configuration options
- Introduced a new CLI module (`cli.py`) to manage server configurations via command line arguments. - Added script entry point in `pyproject.toml` for easy access to the CLI. - Enhanced `Config` class to load configurations from a YAML file. - Updated `__init__.py` to include `__version__` in the module exports. - Added optional dependencies for development tools in `pyproject.toml`. - Implemented logging improvements and error handling in various modules. - Created tests for the CLI functionality to ensure proper behavior. - Removed the old `run.py` implementation in favor of the new CLI approach.
This commit is contained in:
@@ -8,7 +8,7 @@ PyServe is a modern, async HTTP server written in Python. Originally created for
|
||||
|
||||
## Project Overview
|
||||
|
||||
PyServe v0.4.2 introduces a completely refactored architecture with modern async/await syntax and new exciting features like **Vibe-Serving** - AI-powered dynamic content generation.
|
||||
PyServe v0.6.0 introduces a completely refactored architecture with modern async/await syntax and new exciting features like **Vibe-Serving** - AI-powered dynamic content generation.
|
||||
|
||||
### Key Features:
|
||||
|
||||
@@ -23,29 +23,130 @@ PyServe v0.4.2 introduces a completely refactored architecture with modern async
|
||||
- **Modular Extensions** - Plugin-like architecture for security, caching, monitoring
|
||||
- **Beautiful Logging** - Colored terminal output with file rotation
|
||||
- **Error Handling** - Styled error pages and graceful fallbacks
|
||||
- **CLI Interface** - Command-line interface for easy deployment and configuration
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.12 or higher
|
||||
- Dependencies: `pip install -r requirements.txt`
|
||||
- Poetry (recommended) or pip
|
||||
|
||||
### Installation
|
||||
|
||||
#### Via Poetry (рекомендуется)
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ShiftyX1/PyServe.git
|
||||
cd PyServe
|
||||
pip install -r requirements.txt
|
||||
make init # Инициализация проекта для разработки
|
||||
```
|
||||
|
||||
#### Или установка пакета
|
||||
|
||||
```bash
|
||||
# Локальная установка
|
||||
make install-package
|
||||
|
||||
# После установки можно использовать команду pyserve
|
||||
pyserve --help
|
||||
```
|
||||
|
||||
### Running the Server
|
||||
|
||||
Basic startup:
|
||||
#### Используя Makefile (рекомендуется)
|
||||
|
||||
```bash
|
||||
# Запуск в режиме разработки
|
||||
make run
|
||||
|
||||
# Запуск в продакшн режиме
|
||||
make run-prod
|
||||
|
||||
# Показать все доступные команды
|
||||
make help
|
||||
```
|
||||
|
||||
#### Используя CLI напрямую
|
||||
|
||||
```bash
|
||||
# После установки пакета
|
||||
pyserve
|
||||
|
||||
# Или через Poetry
|
||||
poetry run pyserve
|
||||
|
||||
# Или старый способ (для обратной совместимости)
|
||||
python run.py
|
||||
```
|
||||
|
||||
#### Опции командной строки
|
||||
|
||||
```bash
|
||||
# Справка
|
||||
pyserve --help
|
||||
|
||||
# Кастомный конфиг
|
||||
pyserve -c /path/to/config.yaml
|
||||
|
||||
# Переопределить хост и порт
|
||||
pyserve --host 0.0.0.0 --port 9000
|
||||
|
||||
# Режим отладки
|
||||
pyserve --debug
|
||||
|
||||
# Показать версию
|
||||
pyserve --version
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Makefile Commands
|
||||
|
||||
```bash
|
||||
make help # Показать справку по командам
|
||||
make install # Установить зависимости
|
||||
make dev-install # Установить зависимости для разработки
|
||||
make build # Собрать пакет
|
||||
make test # Запустить тесты
|
||||
make test-cov # Тесты с покрытием кода
|
||||
make lint # Проверить код линтерами
|
||||
make format # Форматировать код
|
||||
make clean # Очистить временные файлы
|
||||
make version # Показать версию
|
||||
make publish-test # Опубликовать в Test PyPI
|
||||
make publish # Опубликовать в PyPI
|
||||
```
|
||||
|
||||
### Project Structure
|
||||
|
||||
```
|
||||
pyserveX/
|
||||
├── pyserve/ # Основной пакет
|
||||
│ ├── __init__.py
|
||||
│ ├── cli.py # CLI интерфейс
|
||||
│ ├── server.py # Основной сервер
|
||||
│ ├── config.py # Система конфигурации
|
||||
│ ├── routing.py # Маршрутизация
|
||||
│ ├── extensions.py # Расширения
|
||||
│ └── logging_utils.py
|
||||
├── tests/ # Тесты
|
||||
├── static/ # Статические файлы
|
||||
├── templates/ # Шаблоны
|
||||
├── logs/ # Логи
|
||||
├── Makefile # Автоматизация задач
|
||||
├── pyproject.toml # Конфигурация проекта
|
||||
├── config.yaml # Конфигурация сервера
|
||||
└── run.py # Точка входа (обратная совместимость)
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Create `config.yaml` from example:
|
||||
```bash
|
||||
make config-create
|
||||
```
|
||||
|
||||
Running with specific configuration:
|
||||
```bash
|
||||
python run.py -H 0.0.0.0 -p 8080
|
||||
|
||||
Reference in New Issue
Block a user