Skip to content

Review classes and types - Configuration vs. PathSpec vs. Path (pydantic to the rescue) #26

Closed

Description

@dannyadair

Notes to self: (this ticket might explode out into a handful of separate ones)

It's gotten messy.

  1. It's not 100% consistent what gets set as an instance attribute vs. getting looked up from the self.config dictionaries.
    Lazy load configs - should not be afraid of creating a PDFBakerDocument because it immediately tries to load a config file.

  2. There are types for typehints, and a PDFBakerOptions dataclass. Nothing really in terms of validating the YAML beyond its syntax. I'll go with Pydantic (2.11.3) and make these all BaseModel. That still serves the typehints but also adds validation when I instantiate with a value from YAML.

  3. Implement this top-down. Make the Baker nice, then proceed to Document, then Page.

  4. Images need special attention: Support full spec of name/path/type(/size?). Support multiple image directories. Support multiple image directories #24

  5. Absolute paths are not getting tested yet.
    (tests should just create a temporary config then use its absolute path as the starting point)

Working with PathSpec (name/path/etc.) and Path vs. string (from YAML) is a general issue and should be handled in exactly one place. Special logic ("just a name" for document means directory with config.yaml, for page means {name}.yaml inside "pages" directory) can be delegated to subclasses.

Activity

  1. dannyadair commented on Apr 25, 2025

    @dannyadair
    MemberAuthor

    After making a start in 563b726 on danny-pydantic
    the big commit for the full refactoring is 4f23218
    Still some way to go before this is ready to go live but it's about 90% there.

  2. dannyadair commented on Apr 28, 2025

    @dannyadair
    MemberAuthor

    Migration to pydantic models completed in 22e807a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions