DEV Community

Namatuzio
Namatuzio

Posted on

New Features with Git Remotes

I decided to add a new feature to another open source project in the form of a TOML config functionality for a CLI app found here

How did coding the feature go?

After filing my issue I got to work. Adding such a functionality, especially in Python, was much easier than I had initially anticipated. I decided to use the tomllib library to help me parse TOML files instead of building a parser myself. However, because I was initially using Python 3.8.8, this meant that I had to upgrade my version to utilize the built-in version of tomllib in Python 3.11 or later. After updating everything I took a look at the codebase and eventually stumbled upon the perfect place to implement the functionality. The final solution to the issue was a very simple addition to what was already there. Simply checking for the -c or --config arg was enough to meet one requirement, which was to ignore all other args when this is used. After parsing everything, it could easily be sent through a function which would convert any text or md files to HTML files. The final implementation looked like this in the PR:

    if(args.config):
        with open(args.config, "rb") as f:
            try:
                config = tomllib.load(f)
            except tomllib.TOMLDecodeError as e: # If the TOML file is not formatted correctly, it will exit the program
                print(f"Error decoding TOML file: {e}")
                exit(-1)
            try:
                stylesheet = config["stylesheet"] or "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"
                output_dir = config["output"] or "./til"
                lang = config["lang"] or "en-CA"
            except KeyError as e: # If any of the keys are not found in the TOML file, it will exit the program
                print(f"Error: {e} not found in TOML file.")
                exit(-1)
            text_to_html(input_path, stylesheet, output_dir, lang)
Enter fullscreen mode Exit fullscreen mode

How was it using Git?

It wasn't too bad considering I've worked within a structure like this previously on a major capstone project where each member of my team had their own branch/fork to work off of. It was really nice learning about draft PRs though, I've never used them previously but they seriously are the best.

Someone ended up wanting to add the functionality to my repo, which was nice because it allowed me to have some experience testing remotes in order to make sure the functionality is up to spec, without committing everything to my repo.

What was learned?

I learned a lot more about the PR system as a whole, how useful remotes are, and how to easily test PRs through git remotes.

Top comments (0)