TOML Config
For this week I continued contributing to my classmate's project. The new feature that I worked on was designed to allow the user to include all their optional arguments in a TOML config file and run the program with those configurations when transforming a text or a markdown file into HTML. Since the code-base for the project was in Python I found the tomlib module to use for reading and parsing a Toml file.
Process
- I created an issue to explain the changes and the goal of the feature.
- I created a new branch for the feature after I got the approval from the owner and started working on the implementation.
- I wrote the code for the program to accept -c or --config as an optional argument when running the program, so that the user can provide the path to a TOML config file in addition to the path of the file(s) they want to convert to html.
- I went over the documentation for the tomlib module and understood how it worked. After reading a TOML file, the tomlib module returns a dictionary of key value pairs from the config file. So I used the keys that the program supported to retrieve their values, which were lang/l for custom language input and output/o for a custom output directory. I also made sure that if there were no values for those two keys in the TOML file, the default values were used.
- I coded the error handling and made sure that the program exited with a proper error message and code.
- After I finished implementing the feature, I tested all the possible scenarios and made sure that the feature functioned correctly and that it didn't break all the existing functionalities.
- Since the changes and the code added were small I only made a single commit and pushed the changes to the branch.
- I created a pull request where I explained the changes and how they functioned.
- I received feedback about the changes I had made from the owner. He was satisfied with the changes and asked me to update the help message and the README to reflect the new TOML support and also fix a bug that was causing issues when checking for file extensions.
- I made all the changes that were raised in the feedback and pushed them to update the pull request.
- The project owner accepted the pull request after reviewing it and merged the changes.
Problems
I didn't run into any issues working on this feature. The only thing is that, I need to remember to update the documentation (README), whenever I add new features to a project. I also missed out on a bug during my testing, but fortunately the project owner caught it and asked me to fix it in his feedback.
What I learned
I've never used a TOML configuration file before, so it was cool to experience that for the first time and learn about how all the configurations can be grouped together. I also learned how to work with the tomlib module to read and parse a TOML file in Python.
Top comments (0)