Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /trisongz_lazyops /src /lazyops /libs /jinja /helpers.py
| from __future__ import annotations | |
| """ | |
| Helpers | |
| """ | |
| import os | |
| import yaml | |
| import base64 | |
| import jinja2 | |
| from pathlib import Path | |
| from typing import Dict, Any, Optional, TYPE_CHECKING | |
| def to_yaml(data): | |
| """ | |
| Converts a dict to yaml | |
| """ | |
| return yaml.safe_dump(data) | |
| def to_base64(data: Dict[str, str]): | |
| """ | |
| Converts a dict to a base64 string | |
| """ | |
| return {k: base64.b64encode(v.encode('utf-8')).decode('utf-8') for k, v in data.items()} | |
| def from_env(envvar: str, default: Optional[str] = None) -> str: | |
| """ | |
| Returns the environment variable | |
| """ | |
| return os.getenv(envvar, default) | |
| def create_jinja_env( | |
| path: Path, | |
| **kwargs | |
| ) -> jinja2.Environment: | |
| """ | |
| Creates a jinja2 environment that adds | |
| filters and functions to the environment | |
| """ | |
| templates = jinja2.Environment( | |
| loader = jinja2.FileSystemLoader(path), | |
| **kwargs | |
| ) | |
| templates.filters['to_yaml'] = to_yaml | |
| templates.filters['to_base64'] = to_base64 | |
| return templates | |
Xet Storage Details
- Size:
- 1.02 kB
- Xet hash:
- 5534ec7b899de9b9ee9dd4969677eda84a057b165a325d73aa3c7148d46e2360
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.