Oct 12, 2022 4 MIN

Contributing to a PIP package

How I became a darts open source contributor

blog hero

Since The OpenBB Terminal is written in python, we often find ourselves installing pip packages. We use many common ones such as pandas, numpy, and matplotlib. But, we also use lesser known packages like voila, which allows for jupyter notebooks to be shown as interactive dashboards, and darts, which allows for manipulation and forecasting of timeseries data.

When using these packages, we sometimes run into issues where we need to go beyond the functionality that the package offers. One example of this is our use of plotting in darts. Darts automatically creates clean and easy to read graphs to get insight out of timeseries data. One example of this is the plot_acf command shown below:

Darts original output

However, this command did have an issue very specific to our use case. The OpenBB Terminal has a customized matplotlib to show graphs using custom formats. Unfortunately, our custom OpenBB styles and the ones used by darts conflicted. Meaning the charts created looked like this:

Darts original output

To be able to use this functionality in our terminal, it was clear that the package needed to be able to deal with custom formatting without overlapping. Since OpenBB is committed to the open source environment, we decided to submit a pull request (PR) on Github to give the package a way to handle this conflict.

Understand the codebase and fork the repository

To begin our PR, we need to go to dart’s Github page. On this page, we can start to understand how the codebase works and also we can find the CONTRIBUTING.md. This is a file that tells us specifics on how we should submit pull requests (PRs). Once you're ready to begin your PR, "fork" the repository. This allows you to have your own version of the code which you can sync with the original one later.

Download the code and create an environment

To begin editing your fork copy and paste its url. Then head to your terminal and type git clone [url]. This downloads the pip package onto our local computer. Once you have this done, create a new environment. I use conda, so I typed conda create --name darts. Then I ran conda activate darts to activate my new environment. Once you're inside the newly installed package, type in git checkout -b new_feature to be start your own branch inside git.

Install your custom package locally

After this, you will need to install your local version of the pip package. This can be done by running pip install -e path/to/package, so I ran pip install -e ~/darts. After this, it's time to open up the code and get to work. My changes were done once I had added the ability to ignore dart’s default style. Which allows my charts to look like this:

Darts after update

Working with linters

Another important step in contributing to an open source project is linting and testing your code. These steps make sure that your code is high quality and don't break production. If your code uses pre-commit then you can simply run pip install pre-commit and then pre-commit install inside of the code repository. If not, read the contributing.md to see what linters the project uses. Testing is typically done in pytest. The contributing.md is a great place to find out information on how to test the code.

Commit your code

Once you're done, "stage" your changes using git add path/to/file for each file changed. Then run git commit -m "message" to commit your changes. After this, we just need to run git push to push our changes to our fork. Then once we go back to the Github page for our fork, Github will prompt us to create a new PR with the main repository.

Follow up on feedback

At this point, all that is left is making any changes requested by the reviewer of the PR. This makes sure that your changes are consistent with what the library owners want the library to look like, it's also a great way to improve on your own coding skills. After your requested changes are made, congratulations!! You are now contributing to python’s robust open source community. Need help finding a package to contribute to? The OpenBB Terminal is always looking for new contributors!

Explore the
Terminal Pro

We use cookies

This website uses cookies to meausure and improve your user experience.