Skip to content

Commit

Permalink
remove dependency on IPython genutils (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Dec 17, 2021
1 parent f101cd2 commit c521262
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 60 deletions.
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ipython_genutils
jsonschema
traitlets
-e git+https://github.com/jupyter/jupyter_core.git#egg=jupyter_core
40 changes: 40 additions & 0 deletions nbformat/_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
A simple utility to import something by its string name.
Vendored form ipython_genutils
"""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.


def import_item(name):
"""Import and return ``bar`` given the string ``foo.bar``.
Calling ``bar = import_item("foo.bar")`` is the functional equivalent of
executing the code ``from foo import bar``.
Parameters
----------
name : string
The fully qualified name of the module/package being imported.
Returns
-------
mod : module object
The module that was imported.
"""

parts = name.rsplit(".", 1)
if len(parts) == 2:
# called with 'foo.bar....'
package, obj = parts
module = __import__(package, fromlist=[obj])
try:
pak = getattr(module, obj)
except AttributeError:
raise ImportError("No module named %s" % obj)
return pak
else:
# called with un-dotted string
return __import__(parts[0])

0 comments on commit c521262

Please sign in to comment.