Should I conditionally require simplejson in my setup.py?

I am importing simplejson / json conditionally into my module as follows:

try:
    import simplejson as json
except ImportError:
    import json

In my setup.py, however, I do not want to require simplejson if the user has json from the standard libraries. I could do this:

requires = ['kitchen']
try:
    import simplejson
except ImportError:
    requires.append('simplejson')

setup(..., requires=requires)

Is this good practice for setup.py files? Should I use something else? Should I just just require a simple user?

+3
source share
1 answer

The short answer is no, this is not a good practice.

distutils, zc.buildout .. - . , , . , simplejson json . , , .. , . , .

+3

Source: https://habr.com/ru/post/1792321/


All Articles