DEV Community

Greg Brimble
Greg Brimble

Posted on • Originally published at Medium

My First Attempt at Open-Source

Last night, I made my first contribution to an existing open-source repository: yattag. It's a small Python project (4 project files, 12 pull requests, and 5 contributors), but I have used it in a couple of projects of mine, and quite like the way it works. Basically, it generates HTML on the fly:

>>> from yattag import Doc
>>> doc, tag, text = Doc().tagtext()
>>> scripts = ["jquery.js", "customJS.js"]
>>> with tag("html"):
...     with tag("head"):
...         for script in scripts:
...             with tag("script", src=script):
...                 pass
>>> print(doc.getvalue())
        <script src="jquery.js"></script>
        <script src="customJS.js"></script>

Anyway, there is a method, stag, which generates an element without an end tag (e.g. doc.stag("br") will generate <br />). However, this doesn't really fit with some of the newer HTML5 stuff: according to W3C, these types of tags shouldn't have a closing slash (/) (e.g. <br /> should be <br>).

So, queue my two-line change (+1 extra where I spotted a typo). I inspected all the other files in the repo to see if they referenced the stag method (would the need any examples updated etc.), and I checked the tests file for any checks that would fail (were they comparing the output of doc.stag("test") to the string <test /> etc.), but it all looked good.

Honestly for the time it took me to work out all the git commands and not have my editor remove all the whitespace, the change really wasn't worth making. The old HTML is still read perfectly fine by browsers (and will be, forever). The old style, really isn't going anywhere.

Anyway, I clicked the button: PR made. Checks spun up. And 2 minutes 35 seconds later, the build failed. I had missed a part of the test. It took the output and passed it to a XML parser, and then checked the attributes etc. XML is notorious for its requirement of strict adherence to its grammar templates, so when it couldn't parse the non-XML-compliant tag, the test failed.

Build Failure

Commit Failure

My Failure

Turns out (upon reading the…), this project can be used to generate either XML or HTML, so that closing slash really did need to be kept there. Oops.

So, there we have it: my first clash with Travis; the first, forever red, cross against my name on the internet; and My First Attempt at Open-Source.

Lessons Learnt

  • Before anything else, read the description of the repository you are editing.
  • Don't embarrass yourself on the internet, Greg. Run the tests locally first.
  • Write more Medium posts (this was my first, be nice)!

Discussion (0)