TL;DR: Install my WSL-specific xdg-open replacement by following the instructions on the xdg-open-wsl github page.

Convert a Python script to a Python package with Poetry.

In my previous vxlabs post, I explained how to use Emacs lisp advising to fix buggy behaviour when opening Windows files from Emacs running on WSL.

In that post I mentioned my home-grown xdg-open replacement.

As I was writing that bit, I wondered how long it would take for the first astute reader to wonder about the mentioned script.

Sure enough, after two days the comment arrived, which was enough motivation to take the single-file script and upgrade it in the following ways:

  1. Add documentation.
  2. Write tests.
  3. Create a poetry configuration.
  4. Push to GitHub.
  5. Configure GitHub actions to run the tests automatically on each push and PR.

What I learned.

Long live Poetry.

Whilst a few months ago I did not think poetry was going to be able to fill the hole that pipenv (RIP) has left, going so far as to doubt seriously the single-focus mindset of its developer sdispater, I have come to realise that I was quite wrong.

sdispater took upon himself the exceptionally difficult task of saying “no” most of the time (also known as vision), but this has contributed substantially to the exceptional dependency management tool that poetry has become.

In the case of this simple package, it was a cinch setting up package metadata and dependencies, all in the single pyproject.toml.

From here anyone can setup a new development environment by doing poetry install.

I can build wheels and sdists by doing poetry build and publish to pypi (TBD) using poetry publish.

Thanks to PEP 517 and 518 support, users can install straight from github using a recent pip, no in sight.

Setting up GitHub actions for CI using poetry and pytest is straight-forward.

After having written some pytest tests, the skeleton of which poetry new your-new-package helpfully sets up for you, getting these tests to run automatically on github took only a few minutes of searching and then creating a .github/workflows/ci.yml file which uses the Python Poetry Action from the GitHub marketplace.