My First Attempt at Open-Source
Published: 2017-03-17 13:16:28

---
title: "My First Attempt at Open-Source"
published: true
description: "I tried...
A first and heroic but ultimately, unsuccessful attempt at contributing to an open-source project."
tags: 
canonical_url: https://medium.com/@gregbrimble/my-first-attempt-at-open-source-a9799d31c66b
---

Last night, I made my first contribution to an existing open-source repository: [yattag](https://github.com/leforestier/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())
<html>
    <head>
        <script src="jquery.js"></script>
        <script src="customJS.js"></script>
    </head>
</html>
```
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](https://www.w3.org/TR/html5/text-level-semantics.html#the-br-element), 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)](https://github.com/leforestier/yattag/pull/30/commits/df4d3be1b395458efb121cbb0fa87f101397ac94). I inspected all the other files in the repo to see if they referenced the `stag` method (would the `README.md` 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](https://github.com/leforestier/yattag/pull/30/commits/6a935bcad12cb028d69db885a24008371ea157ec), **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](https://travis-ci.org/leforestier/yattag/builds/211962336)**. 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](https://cdn-images-1.medium.com/1*thn0YoMDLOpeg_kN4FzaQw.png "Build Failure")

![Commit Failure](https://cdn-images-1.medium.com/1*gHEzjXVTz00U2aOIowo21w.png "Commit Failure")

_My Failure_

Turns out (upon reading the `README.md`…), 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~~](https://medium.com/@gregbrimble/my-first-attempt-at-open-source-a9799d31c66b) dev.to posts (this was my first, be nice)!