We updated our Morphi internationalization library to work with modern Python packaging standards, transitioning from setup.py to pyproject.toml using Augment Code’s chat mode. This approach saved hours of manual configuration work while ensuring our translation tools continue to function smoothly across all our projects.
As a consulting shop, we get to work on many different apps and projects. Most of those, we get to start from scratch - meaning we get to drive the selection of tools and framework. Having a common stack of libraries across the board helps maintain a desired level of efficiency across all of those projects.
One of those libraries is Morphi. It provides packaged internationalization (i18n) services and helpers for libraries and applications.
Morphi abstracts all of the configuration needed for the app, using gettext, setting up Jinja templates, and so on. It also has a CI helper that checks to see if all marked strings have corresponding translations for a locale.
Modernizing Morphi with pyproject.toml
As the Python landscape has shifted from setup.py package setup to pyproject.toml, Morphi has been left behind.
Morphi used setup.py commands to refer to Babel for updating/compiling catalogs. We had an additional command for compiling a JSON file based on the catalog, also set up as a setup.py command.
To bring Morphi into the new era, I wanted to take the same configuration I have had in setup.cfg, move it to pyproject.toml, and update my translation-checking procedure to use it appropriately.
Leveraging AI for the Solution
While that process would have been fine to work through getting all of the CLI options right for pybabel, I supposed that it would have been faster to use some AI code generation.
For my tooling, I'm using Augment Code in VSCode. Augment Code has an agent mode, but I have found it to be inferior to its chat mode for general usage. So, I simply started prompting the chats and allowing Augment Code's gathering of context to assist.
The Prompting Process
For starters, I assumed general ignorance just to see what the bot would propose:
What would I need to change in the Morphi library to run check_translations when a project does not have setup.py? Do the Babel commands work with pyproject.toml?
Immediately, Augment suggested modifying the method so that it would work with either setup.py or pyproject.toml.
This is ideal for a library where we don't want to be very opinionated about how a consuming app is constructed. But it didn't pick up on the idea of putting the Babel config itself in pyproject.toml.
I could see that as a sign to start being ultra-specific about my prompting. But what I've found with Augment Code is that I can continue chatting with low-pressure prompts to guide it toward a desired solution:
I want to use the settings I've defined in pyproject.toml for each step.
Then it figured it out: I wanted identical settings to the ones we used for setup.py. To do this, it generated a solution using the Tomli library to read pyproject.toml and gather the needed configuration.
Handling JSON Compilation
One thing got left out: JSON compilation. This is an extra that Morphi layers over the baseline Babel tools, useful for referring translations to a place where they can easily be used via JavaScript. But Augment Code didn't get the memo on that part, likely because it was not in its context.
To move it forward, I added Morphi’s source code to the context manually in settings then prompted again:
To compile JSON, the Morphi library uses Morphi.messages.frontend:CompileJson.
Again, a simple prompt, and then the bot knew how to fill in the section it had stubbed out for that command.
Testing and Implementation
After setting all of this up, I ran the newly formed check on a project to make sure all of the pieces worked. I didn't really need to make any manual adjustments in this case other than to update Morphi's dependency list with the Tomli library.
Now, we can confidently move our translated apps forward to the new package structure.
You can access our Morphi GitHub repository here.