refactor: Remove old decorators and integrate caching into the new cache subsystem
- Deleted the `renamer.decorators` package, including `caching.py` and `__init__.py`, to streamline the codebase. - Updated tests to reflect changes in import paths for caching decorators. - Added a comprehensive changelog to document major refactoring efforts and future plans. - Introduced an engineering guide detailing architecture, core components, and development setup.
This commit is contained in:
324
DEVELOP.md
324
DEVELOP.md
@@ -1,220 +1,118 @@
|
||||
# Developer Guide
|
||||
|
||||
This guide contains information for developers working on the Renamer project.
|
||||
**Version**: 0.7.0-dev
|
||||
**Last Updated**: 2026-01-01
|
||||
|
||||
**Current Version**: 0.5.10
|
||||
> **📘 For complete development documentation, see [ENGINEERING_GUIDE.md](ENGINEERING_GUIDE.md)**
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Prerequisites
|
||||
- Python 3.11+
|
||||
- UV package manager
|
||||
|
||||
### Install UV (if not already installed)
|
||||
```bash
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
```
|
||||
|
||||
### Development Installation
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone <repository-url>
|
||||
cd renamer
|
||||
|
||||
# Install in development mode with all dependencies
|
||||
uv sync
|
||||
|
||||
# Install the package in editable mode
|
||||
uv pip install -e .
|
||||
```
|
||||
|
||||
### Running in Development
|
||||
```bash
|
||||
# Run directly from source
|
||||
uv run python renamer/main.py
|
||||
|
||||
# Or run with specific directory
|
||||
uv run python renamer/main.py /path/to/directory
|
||||
|
||||
# Or use the installed command
|
||||
uv run renamer
|
||||
```
|
||||
|
||||
## Development Commands
|
||||
|
||||
The project includes several development commands defined in `pyproject.toml`:
|
||||
|
||||
### bump-version
|
||||
Increments the patch version in `pyproject.toml` (e.g., 0.2.6 → 0.2.7).
|
||||
```bash
|
||||
uv run bump-version
|
||||
```
|
||||
|
||||
### release
|
||||
Runs a batch process: bump version, sync dependencies, and build the package.
|
||||
```bash
|
||||
uv run release
|
||||
```
|
||||
|
||||
### Other Commands
|
||||
- `uv sync`: Install/update dependencies
|
||||
- `uv build`: Build the package
|
||||
- `uv run pytest`: Run tests
|
||||
|
||||
## Debugging
|
||||
|
||||
### Formatter Logging
|
||||
Enable detailed logging for formatter operations:
|
||||
```bash
|
||||
FORMATTER_LOG=1 uv run renamer /path/to/directory
|
||||
```
|
||||
|
||||
This creates `formatter.log` in the current directory with:
|
||||
- Formatter call sequences and ordering
|
||||
- Input/output values for each formatter
|
||||
- Caller information (file and line number)
|
||||
- Any errors during formatting
|
||||
- Timestamp for each operation
|
||||
|
||||
### Cache Inspection
|
||||
Cache is stored in `~/.cache/renamer/` with subdirectories:
|
||||
- `extractors/`: Extractor results cache
|
||||
- `tmdb/`: TMDB API response cache
|
||||
- `posters/`: Downloaded poster images
|
||||
- `general/`: General purpose cache
|
||||
|
||||
To clear cache:
|
||||
```bash
|
||||
rm -rf ~/.cache/renamer/
|
||||
```
|
||||
|
||||
### Settings Location
|
||||
Settings are stored in `~/.config/renamer/config.json`:
|
||||
```json
|
||||
{
|
||||
"mode": "technical",
|
||||
"cache_ttl_extractors": 21600,
|
||||
"cache_ttl_tmdb": 21600,
|
||||
"cache_ttl_posters": 2592000
|
||||
}
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
The application uses a modular architecture with clear separation of concerns:
|
||||
|
||||
### Core Application (`renamer/`)
|
||||
- **app.py**: Main RenamerApp class (Textual App), tree management, file operations
|
||||
- **main.py**: Entry point with argument parsing
|
||||
- **constants.py**: Comprehensive constants (media types, sources, resolutions, editions)
|
||||
- **settings.py**: Settings management with JSON persistence (`~/.config/renamer/`)
|
||||
- **cache.py**: File-based caching system with TTL support (`~/.cache/renamer/`)
|
||||
- **secrets.py**: API keys and secrets (TMDB)
|
||||
|
||||
### Extractors (`renamer/extractors/`)
|
||||
Data extraction from multiple sources:
|
||||
- **extractor.py**: MediaExtractor coordinator class
|
||||
- **mediainfo_extractor.py**: PyMediaInfo for detailed track information
|
||||
- **filename_extractor.py**: Regex-based filename parsing
|
||||
- **metadata_extractor.py**: Mutagen for embedded metadata
|
||||
- **fileinfo_extractor.py**: Basic file information (size, dates, MIME)
|
||||
- **tmdb_extractor.py**: The Movie Database API integration
|
||||
- **default_extractor.py**: Fallback extractor
|
||||
|
||||
### Formatters (`renamer/formatters/`)
|
||||
Display formatting and rendering:
|
||||
- **formatter.py**: Base formatter interface
|
||||
- **media_formatter.py**: Main formatter coordinating all format operations
|
||||
- **catalog_formatter.py**: Catalog mode display (TMDB data, posters)
|
||||
- **proposed_name_formatter.py**: Intelligent rename suggestions
|
||||
- **track_formatter.py**: Video/audio/subtitle track formatting
|
||||
- **size_formatter.py**: Human-readable file sizes
|
||||
- **date_formatter.py**: Timestamp formatting
|
||||
- **duration_formatter.py**: Duration in HH:MM:SS format
|
||||
- **resolution_formatter.py**: Resolution display
|
||||
- **extension_formatter.py**: File extension handling
|
||||
- **special_info_formatter.py**: Edition/source formatting
|
||||
- **text_formatter.py**: Text styling utilities
|
||||
- **helper_formatter.py**: General formatting helpers
|
||||
|
||||
### Screens (`renamer/screens.py`)
|
||||
UI screens for user interaction:
|
||||
- **OpenScreen**: Directory selection with validation
|
||||
- **HelpScreen**: Comprehensive help with key bindings
|
||||
- **RenameConfirmScreen**: File rename confirmation with preview
|
||||
- **SettingsScreen**: Settings configuration UI
|
||||
|
||||
### Utilities
|
||||
- **decorators/caching.py**: Caching decorator for automatic method caching
|
||||
- **bump.py**: Version bump utility script
|
||||
- **release.py**: Release automation (bump + sync + build)
|
||||
|
||||
## Testing
|
||||
|
||||
Run tests with:
|
||||
```bash
|
||||
uv run pytest
|
||||
```
|
||||
|
||||
Test files are located in `renamer/test/` with sample filenames in `filenames.txt`.
|
||||
|
||||
## Building and Distribution
|
||||
|
||||
### Build the Package
|
||||
```bash
|
||||
uv build
|
||||
```
|
||||
|
||||
### Install as Tool
|
||||
```bash
|
||||
uv tool install .
|
||||
```
|
||||
|
||||
### Uninstall
|
||||
```bash
|
||||
uv tool uninstall renamer
|
||||
```
|
||||
|
||||
## Code Style
|
||||
|
||||
The project follows Python best practices:
|
||||
- **PEP 8**: Standard Python style guide
|
||||
- **Type Hints**: Encouraged where appropriate
|
||||
- **Docstrings**: For all classes and public methods
|
||||
- **Descriptive Naming**: Clear variable and function names
|
||||
- **Pathlib**: For all file operations
|
||||
- **Error Handling**: Appropriate exception handling at boundaries
|
||||
|
||||
Consider using tools like:
|
||||
- `ruff` for linting and formatting
|
||||
- `mypy` for type checking
|
||||
- `black` for consistent formatting
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make your changes
|
||||
4. Run tests: `uv run pytest`
|
||||
5. Run the release process: `uv run release`
|
||||
6. Submit a pull request
|
||||
|
||||
## Additional Documentation
|
||||
|
||||
For comprehensive project information:
|
||||
- **[README.md](README.md)**: User guide and features
|
||||
- **[CLAUDE.md](CLAUDE.md)**: Complete AI assistant reference
|
||||
- **[AI_AGENT.md](AI_AGENT.md)**: AI agent instructions
|
||||
- **[INSTALL.md](INSTALL.md)**: Installation methods
|
||||
- **[ToDo.md](ToDo.md)**: Task list and priorities
|
||||
|
||||
## Project Resources
|
||||
|
||||
- **Cache Directory**: `~/.cache/renamer/`
|
||||
- **Config Directory**: `~/.config/renamer/`
|
||||
- **Test Files**: `renamer/test/`
|
||||
- **Build Output**: `dist/` and `build/`
|
||||
Quick reference for developers working on the Renamer project.
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-12-31
|
||||
## Quick Setup
|
||||
|
||||
```bash
|
||||
# Install UV
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
|
||||
# Clone and setup
|
||||
cd /home/sha/bin/renamer
|
||||
uv sync --extra dev
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Essential Commands
|
||||
|
||||
```bash
|
||||
# Run from source
|
||||
uv run renamer [directory]
|
||||
|
||||
# Run tests
|
||||
uv run pytest
|
||||
|
||||
# Run with coverage
|
||||
uv run pytest --cov=renamer
|
||||
|
||||
# Type check
|
||||
uv run mypy renamer/
|
||||
|
||||
# Version bump
|
||||
uv run bump-version
|
||||
|
||||
# Full release
|
||||
uv run release
|
||||
|
||||
# Build distribution
|
||||
uv build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Debugging
|
||||
|
||||
```bash
|
||||
# Enable detailed logging
|
||||
FORMATTER_LOG=1 uv run renamer /path/to/directory
|
||||
|
||||
# Check logs
|
||||
cat formatter.log
|
||||
|
||||
# Clear cache
|
||||
rm -rf ~/.cache/renamer/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# All tests
|
||||
uv run pytest
|
||||
|
||||
# Specific file
|
||||
uv run pytest renamer/test/test_services.py
|
||||
|
||||
# Verbose
|
||||
uv run pytest -xvs
|
||||
|
||||
# Generate sample files
|
||||
uv run python renamer/test/fill_sample_mediafiles.py
|
||||
```
|
||||
|
||||
See [ENGINEERING_GUIDE.md - Testing Strategy](ENGINEERING_GUIDE.md#testing-strategy)
|
||||
|
||||
---
|
||||
|
||||
## Release Process
|
||||
|
||||
```bash
|
||||
# 1. Bump version
|
||||
uv run bump-version
|
||||
|
||||
# 2. Run full release
|
||||
uv run release
|
||||
|
||||
# 3. Test installation
|
||||
uv tool install .
|
||||
|
||||
# 4. Manual testing
|
||||
uv run renamer /path/to/test/media
|
||||
```
|
||||
|
||||
See [ENGINEERING_GUIDE.md - Release Process](ENGINEERING_GUIDE.md#release-process)
|
||||
|
||||
---
|
||||
|
||||
## Documentation
|
||||
|
||||
- **[ENGINEERING_GUIDE.md](ENGINEERING_GUIDE.md)** - Complete technical reference
|
||||
- **[README.md](README.md)** - User guide
|
||||
- **[INSTALL.md](INSTALL.md)** - Installation instructions
|
||||
- **[CHANGELOG.md](CHANGELOG.md)** - Version history
|
||||
- **[REFACTORING_PROGRESS.md](REFACTORING_PROGRESS.md)** - Future plans
|
||||
- **[ToDo.md](ToDo.md)** - Current tasks
|
||||
|
||||
---
|
||||
|
||||
**For complete documentation, see [ENGINEERING_GUIDE.md](ENGINEERING_GUIDE.md)**
|
||||
|
||||
Reference in New Issue
Block a user