本文整理汇总了Python中notebook.utils.ujoin函数的典型用法代码示例。如果您正苦于以下问题:Python ujoin函数的具体用法?Python ujoin怎么用?Python ujoin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ujoin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
def initialize(webapp, notebook_dir, connection_url, settings):
if os.name == 'nt':
default_shell = 'powershell.exe'
else:
default_shell = which('sh')
shell = settings.get('shell_command',
[os.environ.get('SHELL') or default_shell]
)
# Enable login mode - to automatically source the /etc/profile script
if os.name != 'nt':
shell.append('-l')
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
shell_command=shell,
extra_env={'JUPYTER_SERVER_ROOT': notebook_dir,
'JUPYTER_SERVER_URL': connection_url,
},
)
terminal_manager.log = app_log
base_url = webapp.settings['base_url']
handlers = [
(ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler),
(ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket,
{'term_manager': terminal_manager}),
(ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
(ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
]
webapp.add_handlers(".*$", handlers)
示例2: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
webapp.add_handlers(".*$", [
(ujoin(base_url, r"/nbextensions"), NBExtensionHandler),
(ujoin(base_url, r"/nbextensions/"), NBExtensionHandler),
(ujoin(base_url, r"/nbextensions/config/rendermd/(.*)"), RenderExtensionHandler),
])
示例3: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
mdregex = r'([^"\'>]+.md)'
webapp.add_handlers(".*$", [
(ujoin(base_url, r"/rendermd/%s" % mdregex), RenderExtensionHandler),
(ujoin(base_url, r"/nbextensions"), NBExtensionHandler),
(ujoin(base_url, r"/nbextensions/"), NBExtensionHandler)
])
示例4: _get_lab_config
def _get_lab_config(self, manifest):
"""Get the config data for the page template."""
static_prefix = ujoin(self.base_url, PREFIX)
labextensions = self.labextensions
main = manifest['main']['entry']
bundles = [ujoin(static_prefix, name + '.bundle.js') for name in
['loader', 'main']]
entries = []
# Only load CSS files if they exist.
css_files = []
for css_file in ['main.css']:
if os.path.isfile(os.path.join(BUILT_FILES, css_file)):
css_files.append(ujoin(static_prefix, css_file))
configData = dict(
terminalsAvailable=self.settings.get('terminals_available', False),
)
# Gather the lab extension files and entry points.
for (name, data) in sorted(labextensions.items()):
for value in data.values():
if not isinstance(value, dict):
continue
if value.get('entry', None):
entries.append(value['entry'])
bundles.append('%s/%s/%s' % (
self.extension_prefix, name, value['files'][0]
))
for fname in value['files']:
if os.path.splitext(fname)[1] == '.css':
css_files.append('%s/%s/%s' % (
self.extension_prefix, name, fname
))
python_module = data.get('python_module', None)
if python_module:
try:
value = get_labextension_config_python(python_module)
configData.update(value)
except Exception as e:
self.log.error(e)
mathjax_config = self.settings.get('mathjax_config',
'TeX-AMS_HTML-full,Safe')
config = dict(
static_prefix=static_prefix,
page_title='JupyterLab Alpha Preview',
mathjax_url=self.mathjax_url,
mathjax_config=mathjax_config,
jupyterlab_main=main,
jupyterlab_css=css_files,
jupyterlab_bundles=bundles,
plugin_entries=entries,
)
config['jupyterlab_config'] = configData
return config
示例5: get
def get(self):
static_prefix = ujoin(self.base_url, PREFIX)
labextensions = self.application.labextensions
data = get_labextension_manifest_data_by_folder(BUILT_FILES)
if 'main' not in data or 'extensions' not in data:
msg = ('JupyterLab build artifacts not detected, please see ' +
'CONTRIBUTING.md for build instructions.')
self.log.error(msg)
self.write(self.render_template('error.html',
status_code=500,
status_message='JupyterLab Error',
page_title='JupyterLab Error',
message=msg))
return
main = data['main']['entry']
bundles = [ujoin(static_prefix, name + '.bundle.js') for name in
['loader', 'main', 'extensions']]
entries = [data['extensions']['entry']]
# Only load CSS files if they exist.
css_files = []
for css_file in ['main.css', 'extensions.css']:
if os.path.isfile(os.path.join(BUILT_FILES, css_file)):
css_files.append(ujoin(static_prefix, css_file))
# Gather the lab extension files and entry points.
for name in labextensions:
data = get_labextension_manifest_data_by_name(name)
if data is None:
self.log.warn('Could not locate extension: ' + name)
continue
for value in data.values():
if value.get('entry', None):
entries.append(value['entry'])
bundles.append('%s/%s/%s' % (
EXTENSION_PREFIX, name, value['files'][0]
))
for fname in value['files']:
if os.path.splitext(fname)[1] == '.css':
css_files.append('%s/%s/%s' % (
EXTENSION_PREFIX, name, fname
))
self.write(self.render_template('lab.html',
static_prefix=static_prefix,
page_title='JupyterLab Alpha Preview',
terminals_available=self.settings['terminals_available'],
mathjax_url=self.mathjax_url,
jupyterlab_main=main,
jupyterlab_css=css_files,
jupyterlab_bundles=bundles,
plugin_entries=entries,
mathjax_config='TeX-AMS_HTML-full,Safe',
#mathjax_config=self.mathjax_config # for the next release of the notebook
))
示例6: initialize
def initialize(webapp):
shell = os.environ.get('SHELL') or 'sh'
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(shell_command=[shell])
terminal_manager.log = app_log
base_url = webapp.settings['base_url']
handlers = [
(ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler),
(ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket,
{'term_manager': terminal_manager}),
(ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
(ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
]
webapp.add_handlers(".*$", handlers)
示例7: get
def get(self, action):
example_id = self.get_argument('example_id')
if action == 'preview':
self.finish(self.manager.preview_example(example_id))
elif action == 'fetch':
dest = self.get_argument('dest')
dest = self.manager.fetch_example(example_id, dest)
self.redirect(ujoin(self.base_url, 'notebooks', dest))
elif action == 'submit':
dest = self.manager.submit_example(example_id)
self.redirect(ujoin(self.base_url, 'tree#examples' + dest))
elif action == 'delete':
self.manager.delete_example(example_id)
self.redirect(ujoin(self.base_url))
示例8: get
def get(self, action):
example_id = self.get_argument('example_id')
if action == 'preview':
self.finish(self.manager.preview_example(example_id))
elif action == 'fetch':
dest = self.get_argument('dest')
self.manager.fetch_example(example_id, dest)
# nbconvert appends '.ipynb' if it isn't present
if not dest.endswith('.ipynb'):
dest += '.ipynb'
self.redirect(ujoin(self.base_url, 'notebooks', dest))
elif action == 'submit':
dest = self.manager.submit_example(example_id)
preview_url = '/examples/preview?example_id={}'.format(dest)
self.redirect(ujoin(self.base_url, preview_url))
示例9: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
zsd = find_zotero_styles_dir()
if zsd:
webapp.add_handlers(".*$", [
(ujoin(base_url, r"/cite2c/styles/?"), ListStylesHandler,
{'path': zsd}),
(ujoin(base_url, r"/cite2c/styles/(.+)"), StaticFileHandler,
{'path': zsd}),
])
else:
nbapp.log.warning('Could not find Zotero citation styles directory.')
webapp.add_handlers(".*$", zotero_oauth.handlers(base_url))
示例10: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
"""Load and initialise the server extension."""
logger = ConfiguratorLogger(nbapp.log)
logger.debug('Loading {}'.format(__version__))
webapp = nbapp.web_app
# ensure our template gets into search path
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
logger.debug(' Editing templates path to add {}'.format(templates_dir))
rootloader = webapp.settings['jinja2_env'].loader
for loader in getattr(rootloader, 'loaders', [rootloader]):
if hasattr(loader, 'searchpath') and \
templates_dir not in loader.searchpath:
loader.searchpath.append(templates_dir)
base_url = webapp.settings['base_url']
# make sure our static files are available
static_files_path = os.path.normpath(os.path.join(
os.path.dirname(__file__), 'static'))
logger.debug(
' Editing nbextensions path to add {}'.format(static_files_path))
if static_files_path not in webapp.settings['nbextensions_path']:
webapp.settings['nbextensions_path'].append(static_files_path)
# add our new custom handlers
logger.debug(' Adding new handlers')
new_handlers = [(ujoin(base_url, '/nbextensions/' + u), h) for u, h in [
(r"?", NBExtensionHandlerPage),
(r"nbextensions_configurator/list$", NBExtensionHandlerJSON),
(r"nbextensions_configurator/rendermd/(.*)", RenderExtensionHandler),
]]
webapp.add_handlers(".*$", new_handlers)
logger.info('enabled {}'.format(__version__))
示例11: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
"""Load the nbserver"""
windows = sys.platform.startswith('win')
webapp = nbapp.web_app
webapp.settings['shared_manager'] = SharedManager(parent=nbapp)
base_url = webapp.settings['base_url']
install_nbextension(static, destination='nbshared', symlink=not windows, user=True)
# cfgm = nbapp.config_manager
# cfgm.update('tree', {
# 'load_extensions': {
# 'nbexamples/main': True,
# }
# })
# cfgm.update('notebook', {
# 'load_extensions': {
# 'nbexamples/submit-example-button': True,
# }
# })
webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
for pat, handler in default_handlers
])
示例12: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
"""Load the nbserver"""
windows = sys.platform.startswith('win')
webapp = nbapp.web_app
webapp.settings['example_manager'] = Examples(parent=nbapp)
base_url = webapp.settings['base_url']
install_nbextension(static, destination='nbexamples', symlink=not windows,
user=True)
cfgm = nbapp.config_manager
cfgm.update('tree', {
'load_extensions': {
'nbexamples/main': True,
}
})
cfgm.update('notebook', {
'load_extensions': {
'nbexamples/submit-example-button': True,
}
})
ExampleActionHandler.base_url = base_url # used to redirect after fetch
webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
for pat, handler in default_handlers
])
示例13: get
def get(self, path="/"):
config = self.nteract_config
settings_dir = config.settings_dir
assets_dir = config.assets_dir
base_url = self.settings['base_url']
url = ujoin(base_url, config.page_url, '/static/')
# Handle page config data.
page_config = dict()
page_config.update(self.settings.get('page_config_data', {}))
page_config.setdefault('appName', config.name)
page_config.setdefault('appVersion', config.version)
mathjax_config = self.settings.get('mathjax_config',
'TeX-AMS_HTML-full,Safe')
config = dict(
page_title=config.page_title,
mathjax_url=self.mathjax_url,
mathjax_config=mathjax_config,
page_config=page_config,
public_url=url,
contents_path=path,
page=self.page,
)
self.write(self.render_template('index.html', **config))
示例14: get
def get(self, action):
try:
notebook_id = unquote(self.get_argument('notebook_id'))
# Submit a notebook
if action == 'submit':
name = unquote(self.get_argument('name', default=None))
dest = self.manager.storage.submit(notebook_id, name, True);
self.finish(str(dest));
# Delete a notebook
elif action == 'delete':
if self.manager.storage.delete(notebook_id):
self.finish("OK");
else:
raise web.HTTPError(404, "Impossible to delete: %s" % notebook_id);
# Preview a notebook
elif action == 'preview':
self.finish(self.manager.storage.preview(notebook_id))
# Fetch a notebook
elif action == 'fetch':
dest = unquote(self.get_argument('dest'))
if not dest.endswith('.ipynb'):
dest += '.ipynb'
url = quote(self.manager.storage.fetch(notebook_id, dest));
self.redirect(ujoin(self.base_url, 'notebooks', url))
else:
self.finish("%s is not a valid action!" % action);
except Exception as e:
self.log.error("Error happen when do %s on %s" % (action, notebook_id))
self.log.error(str(e));
raise web.HTTPError(500, "Error happen when do %s on %s" % (action, notebook_id));
示例15: load_jupyter_server_extension
def load_jupyter_server_extension(nbapp):
"""Load the nbserver"""
c = Config()
c.FormgradeApp.authenticator_class = 'notebookauth.NotebookAuth'
c.BaseAuth.connect_ip = nbapp.ip
c.BaseAuth.connect_port = nbapp.port
c.BaseAuth.url_prefix = '/formgrader'
c.NotebookAuth.notebook_base_url = nbapp.base_url
c.NotebookAuth.notebook_url_prefix = "instructor"
c.NbGrader.log_level = nbapp.log_level
c.NbGrader.course_directory = os.path.join(os.getcwd(), "instructor")
formgrader = FormgradeApp(parent=nbapp)
formgrader.update_config(c)
super(FormgradeApp, formgrader).initialize([])
formgrader.init_tornado_settings()
formgrader.init_handlers()
# update handlers
webapp = nbapp.web_app
base_url = webapp.settings["base_url"]
handlers = []
for handler in formgrader.handlers:
handler = list(handler)
handler[0] = ujoin(base_url, handler[0])
handlers.append(tuple(handler))
webapp.add_handlers(".*$", handlers)
# update settings
formgrader.tornado_settings['nbgrader_mathjax_url'] = webapp.settings['mathjax_url']
formgrader.tornado_settings['log_function'] = webapp.settings['log_function']
webapp.settings.update(formgrader.tornado_settings)