Working with Git remotes and merging
Published: 2023-10-06 05:40:20

For this week in [Topics in Open Source Development](https://github.com/Seneca-CDOT/topics-in-open-source-2023) at [Seneca College](https://www.senecacollege.ca/home.html), I was tasked with:

- Adding a new feature to another student's repository
- Practicing working with `git fetch` and `git merge`

## Finding a new partner

For this lab, instead of working with my previous partner, I was asked to work with someone else for a change. I noticed my buddy [Bryce](https://github.com/bryce-seefieldt)'s project [ez-txt2html](https://github.com/bryce-seefieldt/ez-txt2html) was not yet worked on by anyone else. His version of our tool was written in Python - a language I've only had minimal experience working with. It looked like a great opportunity to work with that language so I decided to post an [issue](https://github.com/bryce-seefieldt/ez-txt2html/issues/21) to add this week's new feature.

While I was going through and playing with his code, I noticed it was missing a `.gitignore` file which made it cumbersome when VS Code kept trying to track some generated HTML files; I opened a separate [issue](https://github.com/bryce-seefieldt/ez-txt2html/issues/19) and [PR](https://github.com/bryce-seefieldt/ez-txt2html/pull/20) to address that.

## Introduction to TOML

[Lab 4](https://github.com/Seneca-CDOT/topics-in-open-source-2023/wiki/lab-4) asked us to add the ability to load [TOML](https://toml.io/en/) configuration files with pre-defined arguments to each others' projects. I had never heard of TOML, it's pretty neat! It reminded me of [YAML](https://yaml.org/) and its intent to be a human readable, simple, open-source alternative to JSON that was still widely used. It's pretty interesting how ubiquitous open-sourced standards and conventions can become in the global code space. I only worked with TOML a little bit for this lab and just barely scratched the surface (which I get into below). It looks like a standard `.ini` file but with fancy new features like keys, values, section headers, but with some interesting caveats like:
- A standardized datetime type
- Arrays
- Objects
- Tables

I will definitely look for ways to integrate TOML into my future projects and working with it more.

## Implementing the new TOML loading function

I looked over Bryce's code; all of the core functionality was on one `.py` file so that made things simple to understand. I added a new `-c/--config` argument to his `argparse` command line parser. I added a new TOML loading function which leverages the `tomllib` module. Again, its fantastic that this Python specific implementation of TOML exists and is open source. Best of all, it's natively integrated into Python 3.11 - no fuss, no muss. It's also fantastic that there's not just one implementation - there's also [pytomlpp](https://github.com/bobfang1992/pytomlpp) and [tomli](https://github.com/hukkin/tomli), pick your poison.

Here's my function:

```python
# Load arguments from a config file
def loadConfig(configPath):
    try:
        with open(configPath, "rb") as f:
            config = tomllib.load(f)
    except FileNotFoundError as e:
        raise Exception(f"Config file '{configPath}' could not be found.")

return config
```

Pretty simple stuff. I both catch and throw an exception if there's problems with loading the config file. I call this function in the main argument handling function and override the command line argument values.

I add a new sample `config.toml` file to play with.

```python
output = "./HTML"
```

This application does not yet implementing more options, so the TOML sample was accordingly simple; just an option to pre-define the output parameter. After testing and making sure it looked okay, I pushed a PR for Bryce.

## Feedback

Bryce accepted the PR, but did note that some more documentation would be ideal. I totally forgot to include the implementation details in the `README.md`, silly me. I added that soon after.

All in all, a fun little feature addition experience.

## Working with Git remotes and merging

Note: As of writing, I have not received a pull request for my application [til-to-html](https://github.com/paulkim26/til-to-html), sadly.

As this part of the lab is contingent on receiving a pull request from someone else to experiment with, I will update this section when I do.

Thanks for reading! See y'all next week.