ipython / ipython_genutils

Vestigial IPython utilities: DO NOT USE
Other
11 stars 22 forks source link

Fix import from JSON in Python 2.7 #8

Closed juhasch closed 8 years ago

juhasch commented 8 years ago

Seems Python 2.7 does not like to be fed unicode for __import__: http://stackoverflow.com/questions/27477880/portable-code-import-parameter-string-type-between-python-2-and-python-3

This is needed to allow loading additional pre/postprocessors from a JSON config file: https://github.com/jupyter/nbconvert/issues/362

takluyver commented 8 years ago

I think our plan is not to make any further releases of ipython_genutils unless it's really necessary; the package is something of a fudge for bits we couldn't cleanly separate. So maybe we should make a copy of import_item in nbconvert? @minrk ?

minrk commented 8 years ago

@takluyver I think there's already a copy of import_item in traitlets that may have this fix. We could consider that an exported API (we may already be treating it that way in one or two places, I'm not sure).

juhasch commented 8 years ago

Well there is a copy of import_item in traitlets. So should nbconvert use from traitlets.utils.importstring import import_item instead ?

The traitlets version also needs the proposed fix.

takluyver commented 8 years ago

It looks like the traitlets version has an equivalent fix: https://github.com/ipython/traitlets/blob/146cef48cac8620838500049d65eb51d98f9e522/traitlets/utils/importstring.py#L29

I think it should be fine to import it from traitlets in nbconvert. Possibly we should open an issue on traitlets to document it as part of the public API?

minrk commented 8 years ago

👍 to making import_item a public, documented API of traitlets

juhasch commented 8 years ago

Sounds good, so I am closing this.