didactic-meme/pyfuncol

[FEATURE] Make forbiddenfruit optional

Closed this issue ยท 6 comments

It would be great if forbiddenfruit was made optional. Since forbiddenfruit requires CPython and I think if it would be better if it could work on other versions of python.

Instead of:

import pyfuncol

my_list = [1, 2, 3]
print(my_list.map(lambda x: x * 2))

I can do:

from pyfuncol.list import *

my_list = [1, 2, 3]
print(map(my_list, lambda x: x * 2))

Maybe there can be a check to see if forbiddenfruit is installed. If it is, add all the functions to the builtin classes, otherwise do nothing.

Sorry if I misunderstand how this works.

Hi! The library's primary goal is to offer extension functions, but indeed what you're suggesting can be useful and easily added, I think.

The best way to do so would be to move all forbiddenfruit related code to the __init__.py, maybe add a check to see if the library is installed (not sure it's needed) and then provide an "extra" when installing via pip that doesn't install forbiddenfruit, something like "pip install pyfuncol[pure]".

In this way, your second example should run without problems.

What do you think? Would you be interested in helping with such a feature?

Sure! Why not?

I'm not sure how to create a seperate pure version because I'm not very familiar with pip publishing, but I can definitely help with refactoring the code so forbiddenfruit is optional

That's great, we can handle pip if you want!

A small update. Extras can only install additional packages, so the only modifications to do apart from moving the code is the import check as we were discussing, something like:

try:
  from forbiddenfruit import curse
except ImportError:
  # maybe print a warning?

This however means that users will also install forbiddenfruit by default when installing pyfuncol.

Quick question, should we change forbidden_fruit from install_requires to extras_requires? I'm a little confused

Hi,

Thanks a lot for helping with this feature :)

No, we will keep it in the install_requires as most users likely want to use this library with the extensions. However, with your refactor, users that do not have it installed will be able to nevertheless run the code.