feat: Add developer guide, enhance versioning and release process, and refactor extractor imports

This commit is contained in:
sHa
2025-12-27 03:14:11 +00:00
parent 649ea7fbb3
commit c0ce9c8848
9 changed files with 197 additions and 74 deletions

149
DEVELOP.md Normal file
View File

@@ -0,0 +1,149 @@
# Developer Guide
This guide contains information for developers working on the Renamer project.
## 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` with:
- Formatter call sequences and ordering
- Input/output values for each formatter
- Caller information (file and line number)
- Any errors during formatting
## Architecture
The application uses a modular architecture:
### Extractors (`renamer/extractors/`)
- **MediaInfoExtractor**: Extracts detailed track information using PyMediaInfo
- **FilenameExtractor**: Parses metadata from filenames
- **MetadataExtractor**: Extracts embedded metadata using Mutagen
- **FileInfoExtractor**: Provides basic file information
- **DefaultExtractor**: Fallback extractor
- **MediaExtractor**: Main extractor coordinating all others
### Formatters (`renamer/formatters/`)
- **MediaFormatter**: Formats extracted data for display
- **ProposedNameFormatter**: Generates intelligent rename suggestions
- **TrackFormatter**: Formats video/audio/subtitle track information
- **SizeFormatter**: Formats file sizes
- **DateFormatter**: Formats timestamps
- **DurationFormatter**: Formats time durations
- **ResolutionFormatter**: Formats video resolutions
- **TextFormatter**: Text styling utilities
### Screens (`renamer/screens.py`)
- **OpenScreen**: Directory selection dialog
- **HelpScreen**: Application help and key bindings
- **RenameConfirmScreen**: File rename confirmation dialog
### Main Components
- **app.py**: Main TUI application
- **main.py**: Entry point
- **constants.py**: Application constants
## 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 uses standard Python formatting. Consider using tools like:
- `ruff` for linting and formatting
- `mypy` for type checking (if added)
## 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
For more information, see the main [README.md](../README.md).

View File

@@ -71,74 +71,9 @@ renamer /path/to/media/directory
4. Press **y** to confirm or **n** to cancel
5. The file will be renamed and the tree updated automatically
## Debugging
## Development
### Formatter Logging
The application includes detailed logging for formatter operations that can be enabled for debugging purposes.
To enable formatter logging:
```bash
FORMATTER_LOG=1 renamer /path/to/directory
```
This will create a `formatter.log` file in the current directory containing:
- Formatter call sequences and ordering
- Input/output values for each formatter
- Caller information (file and line number)
- Any errors during formatting
Useful for troubleshooting metadata display issues or formatter problems.
## Architecture
The application uses a modular architecture with separate extractors and formatters:
### Extractors
- **MediaInfoExtractor**: Extracts detailed track information using PyMediaInfo
- **FilenameExtractor**: Parses metadata from filenames
- **MetadataExtractor**: Extracts embedded metadata using Mutagen
- **FileInfoExtractor**: Provides basic file information
### Formatters
- **MediaFormatter**: Formats extracted data for display
- **ProposedNameFormatter**: Generates intelligent rename suggestions
- **TrackFormatter**: Formats video/audio/subtitle track information
- **SizeFormatter**: Formats file sizes
- **DateFormatter**: Formats timestamps
- **DurationFormatter**: Formats time durations
- **ResolutionFormatter**: Formats video resolutions
- **TextFormatter**: Text styling utilities
### Screens
- **OpenScreen**: Directory selection dialog
- **HelpScreen**: Application help and key bindings
- **RenameConfirmScreen**: File rename confirmation dialog
### Setup Development Environment
```bash
# Install in development mode
uv sync
# Run directly (development)
uv run python main.py
# Or run installed version
renamer
```
### Running Without Rebuilding (Development)
```bash
# Run directly from source (no installation needed)
uv run python main.py
# Or run with specific directory
uv run python main.py /path/to/directory
```
### Uninstall
```bash
uv tool uninstall renamer
```
For development setup, architecture details, debugging information, and contribution guidelines, see [DEVELOP.md](DEVELOP.md).
## Supported Video Formats
- .mkv

Binary file not shown.

View File

@@ -15,6 +15,8 @@ dependencies = [
[project.scripts]
renamer = "renamer.main:main"
bump-version = "renamer.bump:main"
release = "renamer.release:main"
[tool.uv]
package = true

View File

@@ -1,7 +1,7 @@
# Renamer package
from .app import RenamerApp
from .extractor import MediaExtractor
from .extractors.extractor import MediaExtractor
from .formatters.media_formatter import MediaFormatter
__all__ = ['RenamerApp', 'MediaExtractor', 'MediaFormatter']

View File

@@ -10,7 +10,7 @@ import os
from .constants import MEDIA_TYPES
from .screens import OpenScreen, HelpScreen, RenameConfirmScreen
from .extractor import MediaExtractor
from .extractors.extractor import MediaExtractor
from .formatters.media_formatter import MediaFormatter
from .formatters.proposed_name_formatter import ProposedNameFormatter
from .formatters.text_formatter import TextFormatter

15
renamer/bump.py Normal file
View File

@@ -0,0 +1,15 @@
def main():
import re
with open('pyproject.toml', 'r') as f:
content = f.read()
match = re.search(r'version = "(\d+)\.(\d+)\.(\d+)"', content)
if match:
major, minor, patch = map(int, match.groups())
patch += 1
new_version = f'{major}.{minor}.{patch}'
content = content.replace(match.group(0), f'version = "{new_version}"')
with open('pyproject.toml', 'w') as f:
f.write(content)
print(f'Version bumped to {new_version}')
else:
print('Version not found')

View File

@@ -1,9 +1,9 @@
from pathlib import Path
from .extractors.filename_extractor import FilenameExtractor
from .extractors.metadata_extractor import MetadataExtractor
from .extractors.mediainfo_extractor import MediaInfoExtractor
from .extractors.fileinfo_extractor import FileInfoExtractor
from .extractors.default_extractor import DefaultExtractor
from .filename_extractor import FilenameExtractor
from .metadata_extractor import MetadataExtractor
from .mediainfo_extractor import MediaInfoExtractor
from .fileinfo_extractor import FileInfoExtractor
from .default_extractor import DefaultExtractor
class MediaExtractor:

22
renamer/release.py Normal file
View File

@@ -0,0 +1,22 @@
def main():
import subprocess
import sys
try:
# Bump version
print("Bumping version...")
subprocess.run([sys.executable, '-m', 'renamer.bump'], check=True)
# Sync dependencies
print("Syncing dependencies...")
subprocess.run(['uv', 'sync'], check=True)
# Build package
print("Building package...")
subprocess.run(['uv', 'build'], check=True)
print("Release process completed successfully!")
except subprocess.CalledProcessError as e:
print(f"Error during release process: {e}")
sys.exit(1)