June 13, 2024How to Detach Sessions From a TerminalWhen we do production deployments at my team at Canonical, we log into a bastion server and execute a long running command from there. Long running as of 30 minutes. The script goes through all our servers and deploys the latest changes. Needless to say that it would not be optimal when e.g. the connection dies during the deployment, as this would stop the deployment right in the middle. Hello terminal multiplexer Most engineers probably heard of tmux and screen before....
July 10, 2023Anonymous HyperlinksToday, I looked something up in our documentation, and noticed an unformatted link. `launchpad-mojo-specs <https://code.launchpad.net/launchpad-mojo-specs>` This is reStructuredText - a file format for structured data. While many people have switched to MarkDown, which is unarguably easier to read and write, I still like reStructuredText as it is very powerful. The above link does not get rendered as a hyperlink, as it misses a trailing underscore. I was about to add it, and directly commit, but luckily I tried to render it first....
February 12, 2023Multiline Commit Messages With `git commit -mWhen you execute git commit on the command line, your specified editor opens and you can create an expressive title and a longer description. That is probably nothing new. You are probably also aware of the shortcut git commit -m <message>, which skips the step with the editor. But there is only room for the title, right? Nope, this is not true. one way It turns out you can use -m multiple times....
October 24, 2022How to Update CargoToday I saw a Tweet by Marius Gedminas, who wrote about lfs, a replacement for df. It is one of the many tools, implemented in Rust, which offer some more features compared to their bash alternatives. What about no When I tried to install it, I just saw the following error message: ❯ cargo install lfs Updating crates.io index Downloaded lfs v2.6.0 error: failed to parse manifest at `/home/jugmac00/.cargo/registry/src/github.com-1ecc6299db9ec823/lfs-2.6.0/Cargo.toml` Caused by: feature `strip` is required The package requires the Cargo feature called `strip`, but that feature is not stabilized in this version of Cargo (1....
September 30, 2022How to Apply Git Log and Git Grep Only for a Specific File TypeToday I wanted to check how the UPDATE statement was used in already deleted SQL patch files. Usually I do a git log -p and then use the interactive search in less via /, but in this case there were too many hits from Python files, so I wanted to restrict my search to SQL files only. Turns out you can pass in the file type via … git log -p -- '*sql' And then use the interactive search....
July 5, 2022How f-strings Handle Double Curly BracesToday 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, 2022Choosing Singular or Plural for Argument Names in ArgparseNaming 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, 2022How to Delete Documentation Hosted on pythonhosted.orgToday, 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, 2022How to Render a Single ReStructuredText DocumentToday 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, 2022How to Combine PDF Files on the Command LineWithout 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.