Why you need to Fork a Repo

Why you need to Fork a Repo

This morning, I needed to generate a pdf file in my Django project. So, I had to shop around for pdf generating tools available in Python. There are a few of them out there. However, I needed some functionalities which I luckily saw in this particular library, Django-Easy-Pdf

The library is cool and does exactly what I wanted with the function :

easy_pdf.rendering.render_to_pdf(template, context, using=None, request=None, encoding='utf-8', **kwargs)

without me having to write too much code. So, I pulled in the package into my Python project:

pip install django-easy-pdf

Gbam, on calling the "render_to_pdf" function, a disappointing error blocked my server. Nothing is working. So what was the error?

ModuleNotFoundError: No module named 'django.utils.six'

This means that django.utils.six doesn't exist. How come the package referenced a missing module? The answer is simple. The package was built far back 2017 and a lot of things have changed in Django after that. Django has moved away from django.utils.six and allows you to use six directly. Hence, any call to django.utils.six will raise the ModuleNotFoundError. So what is the solution for me?

Since I already know this is the only problem with the package, all I need to do is "fork" the package from git. Then I can modify the part of the package that has the issue, from

from django.utils.six import ...

to

from six import ...

Now I have a better package which I can maintain on my own. How then do I pull this new package into my application? First, I have to uninstall the previous one I have installed using:

pip uninstall django-easy-pdf

Then install the new one from my Github account this way

pip install git+https://github.com/adigunsherif/django-easy-pdf.git

Then, this will pull my updated code and install it as django-easy-pdf.

Pros: In future, if I need to modify the package, I can go to my Github account and update it anytime. Cons: When the master branch of the package from which we forked is updated, our package isn't updated. But then, we still can do

git merge

and our new package will be up to date.

If you can't have your pull request merged to a package/library in time, forking is a very good alternative to go!