July 5, 2022

How f-strings Handle Double Curly Braces

Today I was about setting up a test case for parsing a YAML file which is templated with Jinja variables. Something like this… f""" pipeline: - test jobs: test: package-repositories: - type: apt url: "https://{{auth}}@example.org" """ My test case failed… My Pydantic model, which uses yaml.safe_load under the hood to load the above configuration, returned the URL, even before the value got replaced, as https://{auth}@example.org. One pair of the double curly braces was stripped away!...

May 18, 2022

Choosing Singular or Plural for Argument Names in Argparse

Naming is hard, right? Today I was extending an argparse based CLI application. I wanted to add an optional argument so that I can pass in environment variables. For this argparse has a special “action”, called append. From the argparse documentation: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='append') >>> parser.parse_args('--foo 1 --foo 2'.split()) Namespace(foo=['1', '2']) Awesome! Now I can access all the provided values as foo. Wait a moment Wait! This does not match....

May 10, 2022

How to Delete Documentation Hosted on pythonhosted.org

Today, I needed to lookup something in the documentation of lazr.config, which - you guessed it - is a configuration system, using an ini-like configuration file format. The number one search result on Google is still https://pythonhosted.org/lazr.config/. For projects on available on PyPI both wheels and packages are hosted on pythonhosted.org, and as it looks, at least before “my time” and before there was Read the Docs, also documentation was hosted on pythonhosted....

May 7, 2022

How to Render a Single ReStructuredText Document

Today I came across ubuntu-archive-tools which is a great set of scripts to help administer the Ubuntu archive. The project consists of Python scripts only, is not packaged, and the repository comes with no setup documentation. After I have figured out which dependencies the project needs, I wanted to add a minimal documentation, so the next user has an easier start. So, I created a README.rst, added some information… and huh, how would I render the file locally to make sure I have not messed up the syntax?...

April 24, 2022

How to Combine PDF Files on the Command Line

Without further ado… pdfunite in-file-1.pdf in-file-2.pdf outfile.pdf Simple as that. How to get pdfunite? I had it already installed as a dependency when I installed calibre, but you can also install it via… sudo apt install poppler-utils poppler-utils is a collection of PDF utils.

April 22, 2022

How to Cargo Install a Package With Additional Features

Meanwhile you may have heard that there are a couple of new CLI apps out there written in Rust - blazing fast and with additional features. While I rarely use them, as I do not want to get used to tools, which are not available on all Linux machines I work on, I do use ripgrep regularly, as it really makes a difference, especially in speed. Yesterday, I wanted to use ripgrep with PCRE2 (Perl Compatible Regular Expressions), but when I tried it, I got this error message:...

April 14, 2022

Highlight All Matches in Firefox

Modern browsers are pretty similar, so switching from Chrome to Firefox was no big issue… … except that when I searched something on a page with STRG + F / Ctrl + F, only the first match was highlighted. This was a major annoyance. Was? Yep. Turns out there are two ways to enable highlighting for all matches. Via Keyboard Shortcut In search mode you just need to hit Alt + A....

March 30, 2022

add-apt-repository Does Not Support Private PPAs

When you are a regular user of Ubuntu, you are probably familiar with the term PPA: Personal Package Archive Interlude Ubuntu offers packages via different package repositories ( Main, Universe, Restricted, Multiverse). Whenever you enter e.g. apt install <package> the mentioned repositories are queried. Though, while Ubuntu offers many packages, not all are available via apt. Also, for a given version of Ubuntu the packages usually only get security and bug fixes, but no version updates....

March 10, 2022

How to Update a Force Pushed Remote Branch

Imagine your colleague works on a new feature, and you have checked out their branch for a local review, and after an initial round of feedback and fixes, your colleague performs a git push --force to the remote branch. When you just do a git pull, you’ll end up in a mess like this… $ git pull remote: Enumerating objects: 19, done. remote: Counting objects: 100% (19/19), done. remote: Compressing objects: 100% (11/11), done....

February 7, 2022

How to Gracefully Rename a Command Line Argument in an Argparse Application

The CI runner I am currently working on can be used as follows: lpcraft run --output Now, what is output? A boolean? In the sense of “do create output”? A path to a directory? Something else? disambiguate --output can be used to specify a directory for the build artifacts. So, let’s rename it to --output-directory - problem solved. Yes, but what about all the users out there… argparse magic to the rescue We all know argparse is magic, and sometimes that even helps....