umpyre.storage#
Storage operations for metrics.
Functions
|
Serialize metrics to file. |
|
Deserialize metrics from file. |
|
Parse metric filename into components. |
|
Find metrics file for a specific commit. |
|
Find all metrics files for a specific PyPI version. |
|
Get the most recent metrics file for a version. |
|
Get all unique PyPI versions found in metrics. |
|
Get metrics files within a date range. |
Classes
|
Store metrics in a separate git branch. |
Exceptions
Raised when git branch storage operations fail. |
- class umpyre.storage.GitBranchStorage(repo_path, remote='origin', *, token=None)[source]#
Bases:
objectStore metrics in a separate git branch.
This provides versioned, branch-based storage without polluting the main branch or requiring external artifacts.
Example
>>> storage = GitBranchStorage(repo_path="/path/to/repo") >>> metrics = {"lines": 100, "functions": 10} >>> storage.store_metrics(metrics, "abc123", branch="code-metrics")
- exception umpyre.storage.GitBranchStorageError[source]#
Bases:
ExceptionRaised when git branch storage operations fail.
- umpyre.storage.deserialize_metrics(file_path, format='json')[source]#
Deserialize metrics from file.
- umpyre.storage.filter_by_date_range(history_dir, start_date=None, end_date=None)[source]#
Get metrics files within a date range.
- Parameters:
- Return type:
- Returns:
List of paths within date range (sorted chronologically)
Example
>>> from datetime import datetime, timedelta >>> end = datetime.now() >>> start = end - timedelta(days=7) >>> recent = filter_by_date_range(Path("history"), start, end) >>> print(f"Found {len(recent)} metrics from last 7 days")
- umpyre.storage.find_metrics_by_commit(history_dir, commit_sha)[source]#
Find metrics file for a specific commit.
- Parameters:
- Return type:
- Returns:
Path to metrics file or None
Example
>>> metrics = find_metrics_by_commit(Path("history"), "700e012") >>> print(metrics.name) 2025_11_14_22_45_00__700e012__0.1.0.json
- umpyre.storage.find_metrics_by_version(history_dir, version)[source]#
Find all metrics files for a specific PyPI version.
- Parameters:
- Return type:
- Returns:
List of paths (sorted by timestamp, latest first)
Example
>>> metrics = find_metrics_by_version(Path("history"), "0.1.0") >>> for m in metrics: ... print(m.name) 2025_11_14_22_50_00__abc1234__0.1.0.json 2025_11_14_22_45_00__700e012__0.1.0.json
- umpyre.storage.get_all_versions(history_dir)[source]#
Get all unique PyPI versions found in metrics.
- Parameters:
history_dir (
Path) – Path to history directory- Return type:
- Returns:
Sorted list of versions (excluding ‘none’)
Example
>>> versions = get_all_versions(Path("history")) >>> print(versions) ['0.1.0', '0.1.1', '0.2.0']
- umpyre.storage.get_latest_metric_for_version(history_dir, version)[source]#
Get the most recent metrics file for a version.
- Parameters:
- Return type:
- Returns:
Path to latest metrics file or None
Example
>>> latest = get_latest_metric_for_version(Path("history"), "0.1.0") >>> info = parse_metric_filename(latest.name) >>> print(f"Latest 0.1.0 metrics from {info['timestamp_str']}")
- umpyre.storage.parse_metric_filename(filename)[source]#
Parse metric filename into components.
- Parameters:
filename (
str) – Filename like “2025_11_14_22_45_00__700e012__0.1.0.json”- Returns:
- {
“timestamp”: datetime object, “timestamp_str”: “2025-11-14T22:45:00”, “commit_sha”: “700e012”, “pypi_version”: “0.1.0” or None, “has_version”: bool,
}
- Return type:
Example
>>> info = parse_metric_filename("2025_11_14_22_45_00__700e012__0.1.0.json") >>> info['commit_sha'] '700e012' >>> info['pypi_version'] '0.1.0'
- umpyre.storage.serialize_metrics(data, output_path, format='json')[source]#
Serialize metrics to file.
Modules
JSON and CSV serialization for metrics. |
|
Git branch-based storage operations. |
|
Helper utilities for working with umpyre metrics storage. |