Refactoring Turtmail Part 2
Refactoring is not just a way of life, it is the way of life.
tldr;
- Added GUI using Gooey to facilitate user interaction
- Operated it as a Windows Batch Script
Read Part 1 here
Gooey
Gooey is a python library that turns your command line program into a full GUI application.
For example:
python main.py xxx.xlxs --send-email yes
After Gooey-fying it:
User without technical know-how of what a command line will be able to interact with it now. Click browse to select file(s) from the file system, radio buttons for single choice questions, or free text fields. I was really mind-blown by this!
Windows Batch File
The Windows Batch file was the user's entry point into the system.
- Create a batch file (payslips.bat)
// payslips.bat
"C:\Users\xxx\venv\Scripts\python.exe" "path/to/payslips-mailer-runner.py"
TIP: Use where python
to get the path of python executable
2. Create entry-point for python
```python
# payslips-mailer-runner.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from payslip_mailer.payslip_mailer import main
import sys
if __name__ == '__main__':
sys.exit(main())
- Double click on the bat file, it'll run the script and open up the Gooey interface
Organise
Initially I wanted to package my application into a python wheel (executable), so I followed some best practices for that, including:
- Moving all services/classes into a python module (remove the src folder).
- Leave tests outside of that module
- Use setup-tools package to
Keep code clean
My choice of libraries to use to keep the code well formatted and coherent.
- Linting - Ruff
- Formatting - Black
- Test - Pytest and pytest-mocker
Conclusion
- Always good to have formatting and linting in place.
- Add more test coverage
- Refactoring more and frequently
Did you know this was built with 11ty and tailwind? And works even with Javascript disabled? Yeah I don't care either.