Classes
PathResolver
Centralized path resolution utility.
All paths resolved relative to a fixed base (site root).
Elim…
PathResolver
Centralized path resolution utility.
All paths resolved relative to a fixed base (site root). Eliminates CWD-dependent behavior across the codebase.
Attributes
| Name | Type | Description |
|---|---|---|
base |
— | Absolute base path for resolution |
Methods 6
resolve
Resolve path to absolute, relative to base.
If path is already absolute, retur…
resolve
def resolve(self, path: str | Path) -> Path
Resolve path to absolute, relative to base.
If path is already absolute, returns it unchanged. If path is relative, resolves it relative to self.base.
Parameters 1
path |
str | Path |
Path to resolve (absolute or relative) |
Returns
Absolute pathPath
—
resolve_many
Resolve multiple paths.
resolve_many
def resolve_many(self, paths: list[str | Path]) -> list[Path]
Resolve multiple paths.
Parameters 1
paths |
list[str | Path] |
List of paths to resolve |
Returns
List of absolute pathslist[Path]
—
resolve_if_exists
Resolve path and return only if it exists.
resolve_if_exists
def resolve_if_exists(self, path: str | Path) -> Path | None
Resolve path and return only if it exists.
Parameters 1
path |
str | Path |
Path to resolve |
Returns
Absolute path if exists, None otherwisePath | None
—
is_within_base
Check if a path is within the base directory.
Useful for security checks to pr…
is_within_base
def is_within_base(self, path: str | Path) -> bool
Check if a path is within the base directory.
Useful for security checks to prevent path traversal attacks.
Parameters 1
path |
str | Path |
Path to check (will be resolved first) |
Returns
True if resolved path is under base directorybool
—
relative_to_base
Get path relative to base.
relative_to_base
def relative_to_base(self, path: str | Path) -> Path
Get path relative to base.
Parameters 1
path |
str | Path |
Path to make relative (resolved first) |
Returns
Path relative to basePath
—
from_site
classmethod
Create resolver from site instance.
from_site
classmethod def from_site(cls, site: Site) -> PathResolver
Create resolver from site instance.
Parameters 1
site |
Site |
Site instance (uses site.root_path as base) |
Returns
PathResolver with site root as basePathResolver
—
Internal Methods 2
__init__
Initialize resolver with absolute base path.
__init__
def __init__(self, base: Path) -> None
Initialize resolver with absolute base path.
Parameters 1
base |
Path |
Base path for resolution (will be resolved to absolute) |
__repr__
__repr__
def __repr__(self) -> str
Returns
str
Functions
resolve_path
Convenience function to resolve a single path.
For one-off resolutions without creating a resolver…
resolve_path
def resolve_path(path: str | Path, base: Path) -> Path
Convenience function to resolve a single path.
For one-off resolutions without creating a resolver instance.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
path |
str | Path |
— | Path to resolve |
base |
Path |
— | Base path for resolution |
Returns
Absolute pathPath
—