topmark.utils.file¶
File utilities for TopMark.
This module contains small, dependency-free helpers for file/path handling and presentation logic shared across the CLI, API and core.
RebasedGlobPatterns
dataclass
¶
Result of rebasing glob-like patterns between directory anchors.
Attributes:
| Name | Type | Description |
|---|---|---|
patterns |
list[str]
|
Rebased glob patterns using POSIX-style separators. |
warnings |
list[str]
|
Non-fatal warnings encountered during rebasing. |
compute_relpath ¶
Compute the relative path from root_path to file_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The file path to compute the relative path for. |
required |
root_path
|
Path
|
The root path to compute the relative path from. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The relative path from root_path to file_path. |
Source code in src/topmark/utils/file.py
rebase_glob_patterns ¶
Rebase glob-like patterns declared relative to one base directory to another.
This is intended for presentation (e.g. topmark config dump) when configuration
patterns were declared relative to a config file directory (from_base) but we want to
display them as they would be interpreted from the current working directory
(to_base).
The transformation is best-effort
- Empty/whitespace-only patterns are skipped.
- Negation patterns starting with '!' keep their negation.
- Patterns starting with '/' are treated as "anchored to the base". During rebasing, the leading '/' is dropped and the pattern is re-anchored under the computed prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patterns
|
Iterable[str]
|
Input patterns (may include negation '!' and anchored '/' prefixes). |
required |
from_base
|
Path
|
The directory the patterns were originally intended to be relative to. |
required |
to_base
|
Path
|
The directory the returned patterns should be relative to. |
required |
Returns:
| Type | Description |
|---|---|
RebasedGlobPatterns
|
Structured rebasing result containing rebased patterns and any non-fatal warnings. |
Source code in src/topmark/utils/file.py
safe_unlink ¶
Attempt to delete a file, ignoring any errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Path to delete, or None (no-op). |
required |
Notes
- Any errors during deletion are logged and ignored.