Skip to content

Latest commit

Β 

History

History
423 lines (313 loc) Β· 9.47 KB

File metadata and controls

423 lines (313 loc) Β· 9.47 KB

Audio Archive Bot - Modern Python Packaging Summary

Overview

The audio_archive_bot project has been successfully restructured with modern Python packaging following PEP 621 standards while maintaining full backward compatibility with existing code.

Files Created

Core Package Files

  1. audio_archive_bot/__init__.py

    • Package initialization file
    • Exports version and main components
    • Provides backward compatibility fallbacks
  2. audio_archive_bot/__main__.py

    • Entry point for python -m audio_archive_bot
    • Delegates to the CLI module
  3. audio_archive_bot/cli.py

    • Main CLI entry point
    • Handles environment validation
    • Imports and runs the existing hybrid_bot.py code
    • Provides user-friendly error messages
  4. audio_archive_bot/hybrid_bot.py (copied)

    • Main bot implementation
    • Discord event handlers
    • Bot configuration and setup
  5. audio_archive_bot/voice_manager_hybrid.py (copied)

    • Hybrid voice manager
    • IPC interface to Node.js
    • Recording management

Configuration Files

  1. pyproject.toml

    • Modern packaging configuration (PEP 621)
    • Project metadata and dependencies
    • Development tool configurations (black, isort, pytest, etc.)
    • Console scripts entry point
    • Comprehensive classifiers and keywords
  2. MANIFEST.in

    • Specifies non-Python files to include in distribution
    • Includes .js files, shell scripts, documentation
    • Includes Node.js configuration (package.json)
    • Excludes build artifacts and logs
  3. setup.py

    • Legacy compatibility file
    • Delegates to pyproject.toml
    • Ensures compatibility with older pip versions

Documentation

  1. PACKAGING_GUIDE.md

    • Comprehensive packaging documentation
    • Installation instructions
    • Development workflow
    • Building and publishing guide
    • Troubleshooting section
  2. PACKAGE_SUMMARY.md (this file)

    • Quick reference summary
    • Package structure overview
    • Installation and usage instructions
  3. install_package.sh

    • Interactive installation script
    • Checks Python version
    • Offers development/production installation options

Package Structure

audio_archive_bot/
β”œβ”€β”€ audio_archive_bot/              # Main Python package
β”‚   β”œβ”€β”€ __init__.py                # Package exports (version, HybridVoiceManager)
β”‚   β”œβ”€β”€ __main__.py                # python -m audio_archive_bot entry point
β”‚   β”œβ”€β”€ cli.py                     # CLI entry point (audio_bot_run command)
β”‚   β”œβ”€β”€ hybrid_bot.py              # Main bot implementation
β”‚   └── voice_manager_hybrid.py    # Voice management IPC
β”‚
β”œβ”€β”€ pyproject.toml                 # Modern packaging (PEP 621)
β”œβ”€β”€ MANIFEST.in                    # Distribution file inclusion rules
β”œβ”€β”€ setup.py                       # Legacy compatibility
β”œβ”€β”€ requirements.txt               # Original dependencies (kept for reference)
β”‚
β”œβ”€β”€ PACKAGING_GUIDE.md             # Complete packaging documentation
β”œβ”€β”€ PACKAGE_SUMMARY.md             # This summary file
β”œβ”€β”€ install_package.sh             # Interactive installer
β”‚
β”œβ”€β”€ [Original files]               # All original files preserved
β”‚   β”œβ”€β”€ hybrid_bot.py              # Original bot (still works)
β”‚   β”œβ”€β”€ voice_manager_hybrid.py    # Original voice manager
β”‚   β”œβ”€β”€ voice_recorder.js          # Node.js voice recorder
β”‚   β”œβ”€β”€ package.json               # Node.js dependencies
β”‚   β”œβ”€β”€ run_hybrid.sh              # Original run script
β”‚   └── ...                        # Other original files
β”‚
└── [Documentation]                # All existing documentation
    β”œβ”€β”€ README.md
    β”œβ”€β”€ CONTRIBUTING.md
    β”œβ”€β”€ CHANGELOG.md
    └── ...

Installation

Quick Start

# Interactive installation
./install_package.sh

# Or manual development installation
pip3 install -e .

# With development tools
pip3 install -e ".[dev]"

Verify Installation

# Check package is installed
pip3 show audio-archive-bot

# Check version
python3 -c "import audio_archive_bot; print(audio_archive_bot.__version__)"

# Verify command is available
which audio_bot_run

Running the Bot

Method 1: Using the CLI Command (Recommended)

audio_bot_run

This is the modern, packaged way to run the bot.

Method 2: Using Python Module

python3 -m audio_archive_bot

Method 3: Traditional (Backward Compatible)

# Original methods still work
python3 hybrid_bot.py
./run_hybrid.sh
./run_bot_forever.sh

Key Features

Modern Python Packaging (PEP 621)

  • Build System: setuptools >= 45
  • Version: 0.1.0
  • Python Requirement: >= 3.8
  • License: MIT

Project Metadata

  • Name: audio-archive-bot
  • Description: Hybrid Python/Node.js Discord bot for voice recording
  • Keywords: discord, bot, audio, recording, voice, mp3, archive
  • Classifiers: Beta, End Users/Desktop, MIT License, Python 3.8+

Dependencies

Production:

  • discord.py[voice] >= 2.6.3
  • python-dotenv >= 1.0.0
  • pydub >= 0.25.1
  • psutil >= 5.9.0

Development (optional):

  • black >= 24.10.0 (code formatting)
  • isort >= 5.13.2 (import sorting)
  • flake8 >= 7.1.1 (linting)
  • bandit >= 1.7.10 (security)
  • pytest >= 8.0.0 (testing)
  • pre-commit >= 4.0.0 (git hooks)

Console Scripts

The package provides the following command-line tools:

  • audio_bot_run: Main entry point to start the bot

Tool Configurations

Integrated configurations for:

  • Black: Code formatting (line length 100)
  • isort: Import sorting (Black-compatible)
  • Bandit: Security linting
  • pytest: Testing framework
  • Coverage: Code coverage reporting

Development Workflow

Setup Development Environment

# Clone and install
git clone <repository-url>
cd audio_archive_bot
pip3 install -e ".[dev]"
npm install

Code Quality

# Format code
black audio_archive_bot/

# Sort imports
isort audio_archive_bot/

# Lint
flake8 audio_archive_bot/

# Security check
bandit -r audio_archive_bot/

Testing

# Run tests (when available)
pytest

# With coverage
pytest --cov=audio_archive_bot --cov-report=html

Pre-commit Hooks

# Install hooks
pre-commit install

# Run manually
pre-commit run --all-files

Building and Distribution

Build Package

# Install build tool
pip3 install build

# Build both sdist and wheel
python3 -m build

This creates:

  • dist/audio-archive-bot-0.1.0.tar.gz (source distribution)
  • dist/audio_archive_bot-0.1.0-py3-none-any.whl (wheel)

Publish to PyPI

# Install twine
pip3 install twine

# Test PyPI (recommended first)
twine upload --repository testpypi dist/*

# Production PyPI
twine upload dist/*

Backward Compatibility

All original functionality is preserved:

  1. Original files remain in place - No files were moved or deleted from the root
  2. Original scripts still work - run_hybrid.sh, run_bot_forever.sh, etc.
  3. Original import paths work - Can still import from root-level modules
  4. Configuration unchanged - .env file format is identical

Migration Path

For End Users

Before:

git clone <repo>
cd audio_archive_bot
pip3 install -r requirements.txt
python3 hybrid_bot.py

After (recommended):

git clone <repo>
cd audio_archive_bot
pip3 install -e .
audio_bot_run

Or (still supported):

# Old method still works!
python3 hybrid_bot.py

For Developers

Before:

pip3 install -r requirements.txt
python3 hybrid_bot.py

After:

pip3 install -e ".[dev]"
black audio_archive_bot/
pytest
audio_bot_run

Configuration

Before running, configure your environment:

# Copy template
cp .env.example .env

# Edit with your credentials
nano .env

Required variables:

  • DISCORD_TOKEN - Your Discord bot token
  • TARGET_USER_ID - User ID to monitor

Optional variables:

  • EMAIL_USER - Gmail address for email delivery
  • EMAIL_PASS - Gmail app password
  • EMAIL_RECIPIENT - Where to send recordings

Node.js Integration

The package includes Node.js integration for voice recording:

# Install Node.js dependencies
npm install

# Run Node.js component (separate terminal)
node voice_recorder.js

# Or use the integrated script
./run_hybrid.sh

Uninstallation

pip3 uninstall audio-archive-bot

Next Steps

  1. Configure Environment

    • Copy .env.example to .env
    • Add your Discord credentials
  2. Install Dependencies

    • Run ./install_package.sh or pip3 install -e .
    • Run npm install for Node.js
  3. Start the Bot

    • Run audio_bot_run or ./run_hybrid.sh
  4. Development (optional)

    • Install dev dependencies: pip3 install -e ".[dev]"
    • Set up pre-commit: pre-commit install
    • Read CONTRIBUTING.md

Resources

  • README.md - User guide and bot functionality
  • PACKAGING_GUIDE.md - Detailed packaging documentation
  • CONTRIBUTING.md - Development guidelines
  • CHANGELOG.md - Version history
  • SECURITY.md - Security policy and reporting

Support

For issues or questions:

  • Check the documentation files
  • Review existing GitHub issues
  • Open a new issue with details

Version

Current Version: 0.1.0

This is the initial packaged release. Future versions will follow semantic versioning (MAJOR.MINOR.PATCH).


Last Updated: 2025-10-17 Status: Production Ready Compatibility: Python 3.8+, Node.js 18+