Skip to content
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

Merged
merged 20 commits into from
Dec 15, 2024
Merged

overhaul(formaverter): recreated project from scratch #20

merged 20 commits into from
Dec 15, 2024

Conversation

Daethyra
Copy link
Owner

@Daethyra Daethyra commented Dec 15, 2024

Changes

  1. Feature Enhancements:

    • Added WebP support to expand the range of supported image formats.
    • Implemented an image collector module to facilitate batch processing of images.
    • Streamlined the main image conversion process for improved efficiency.
  2. Code Refactoring:

    • Refactored the conversion logic in the image_converter module for better maintainability.
    • Removed redundant format argument in the save method to simplify the conversion process.
    • Reorganized imports and updated function signatures for cleaner code structure.
    • Ensured file existence checks before appending to lists to prevent potential errors.
  3. Testing Improvements:

    • Added unit tests for both the image collector and image converter modules.
    • Updated existing tests to accommodate new conversion parameters.
    • Refactored tests to use context managers for file and image handling, improving resource management.
  4. Project Structure and Dependencies:

    • Migrated from Poetry to PDM for dependency management.
    • Added pyproject.toml for modern Python packaging.
    • Created a poetry.lock file (now replaced by pdm.lock) to lock dependencies.
    • Reorganized the src directory into a dedicated 'formaverter' package for better modularity.
    • Removed unused files and the archive directory to clean up the project structure.
    • Removed test pictures to reduce repository size.
  5. Continuous Integration:

    • Added GitHub Actions workflows for Black (code formatting) and CodeQL (code quality and security analysis).

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:

  1. Clone the updated repository
  2. Run pdm install to set up the environment
  3. Execute python -m unittest ./tests/test_<select_test> to run a test

Note

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.

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 Daethyra self-assigned this Dec 15, 2024
@Daethyra Daethyra added enhancement New feature or request documentation Improvements or additions to documentation labels Dec 15, 2024
@Daethyra Daethyra merged commit 80efbe2 into main Dec 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant