Skip to content

2020¤

Local HTTP server sending fake files for testing purposes

I have developed a Python client/library for aria2 called aria2p.

To test my code, I spawn aria2c processes to interact with them and see if everything works correctly. I know I could mock the calls, but I feel like actually testing the interaction between my client and aria2c is a better way to ensure my code does its best.

Until recently the test suite fed actual downloads to aria2c (like Linux distributions ISOs, metalinks, magnets, or torrents), but of course the inevitable happened: some URLs broke.

So I decided to go full local. This post describes my attempt at spawning local HTTP servers to serve fake/virtual files efficiently, files that are then fed to aria2c.

local http server fake files testing purposes

Passing Makefile arguments to a command, as they are typed in the command line.

In my Python projects, I use a combination of Duty (my task runner) and make.

My Makefile declares the same tasks as the ones written in duties.py, but in a generic manner:

TASKS = check test release

.PHONY: $(TASKS)
$(TASKS):
    @poetry run duty $@

So, instead of running poetry run duty check, I can run make check. Convenient, right?

Except that some duties (tasks) accept arguments. For example:

poetry run duty release version=0.1.2

So how do I allow the make equivalent?

make release version=0.1.2

Python packages and plugins as namespace packages

A user of mkdocstrings wrote a Crystal handler for their own use-case. They asked on the Gitter channel if we could allow to load external handlers, so they don't have to fork the project and install the fork, but rather just install their lightweight package containing just the handler.

We both saw Python namespace packages as good candidates, so I experimented a bit, and here are my conclusions.

How to edit the contents of a git commit

When you type change git commit or similar keywords in a search engine, you find many answers explaning how to rewrite a commit message, but not how to actually modify the contents of the commit.

This post quickly explains how to do that.

howto edit git commit contents

Migrate Disqus comments to Utterances (in GitHub issues) with Python

When I replaced Jekyll and my Jekyll-ReadTheDocs theme with MkDocs and a blog-customised version of the Material for MkDocs theme, the URLs of my posts changed.

I was using Disqus for comments, and they provide a way to migrate threads from old URLs to new URLs. Unfortunately, this time it didn't work for some reason (I had already done it once in the past and it worked fine).

I've read more and more criticism about Disqus related to privacy, so I looked at a replacement. The Disqus thread migration was not working so it was the perfect occasion!

I've read a few webpages and got interested in Isso. Unfortunately again, I did not manage to install it on my Raspberry Pi.

So I went with a much simpler solution: Utterances. You basically enable a GitHub app on your repository, add a script in your posts pages, and voilà: your new comment section powered by GitHub issues.

migrate disqus comments to utterances github

How to deal with spacing in Jinja2 templates

It started with a comment in a GitHub issue.

I often find it difficult to wrangle spacing jinja2 templates especially around optional clauses.

I couldn't wrap my head either about this. So I decided to write a script and test every combination of newlines, indentation and dashes or no dashes in {%-, with the goal being to find combinations that will not have an extra middle line when an optional Jinja clause is false.

Unify Python logging for a Gunicorn/Uvicorn/FastAPI application

I recently started playing with FastAPI and HTTPX, and I am deploying my app with Gunicorn and Uvicorn workers.

But when serving, the logs from each component looks quite different from the others. I want them to all look the same, so I can easily read them or exploit them in something like Kibana.

After a lot of hours trying to understand how Python logging works, and how to override libraries' logging settings, here is what I have...

unify logging for a gunicorn uvicorn app