Skip to content

Instantly share code, notes, and snippets.

View pedro-psb's full-sized avatar

Pedro Brochado pedro-psb

View GitHub Profile
@pedro-psb
pedro-psb / pulpproject_org_blog_fix.py
Created June 10, 2024 19:19
Sanitize pulpproject.org posts so they can work with mkdocs-material blog plugin
import re
from pathlib import Path
def read_files():
return list(Path("staging_docs/sections/blog/posts/").glob("*.md"))
def fix_blog_posts():
"""
Problems:
* add heading zero to filenames missing it: yyyy-mm-d
* delete "- date:" lines from frontmatter
@pedro-psb
pedro-psb / dynaconf_typing_experiment.py
Created May 15, 2024 23:31
Small experiment with adding Schema typing workaround for Dynaconf. https://github.com/dynaconf/dynaconf/issues/1082
import typing as t
from dataclasses import dataclass, is_dataclass
# not strictly necessary, but makes sense
T = t.TypeVar("T") # https://mypy.readthedocs.io/en/stable/generics.html
class ValidationError(ValueError):
...
@pedro-psb
pedro-psb / convert-changelog-rst-md.sh
Created March 15, 2024 19:35
This script creates a CHANGES.md file converted from an rst file and perform characteristic cleanups.
#/bin/bash
# https://gist.github.com/zaiste/77a946bbba73f5c4d33f3106a494e6cd
FILENAME="CHANGES"
pandoc "$FILENAME.rst" -f rst -t markdown -o "$FILENAME.md"
# quotes: \"hupper\" -> "hupper"
sed -i "$FILENAME.md" -e 's/\\\("[a-zA-Z_-]*\)\\"/\1"/g'
# github: `4976`{.interpreted-text role="github"} -> [4976](https://github.../issues/4976)
@pedro-psb
pedro-psb / clean-conversion.sh
Created February 6, 2024 16:29
Create pulp-docs structure, convert to markdown and do some conversion cleaning
#!/bin/bash
# 1. create structure
mkdir -p \
staging_docs/{admin,user,dev}/{guides,tutorials,learn} \
staging_docs/reference
cp -r docs tmp_docs
# 2. convert to rst->markdown (optional)
pip install rst-to-myst[sphinx]
find tmp_docs -name '*.rst' -exec rst2myst convert --replace-files {} ';'
@pedro-psb
pedro-psb / sff_loader.py
Last active March 13, 2023 19:29
dynaconf: custom loader boilerplate example #750
from __future__ import annotations
from io import TextIOWrapper
from typing import Callable, TypeAlias
FileParser: TypeAlias = Callable[[TextIOWrapper], dict[str, str]]
def load_data(obj, file_parser: FileParser, extensions: tuple[str, ...], **kwargs):
"""
@pedro-psb
pedro-psb / config.py
Last active March 8, 2023 14:49
#879 [bug] dynaconf validate not working with dynaconf_validators.toml
from dynaconf import Dynaconf
settings = Dynaconf(
envvar_prefix="DYNACONF",
settings_file="settings.toml",
environments=True,
)