Skip to content

Commit f57546d

Browse files
authored
Merge branch 'master' into cg-validate-worksheets
2 parents 1e8b7ea + dee3e4f commit f57546d

28 files changed

+771
-70
lines changed

docs/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
ipython_genutils
21
jsonschema
32
traitlets
43
-e git+https://github.com/jupyter/jupyter_core.git#egg=jupyter_core

nbformat/_imports.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
A simple utility to import something by its string name.
3+
4+
Vendored form ipython_genutils
5+
"""
6+
7+
# Copyright (c) IPython Development Team.
8+
# Distributed under the terms of the Modified BSD License.
9+
10+
11+
def import_item(name):
12+
"""Import and return ``bar`` given the string ``foo.bar``.
13+
14+
Calling ``bar = import_item("foo.bar")`` is the functional equivalent of
15+
executing the code ``from foo import bar``.
16+
17+
Parameters
18+
----------
19+
name : string
20+
The fully qualified name of the module/package being imported.
21+
22+
Returns
23+
-------
24+
mod : module object
25+
The module that was imported.
26+
"""
27+
28+
parts = name.rsplit(".", 1)
29+
if len(parts) == 2:
30+
# called with 'foo.bar....'
31+
package, obj = parts
32+
module = __import__(package, fromlist=[obj])
33+
try:
34+
pak = getattr(module, obj)
35+
except AttributeError:
36+
raise ImportError("No module named %s" % obj)
37+
return pak
38+
else:
39+
# called with un-dotted string
40+
return __import__(parts[0])

0 commit comments

Comments
 (0)