Skip to content

Support pathlib.Path objects for file paths #65

@Brekkjern

Description

@Brekkjern

This has become a fairly common pattern in my setup:

from decman import Module, File
from pathlib import Path

files = Path(__file__).parent / "files"

class MyModule(Module):
    def files(self) -> dict[str, File]:
        return {
            str(var.user_config / "systemd" / "user" / "some_service.service"): File(
                source_file=str(files / "some_service.service"),
                owner=var.username, permissions = 0o644)
        }

Having to convert both the key for the files dictionary and the source_file to a string is somewhat unergonomic. Being able to just pass pathlib.Path objects directly as keys or values for the decman.File constructors would be cut down on a bit of boilerplate, plus it would make the signature clearer on what the string is supposed to be for.

Using a bit new syntax here, but something like this?

type filepath = str | pathlib.Path

class Module:
    def files(self) -> dict[filepath, File]: ...

I'm wondering if you see any immediate issues with attempting this before I start delving into the code myself for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions