Refactor/split utilities - #186
Open
bigglezworthe wants to merge 30 commits into
Open
Conversation
Contributor
Author
|
2 tests failing in |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Utilities Split Refactor
Purpose
This branch refactors the original
utilities.pymodule into smaller, purpose-specific modules contained insrc/.The goal is to improve maintainability and make future changes easier by separating unrelated functionality while preserving existing behavior.
This refactor is primarily architectural. It is not intended to change the output of generated PDFs or alter the behavior of card creation.
Scope
Included
src/page_manager.pyandenums.pyintosrc/Intentionally Not Included
page_manager.pypage_manager.pyremains responsible for page-level generation and registration mark handling. Any future architectural changes involving page management should be handled separately.New Module Organization
src/paths.pyResponsible for project paths and filesystem-related helpers.
Examples:
src/pdf.pyResponsible for PDF generation workflows.
Examples:
src/layouts.pyResponsible for loading and working with layout definitions.
Examples:
Note:
Layout responsibilities overlap with PDF generation and page management because layouts define the geometry used when placing cards.
src/images.pyResponsible for general image manipulation.
Examples:
src/crop.pyResponsible for image cropping operations.
This module currently contains a small number of tightly related functions.
Future consolidation into
images.pymay be considered if cropping functionality remains small.src/draw.pyResponsible for drawing operations.
Examples:
Some overlap exists with
images.pybecause SCM creates pages by manipulating images rather than drawing directly to a PDF canvas.src/offset.pyResponsible for saved image offsets.
Examples:
src/measurements.pyResponsible for measurement parsing and unit conversion.
Examples:
3mmor0.125insrc/enums.pyContains shared enumerations.
Examples:
Source Roadmap
The refactor reorganizes the previous monolithic
utilities.pymodule into focused modules undersrc/. This roadmap lists the current ownership of constants, classes, and functions after the split.This is intended as a guide for reviewers and future contributors. Some internal implementation details may continue to move as the project evolves.
src/draw.pyFunctions
draw_card_with_bleeddraw_card_layoutdraw_card_layoutsdraw_outlinedraw_outlinessrc/enums.pyClasses
RegistrationOrientationOrientationModeVariantUnitFitModesrc/images.pyConstants
MINIMUM_BLEEDFunctions
calculate_max_print_bleedfill_rounded_cornersload_card_imageconvert_inch_to_cropparse_dimension_stringparse_crop_stringcrop_and_scale_imagesrc/layouts.pyConstants
CUTTING_TEMPLATES_DIR_ENVEXTRA_LAYOUTS_ENVEXTRA_LAYOUTS_PATHLAYOUTS_FILENAMELAYOUTS_PATHClasses
RegistrationSettingsVariantRegistrationSettingsDefaultSettingsCardSizeDefPaperSizeDefCardLayoutSpecialtyCardSizeDefSpecialtyPaperSizeDefSpecialtyLayoutDefLayoutConfigFunctions
extra_layout_pathsfind_extra_layout_ownermerge_extra_layoutsresolve_cutting_templates_dirresolve_card_size_aliasresolve_paper_size_aliasget_all_card_size_namesget_all_paper_size_namesget_all_specialty_layout_namesload_layout_configbiased_sortbiased_sortis currently retained as a layout-related helper. It may be relocated in a future cleanup if a more general utility module is introduced.src/measurements.pyConstants
MM_PER_INCHPT_PER_INCH_UNIT_PATTERNFunctions
parse_unit_stringsize_to_mmsize_to_insize_to_ptsize_to_pixelsrc/offset.pyConstants
DATA_PATHOFFSET_DATA_PATHClasses
OffsetDataFunctions
save_offsetload_saved_offsetoffset_imagessrc/page_manager.pyConstants
BORDERLESS_EXPANSION_MMBORDERLESS_INSET_MMMAX_REG_INSET_MMMAX_REG_LENGTH_MMMAX_REG_THICKNESS_MMMIN_REG_INSET_MMMIN_REG_LENGTH_MMMIN_REG_THICKNESS_MMREG_PADDING_MMClasses
CardLayoutFunctions
generate_reg_marknormalize_page_sizecompute_grid_fitselect_best_marginscompute_card_positionsgenerate_layoutsrc/paths.pyConstants
RELATIVE_ROOTVALID_MIMETYPESClasses
PathsFunctions
check_paths_subsetdelete_hidden_files_in_directoryget_directoryensure_directoryensure_output_directory_existsget_image_file_pathsget_back_card_image_pathresolve_image_with_any_extensionsrc/pdf.pyFunctions
create_template_nameadd_front_back_pagesfind_best_orientationgenerate_pdfKnown Boundary Areas
Some responsibilities intentionally remain somewhat flexible because of how SCM operates.
PDF vs Images
SCM does not directly place images onto a PDF canvas. Instead:
Because of this, responsibilities between
pdf.py,draw.py, andimages.pyoverlap.Layouts vs Page Generation
Layouts define where cards belong, but page generation determines how those positions are used.
Some layout calculations currently interact with:
layouts.pydraw.pypdf.pypage_manager.pyFurther separation may require a larger redesign beyond the scope of this refactor.
Enums
All enums are currently placed in
enums.pydespite logical associations.Constants remain in their associated file locations.
Review Notes
This branch intentionally favors a conservative architectural split over a complete redesign.
The priority is:
Future Work
Potential future improvements:
str/Pathusage to consistentPathusageAI Disclaimer
AI assistance was used in this refactor, including the generation of this document. All of the code was typed by hand (even the code directly copied from
utilities.py) to help me better understand the project as a whole. ChatGPT was primarily used to assist with naming conventions and identifying modernization methods. For example, we had a riveting discussion on what to name thePathsclass, whether it should even be a class, and what the scope of its content should be. Super exciting stuff.