DEV Community

Paul Kim
Paul Kim

Posted on

Working with Git remotes and merging

For this week in Topics in Open Source Development at Seneca College, 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's project 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 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 and PR to address that.

Introduction to TOML

Lab 4 asked us to add the ability to load TOML 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 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 and tomli, pick your poison.

Here's my function:

# 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
Enter fullscreen mode Exit fullscreen mode

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.

output = "./HTML"
Enter fullscreen mode Exit fullscreen mode

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, 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.

Top comments (0)