I am currently developing a Python library under an MIT license (let's call it mylib). I have, however, come across what may be a minor hurdle. I want to include an optional GPL-licensed dependency.
I have three circumstances. Consider two libraries, mitlib and gpllib. Both mitlib provide the same functionality, but mitlib is licensed under an MIT license and gpllib under a GPL license.
Circumstance 1: I have a function with the signature
from mitlib import utility_func
def func(x, use_gpl=False):
if use_gpl:
try:
from gpllib import utility_func # Overwrite mitlib.utility_func in this scope only
except ImportError:
raise ImportError(
"gpllib is not installed, but it is needed to run func with use_gpl=True. "
"Install gpllib by running pip install gpllib."
)
return utility_func(x)
To my understanding (based on Optional GPL dependency in commercial Python application and that this is almost what scipy.sparse.linalg.use_solver does), this approach allows me to license mylib under a MIT license , since I do not actually copy any code from gpllib.
Circumstance 2: There is no permissively licensed alternative for gpllib, so my function has the signature
try:
from gpllib import utility_func
except ImportError:
HAS_GPLLIB = False
else:
HAS_GPLLIB = True
def func(x):
if not HAS_GPLLIB:
raise RuntimeError("Cannot run func without installing gpllib first. To install, run pip install gpllib.")
return utility_func(x)
This is, to my understanding, more complicated (based on: Can I license Python project under 3-clause BSD while it has GPL-based dependencies). mylib now directly depends on gpllib. However, func is only a small part of mylib that only some power-users will use, and not an integral part of my library. Also, the rest of mylib will still work without installing any GPL-licensed code. I could, in fact, move all code that depend on gpllib GPL-licensed plugin library. However this would fragment the codebase further, and I would prefer not doing this. Can I have all code in mylib, or should I separate it into mylib and a GPL-licensed plugin mylib_gpl?
Circumstance 3: My library is fully MIT-licensed, however, I have an example script that uses GPL-licensed code. Can I then license only the example script with a GPL-license?
gpllib(pingouin) does a better job thanmitlib(statsmodels). Both libraries can create a QQ-plot, but pingouin's plot is slightly better.