##// END OF EJS Templates
add `ipython install-nbextension` entrypoint
MinRK -
Show More
@@ -99,3 +99,78 b' def install_nbextension(files, overwrite=False, ipython_dir=None, verbose=1):'
99 99 else:
100 100 src = path
101 101 _maybe_copy(src, dest, verbose)
102
103 #----------------------------------------------------------------------
104 # install nbextension app
105 #----------------------------------------------------------------------
106
107 import logging
108 from IPython.utils.traitlets import Bool, Enum
109 from IPython.core.application import BaseIPythonApplication
110
111 flags = {
112 "overwrite" : ({
113 "NBExtensionApp" : {
114 "overwrite" : True,
115 }}, "Force overwrite of existing files"
116 ),
117 "debug" : ({
118 "NBExtensionApp" : {
119 "verbose" : 2,
120 }}, "Extra output"
121 ),
122 "quiet" : ({
123 "NBExtensionApp" : {
124 "verbose" : 0,
125 }}, "Minimal output"
126 ),
127 }
128 aliases = {
129 "ipython-dir" : "NBExtensionApp.ipython_dir"
130 }
131
132 class NBExtensionApp(BaseIPythonApplication):
133 """Entry point for installing notebook extensions"""
134
135 description = """Install IPython notebook extensions
136
137 Usage
138
139 ipython install-nbextension file [more files or folders]
140
141 This copies files and/or folders into the IPython nbextensions directory.
142 If the requested files are already up to date, no action is taken
143 unless --overwrite is specified.
144 """
145
146 examples = """
147 ipython install-nbextension /path/to/d3.js /path/to/myextension
148 """
149 aliases = aliases
150 flags = flags
151
152 overwrite = Bool(False, config=True, help="Force overwrite of existing files")
153 verbose = Enum((0,1,2), default_value=1, config=True,
154 help="Verbosity level"
155 )
156
157 def install_extensions(self):
158 install_nbextension(self.extra_args,
159 overwrite=self.overwrite,
160 verbose=self.verbose,
161 ipython_dir=self.ipython_dir,
162 )
163
164 def start(self):
165 if not self.extra_args:
166 nbext = pjoin(self.ipython_dir, u'nbextensions')
167 print("Notebook extensions in %s:" % nbext)
168 for ext in os.listdir(nbext):
169 print(u" %s" % ext)
170 else:
171 self.install_extensions()
172
173
174 if __name__ == '__main__':
175 NBExtensionApp.launch_instance()
176 No newline at end of file
@@ -224,7 +224,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
224 224 StoreMagics,
225 225 ]
226 226
227 subcommands = Dict(dict(
227 subcommands = dict(
228 228 qtconsole=('IPython.qt.console.qtconsoleapp.IPythonQtConsoleApp',
229 229 """Launch the IPython Qt Console."""
230 230 ),
@@ -253,6 +253,10 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
253 253 "Sign notebooks to trust their potentially unsafe contents at load."
254 254 ),
255 255 ))
256 subcommands['install-nbextension'] = (
257 "IPython.html.nbextensions.NBExtensionApp",
258 "Install IPython notebook extension files"
259 )
256 260
257 261 # *do* autocreate requested profile, but don't create the config file.
258 262 auto_create=Bool(True)
General Comments 0
You need to be logged in to leave comments. Login now