-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
overhaul(formaverter): recreated project from scratch #20
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added support for converting images to and from the WebP format, expanding the range of supported conversions. Refactored the conversion logic to streamline the process by consolidating similar operations and removing redundant checks. Introduced a new method `_convert_image` to handle all image format conversions using Pillow, and `_move_or_error` to manage file moves when input and output formats are identical. Updated the `supported_conversions` method to reflect these changes. This enhances functionality and improves code maintainability.
Introduced a new module `image_collector.py` to facilitate the collection of image files from a specified directory. The function `collect_images` retrieves paths of supported image formats, leveraging extensions defined in `ImageConverter.SUPPORTED_CONVERSIONS`. It raises a `ValueError` if the input directory is invalid. This enhancement aids in organizing and processing images efficiently within the application.
…ection and conversion Added comprehensive unit tests for the `collect_images` function in `image_collector` and various methods in `image_converter`. These tests cover scenarios such as collecting valid images, handling non-existent directories, and ensuring only supported file extensions are processed. For `image_converter`, tests include converting JPEG to PNG, handling unsupported formats, and verifying that input and output paths differ. This ensures robustness and correctness of image processing functionalities.
Replaced the interactive menu-driven file conversion system with a command-line interface using argparse for improved usability and automation. Removed logging setup and text conversion functionalities to focus solely on image processing. Introduced `process_images` function to handle both single image and directory conversions, utilizing `convert_image` and `collect_images`. This refactoring simplifies the codebase, enhances maintainability, and aligns the module with modern CLI practices.
The `img.save` method no longer requires the output format to be explicitly specified, as Pillow already infers the format from the file extension of `self.output_path`. This change simplifies the code and reduces potential errors from mismatched extensions and formats. Error was found using the `test_image_converter.py` file :o
…ignature - Program is non-operational Reorganized the project structure by moving `image_converter` and `image_collector` modules into a `src` directory, updating import paths accordingly. Removed `requirements.txt` as it is no longer needed in the current setup. Modified the `convert_image` function to include an `output_format` parameter, aligning with the updated `ImageConverter` class requirements. These changes improve code organization and functionality, ensuring compatibility with the new module structure and enhancing image conversion capabilities.
- Program is operational Added checks to verify the existence of output files before appending them to the converted images list in `process_images` function. This prevents potential issues with non-existent files being recorded as successfully processed. Additionally, updated the `ImageConverter` class to include `output_format` as an initialization parameter and adjusted logic to skip conversion if input and output formats are identical, providing a message instead. These changes enhance robustness and clarity in image conversion handling.
Updated test cases in `test_image_converter.py` to accommodate the additional format parameter in the `ImageConverter` class and `convert_image` function. This change ensures that the correct output format is specified during conversion, preventing unnecessary file creation when input and output formats are identical. Adjusted assertions to reflect these changes, particularly ensuring no new file is created when converting an image to the same format.
Updated test_image_converter.py to utilize context managers when opening files and images. This change ensures that resources are properly managed and closed, reducing the risk of resource leaks. The modifications include using 'with' statements for creating and opening images and files, enhancing code readability and reliability.
Migrated the project from using Poetry to PDM for package management. This involved updating the configuration files: replacing `pyproject.toml` with PDM-specific settings, adding a new `pdm.lock` file, and removing the old `poetry.lock`. The `.gitignore` was updated to include `.pdm-python`. The project name was changed from "image-type-converter" to "Formaverter", and the version was bumped to 2.0.0. Dependencies were adjusted to align with PDM's format, maintaining compatibility with Python 3.13 and Pillow 11.0.0. This change aims to streamline the build process and leverage PDM's features.
Moved source files from the 'src' directory to a new 'formaverter' package to improve project organization and modularity. Updated import statements in both source and test files to reflect the new package structure. This change enhances maintainability by clearly defining the scope of the formaverter module, making it easier to manage dependencies and future expansions.
Added `package-dir = "src"` to the [tool.pdm] section of pyproject.toml. This change specifies the source directory for packages, aligning with common project structures where source files are organized under a 'src' directory. This adjustment helps ensure that PDM correctly locates and manages the project's packages during build and distribution processes.
This commit introduces two new GitHub Actions workflows to the repository. The first workflow, `black.yml`, is set up to automatically format code using Black on pull requests targeting the main branch. It ensures consistent code style by running Black with color output on the source directory. The second workflow, `codeql.yml`, integrates CodeQL analysis into the CI process. It triggers on pull requests to the main branch and on a weekly schedule. This workflow is configured to analyze Python code, providing security and quality insights through automated code scanning. Additionally, the README has been updated to reflect changes in the project's description, features, installation instructions, usage examples, and development setup. The tool, now named Formaverter, focuses on image format conversion and includes detailed guidance for both command-line use and integration into other Python projects.
…e formatting Updated the import paths to reflect the new package structure, changing from 'src' to 'formaverter'. Improved code readability by reformatting long lines and ensuring consistent use of quotes. These changes enhance maintainability and align with Python's PEP 8 style guide. No functional changes were made, so existing functionality should remain unaffected.
Daethyra
added
enhancement
New feature or request
documentation
Improvements or additions to documentation
labels
Dec 15, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Feature Enhancements:
Code Refactoring:
Testing Improvements:
Project Structure and Dependencies:
Continuous Integration:
Overview
These changes collectively improve the project's functionality, maintainability, and development workflow. Adding WebP support and the image collector module expands and streamlines the tool's capabilities, while the refactoring and testing improvements enhance code quality and reliability.
Testing
To test these changes:
pdm install
to set up the environmentpython -m unittest ./tests/test_<select_test>
to run a testNote
Please review these changes as the entire project has been overhauled to fulfill my personal needs. Be sure to read the code before using it, and check out the README for guidance. Any feedback on the migration from Poetry to PDM and the new CI workflows is appreciated.