diff --git a/DEVELOP.md b/DEVELOP.md new file mode 100644 index 0000000..eab4572 --- /dev/null +++ b/DEVELOP.md @@ -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 +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). \ No newline at end of file diff --git a/README.md b/README.md index 7b3d665..f4993ca 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/renamer-0.2.5-py3-none-any.whl b/dist/renamer-0.2.5-py3-none-any.whl index b85c9d6..a91fa34 100644 Binary files a/dist/renamer-0.2.5-py3-none-any.whl and b/dist/renamer-0.2.5-py3-none-any.whl differ diff --git a/pyproject.toml b/pyproject.toml index a9fb251..b0082d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,8 @@ dependencies = [ [project.scripts] renamer = "renamer.main:main" +bump-version = "renamer.bump:main" +release = "renamer.release:main" [tool.uv] package = true diff --git a/renamer/__init__.py b/renamer/__init__.py index c843dd0..741abc4 100644 --- a/renamer/__init__.py +++ b/renamer/__init__.py @@ -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'] \ No newline at end of file diff --git a/renamer/app.py b/renamer/app.py index cc4583d..19a65f5 100644 --- a/renamer/app.py +++ b/renamer/app.py @@ -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 diff --git a/renamer/bump.py b/renamer/bump.py new file mode 100644 index 0000000..6e01da2 --- /dev/null +++ b/renamer/bump.py @@ -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') \ No newline at end of file diff --git a/renamer/extractor.py b/renamer/extractors/extractor.py similarity index 95% rename from renamer/extractor.py rename to renamer/extractors/extractor.py index 4456a72..91a0d03 100644 --- a/renamer/extractor.py +++ b/renamer/extractors/extractor.py @@ -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: diff --git a/renamer/release.py b/renamer/release.py new file mode 100644 index 0000000..4954f57 --- /dev/null +++ b/renamer/release.py @@ -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) \ No newline at end of file