Posts tagged: python
All posts with the tag "python"
nless is a seriously sick tui for exploring streaming data. It makes it seriously simple to pivot (U), drill in (Enter), sort (s). It leave breadcrumbs as you go and you can press q to back out.
Play with your kubernetes events. Ya, my homelab is far from perfect, dont judge.
kubectl get events -A -w | uvx --from nothing-less nless
I really wish I would have got this right a few years ago. Theres a couple of flags I had to use to get mdformat to do hard wraps at 80 characters and not wreck tables. This mix of flags and plugins is workign really well for me so far.
mdfmt() {
uvx \
--with "mdformat-ruff" \
--with "mdformat-beautysh" \
--with "mdformat-web" \
--with "mdformat-config" \
--with "mdformat-gfm" \
--with "mdformat-front-matters" \
--with "mdformat-wikilink" \
--with "mdformat-simple-breaks" \
mdformat \
--wrap 80 \
--end-of-line lf \
--codeformatters python \
--codeformatters bash \
"$@"
}
And as pre-commmit.
repos
- repo: https://github.com/hukkin/mdformat
rev: 1.0.0 # pin to the version you want
hooks:
- id: mdformat
args:
- --wrap
- "80"
- --end-of-line
- lf
- --codeformatters
- python
- --codeformatters
- bash
additional_dependencies:
- mdformat-ruff
- mdformat-beautysh
- mdformat-web
- mdformat-config
- mdformat-gfm
- mdformat-front-matters
- mdformat-wikilink
- mdformat-simple-breaks
My First Agentic Workflow
Dont Trust Users Tokens
Characters
Og-Sample
I Think I Built A Cms
One Year Of Shots
Workspaces V1
setting COLUMNS env var to a number greater than 0 will make the terminal resize to that number of columns.
COLUMNS=80 uvx --from rich-cli rich myscript.py
Note
Not all programs respct the COLUMNS env var, but rich does, and a lot of
stuff I’m building uses rich.
I discovered this when I was trying to make a low effort readme generated from the code, but did not depend on the size of terminal it was ran on.
# justfile
readme:
echo "# Workspaces" > README.md
echo "" >> README.md
echo '``` bash' >> README.md
COLUMNS=80 ./workspaces.py --help >> README.md
echo '```' >> README.md
Today I learned how to use AliasChoices with pydantic settings to setup common aliases for the same field. I’m bad about remembering these things, and hate looking up the docs. I like things to be intuitive and just do the thing I want it to do. Especially when they get configured through something like yaml and do not have a direct lsp look up right from my editor. I figured out how to support what might be common aliases for a storage directory. These can be set up as environment variables and used by config.
from pathlib import Path
from pydantic import Field
from pydantic import AliasChoices
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
storage_dir: Path | None = Field(
default=None,
validation_alias=AliasChoices(
"STORAGE_DIR", "STORAGE_DIRECTORY", "STORAGE_PATH", "STORAGE_PATHNAME",
"DROPPER_STORAGE_DIR", "DROPPER_STORAGE_DIRECTORY", "DROPPER_STORAGE_PATH", "DROPPER_STORAGE_PATHNAME",
),
description="Directory for stored files",
)
Mcat Anything
Missing Thoughts
I often want to run an s3 sync in an isolated environment, I don’t want to set
any environment variables, I don’t want anything secret in my history, and I
don’t want to change my dotenv into something that exports variables, I just
want s3 sync to work. dotenv run is the tool that I’ve been using for this,
and this uv one liner lets it run fully isolated from the project.
one liner #
uv tool run --from 'python-dotenv[cli]' dotenv run -- uv tool run --from awscli aws s3 sync s3://bucket data
multi-line #
same thing formatted for readability
uv tool run \
--from 'python-dotenv[cli]' \
dotenv run -- \
uv tool run \
--from awscli \
aws s3 sync s3://dropper data
There are probably 10 ways to skin this cat, but this is what I did, if you have a better way let me know, I’ll link you below.
