From ac119bb62c7feb52728b2c570b4c4edb7c2b052a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Sat, 12 Oct 2019 14:41:31 +0200 Subject: [PATCH 01/12] Use f-strings After #403 is merged, there will be no reason to use the old string styling from Python2, and since f-strings are available since Python 3.6 it could be adopted as the default style. --- setup.py | 14 +++++----- tests/app/config_paths_test.py | 2 +- tests/app/cwd_subdir_test.py | 4 +-- tests/app/execute_cpp_test.py | 2 +- tests/app/execute_test.py | 4 +-- tests/app/nbextensions_test.py | 2 +- tests/app/no_kernelspec_test.py | 4 +-- tests/app/non_existing_kernel_test.py | 4 +-- tests/app/notebooks_test.py | 4 +-- tests/app/serve_directory_test.py | 2 +- tests/app/template_cli_test.py | 2 +- tests/app/tree_test.py | 2 +- tests/conftest.py | 2 +- tests/server/cwd_subdir_test.py | 4 +-- tests/server/execute_cpp_test.py | 4 +-- tests/server/tree_test.py | 4 +-- voila/app.py | 38 +++++++++++++-------------- voila/execute.py | 4 +-- voila/treehandler.py | 2 +- voila/utils.py | 2 +- 20 files changed, 52 insertions(+), 54 deletions(-) diff --git a/setup.py b/setup.py index 33e82c43b..5943d5c24 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ def run(self): if strict or missing: log.warn('rebuilding js and css failed') if missing: - log.error('missing files: %s' % missing) + log.error(f'missing files: {missing}') raise e else: log.warn('rebuilding js and css failed (not a problem)') @@ -166,9 +166,9 @@ def run(cmd, **kwargs): cmd = shlex.split(cmd) cmd_path = which(cmd[0]) if not cmd_path: - sys.exit("Aborting. Could not find cmd (%s) in path. " + sys.exit(f"Aborting. Could not find cmd ({cmd[0]}) in path. " "If command is not expected to be in user's path, " - "use an absolute path." % cmd[0]) + "use an absolute path.") cmd[0] = cmd_path return check_call(cmd, **kwargs) @@ -222,7 +222,7 @@ def run(self): for t in self.targets: if not os.path.exists(t): - msg = 'Missing file: %s' % t + msg = f'Missing file: {t}' if not has_npm: msg += '\nnpm is required to build a development version' raise ValueError(msg) @@ -235,13 +235,13 @@ def run(self): jupyterlab_css_version = '0.1.0' -css_url = "https://unpkg.com/@jupyterlab/nbconvert-css@%s/style/index.css" % jupyterlab_css_version +css_url = f"https://unpkg.com/@jupyterlab/nbconvert-css@{jupyterlab_css_version}/style/index.css" theme_light_version = '0.19.1' -theme_light_url = "https://unpkg.com/@jupyterlab/theme-light-extension@%s/static/embed.css" % theme_light_version +theme_light_url = f"https://unpkg.com/@jupyterlab/theme-light-extension@{theme_light_version}s/static/embed.css" theme_dark_version = '0.19.1' -theme_dark_url = "https://unpkg.com/@jupyterlab/theme-dark-extension@%s/static/embed.css" % theme_dark_version +theme_dark_url = f"https://unpkg.com/@jupyterlab/theme-dark-extension@{theme_dark_version}/static/embed.css" class FetchCSS(Command): diff --git a/tests/app/config_paths_test.py b/tests/app/config_paths_test.py index aceed7fc9..dd45271db 100644 --- a/tests/app/config_paths_test.py +++ b/tests/app/config_paths_test.py @@ -10,7 +10,7 @@ @pytest.fixture def voila_config_file_paths_arg(): path = os.path.join(BASE_DIR, '..', 'configs', 'general') - return '--VoilaTest.config_file_paths=[%r]' % path + return f'--VoilaTest.config_file_paths=[{path!r}]' def test_config_app(voila_app): diff --git a/tests/app/cwd_subdir_test.py b/tests/app/cwd_subdir_test.py index ab8834aad..0480fc20a 100644 --- a/tests/app/cwd_subdir_test.py +++ b/tests/app/cwd_subdir_test.py @@ -4,12 +4,12 @@ @pytest.fixture def cwd_subdir_notebook_url(base_url): - return base_url + "/voila/render/subdir/cwd_subdir.ipynb" + return f"{base_url}/voila/render/subdir/cwd_subdir.ipynb" @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.mark.gen_test diff --git a/tests/app/execute_cpp_test.py b/tests/app/execute_cpp_test.py index 5cbd5c5aa..97345de04 100644 --- a/tests/app/execute_cpp_test.py +++ b/tests/app/execute_cpp_test.py @@ -6,7 +6,7 @@ @pytest.fixture def cpp_file_url(base_url): - return base_url + "/voila/render/print.xcpp" + return f"{base_url}/voila/render/print.xcpp" @pytest.fixture diff --git a/tests/app/execute_test.py b/tests/app/execute_test.py index bf34b0234..a84d23b86 100644 --- a/tests/app/execute_test.py +++ b/tests/app/execute_test.py @@ -32,9 +32,7 @@ def test_no_execute_allowed(voila_app, app, http_client, base_url): kernel_id = groups[0] print(kernel_id, base_url) session_id = '445edd75-c6f5-45d2-8b58-5fe8f84a7123' - url = '{base_url}/api/kernels/{kernel_id}/channels?session_id={session_id}'.format( - kernel_id=kernel_id, base_url=base_url, session_id=session_id - ).replace('http://', 'ws://') + url = f'{base_url}/api/kernels/{kernel_id}/channels?session_id={session_id}'.replace('http://', 'ws://') conn = yield tornado.websocket.websocket_connect(url) msg = { diff --git a/tests/app/nbextensions_test.py b/tests/app/nbextensions_test.py index 1ec72010d..738386a39 100644 --- a/tests/app/nbextensions_test.py +++ b/tests/app/nbextensions_test.py @@ -19,7 +19,7 @@ def config(app): def voila_config_file_paths_arg(): # we don't want the tests to use any configuration on the system path = os.path.abspath(os.path.join(BASE_DIR, '../configs/general')) - return '--VoilaTest.config_file_paths=[%r]' % path + return f'--VoilaTest.config_file_paths=[{path!r}]' @pytest.mark.gen_test diff --git a/tests/app/no_kernelspec_test.py b/tests/app/no_kernelspec_test.py index 451dfde85..c66f2822a 100644 --- a/tests/app/no_kernelspec_test.py +++ b/tests/app/no_kernelspec_test.py @@ -3,12 +3,12 @@ @pytest.fixture def non_existing_kernel_notebook(base_url): - return base_url + "/voila/render/no_kernelspec.ipynb" + return f"{base_url}/voila/render/no_kernelspec.ipynb" @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}'] + voila_args_extra @pytest.mark.gen_test diff --git a/tests/app/non_existing_kernel_test.py b/tests/app/non_existing_kernel_test.py index e588f8752..6e48674be 100644 --- a/tests/app/non_existing_kernel_test.py +++ b/tests/app/non_existing_kernel_test.py @@ -3,12 +3,12 @@ @pytest.fixture def non_existing_kernel_notebook(base_url): - return base_url + "/voila/render/non_existing_kernel.ipynb" + return f"{base_url}/voila/render/non_existing_kernel.ipynb" @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}'] + voila_args_extra @pytest.mark.gen_test diff --git a/tests/app/notebooks_test.py b/tests/app/notebooks_test.py index c3b9c0b34..5d440078d 100644 --- a/tests/app/notebooks_test.py +++ b/tests/app/notebooks_test.py @@ -4,11 +4,11 @@ @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.mark.gen_test def test_other_comms(http_client, base_url): - response = yield http_client.fetch(base_url + '/voila/render/other_comms.ipynb') + response = yield http_client.fetch(f'{base_url}/voila/render/other_comms.ipynb') html_text = response.body.decode('utf-8') assert 'This notebook executed' in html_text diff --git a/tests/app/serve_directory_test.py b/tests/app/serve_directory_test.py index 6f5ba4c30..a2e18ca6f 100644 --- a/tests/app/serve_directory_test.py +++ b/tests/app/serve_directory_test.py @@ -7,7 +7,7 @@ @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.mark.gen_test diff --git a/tests/app/template_cli_test.py b/tests/app/template_cli_test.py index 2bfbcd8fc..697e1151a 100644 --- a/tests/app/template_cli_test.py +++ b/tests/app/template_cli_test.py @@ -10,7 +10,7 @@ def voila_args_extra(): path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/nbconvert_templates')) path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default/nbconvert_templates')) - return ['--template=None', '--Voila.nbconvert_template_paths=[%r, %r]' % (path_test_template, path_default)] + return ['--template=None', f'--Voila.nbconvert_template_paths=[{path_test_template!r}, {path_default!r}]'] @pytest.mark.gen_test diff --git a/tests/app/tree_test.py b/tests/app/tree_test.py index be6fc64f7..da6af3cc2 100644 --- a/tests/app/tree_test.py +++ b/tests/app/tree_test.py @@ -4,7 +4,7 @@ @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.fixture diff --git a/tests/conftest.py b/tests/conftest.py index f3120f890..b87010208 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ def notebook_directory(): @pytest.fixture def print_notebook_url(base_url): - return base_url + "/voila/render/print.ipynb" + return f"{base_url}/voila/render/print.ipynb" @pytest.fixture diff --git a/tests/server/cwd_subdir_test.py b/tests/server/cwd_subdir_test.py index 6bdad3d13..382345573 100644 --- a/tests/server/cwd_subdir_test.py +++ b/tests/server/cwd_subdir_test.py @@ -5,12 +5,12 @@ @pytest.fixture def cwd_subdir_notebook_url(base_url): - return base_url + "/voila/render/subdir/cwd_subdir.ipynb" + return f"{base_url}/voila/render/subdir/cwd_subdir.ipynb" @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.mark.gen_test diff --git a/tests/server/execute_cpp_test.py b/tests/server/execute_cpp_test.py index 9684e7439..a4a1cf18c 100644 --- a/tests/server/execute_cpp_test.py +++ b/tests/server/execute_cpp_test.py @@ -6,7 +6,7 @@ @pytest.fixture def cpp_file_url(base_url): - return base_url + "/voila/render/print.xcpp" + return f"{base_url}/voila/render/print.xcpp" @pytest.fixture @@ -16,7 +16,7 @@ def jupyter_server_args_extra(): @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}'] + voila_args_extra @pytest.mark.skipif(not TEST_XEUS_CLING, reason='opt in to avoid having to install xeus-cling') diff --git a/tests/server/tree_test.py b/tests/server/tree_test.py index 3846abc70..da4784277 100644 --- a/tests/server/tree_test.py +++ b/tests/server/tree_test.py @@ -4,7 +4,7 @@ @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra + return [f'--VoilaTest.root_dir={notebook_directory!r}', '--VoilaTest.log_level=DEBUG'] + voila_args_extra @pytest.fixture @@ -14,7 +14,7 @@ def jupyter_server_args_extra(): @pytest.mark.gen_test def test_tree(http_client, base_url): - response = yield http_client.fetch(base_url+'/voila/tree') + response = yield http_client.fetch(f'{base_url}/voila/tree') assert response.code == 200 text = response.body.decode('utf-8') assert 'print.ipynb' in text, 'tree handler should render ipynb files' diff --git a/voila/app.py b/voila/app.py index 9edaee14b..9ff4b4e2f 100644 --- a/voila/app.py +++ b/voila/app.py @@ -241,7 +241,7 @@ def display_url(self): url += '/' else: if self.ip in ('', '0.0.0.0'): - ip = "%s" % socket.gethostname() + ip = f"{socket.gethostname()}" else: ip = self.ip url = self._url(ip) @@ -263,7 +263,7 @@ def _url(self, ip): # TODO: https / certfile # proto = 'https' if self.certfile else 'http' proto = 'http' - return "%s://%s:%i%s" % (proto, ip, self.port, self.base_url) + return f"{proto}://{ip}:{self.port}{self.base_url}" config_file_paths = List( Unicode(), @@ -288,7 +288,7 @@ def _config_file_paths_default(self): @default('connection_dir_root') def _default_connection_dir(self): connection_dir = tempfile.gettempdir() - self.log.info('Using %s to store connection files' % connection_dir) + self.log.info(f'Using {connection_dir} to store connection files') return connection_dir @default('log_level') @@ -317,7 +317,7 @@ def _default_root_dir(self): return getcwd() def initialize(self, argv=None): - self.log.debug("Searching path %s for config files", self.config_file_paths) + self.log.debug(f"Searching path {self.config_file_paths} for config files") # to make config_file_paths settable via cmd line, we first need to parse it super(Voila, self).initialize(argv) if len(self.extra_args) == 1: @@ -329,9 +329,9 @@ def initialize(self, argv=None): elif os.path.isfile(arg): self.notebook_path = arg else: - raise ValueError('argument is neither a file nor a directory: %r' % arg) + raise ValueError(f'argument is neither a file nor a directory: {arg!r}') elif len(self.extra_args) != 0: - raise ValueError('provided more than 1 argument: %r' % self.extra_args) + raise ValueError(f'provided more than 1 argument: {self.extra_args!r}') # then we load the config self.load_config_file('voila', path=self.config_file_paths) @@ -349,15 +349,15 @@ def setup_template_dirs(self): self.static_paths, self.template_paths, self.voila_configuration.template) - self.log.debug('using template: %s', self.voila_configuration.template) - self.log.debug('nbconvert template paths:\n\t%s', '\n\t'.join(self.nbconvert_template_paths)) - self.log.debug('template paths:\n\t%s', '\n\t'.join(self.template_paths)) - self.log.debug('static paths:\n\t%s', '\n\t'.join(self.static_paths)) + self.log.debug(f'using template: {self.voila_configuration.template}') + self.log.debug(f'nbconvert template paths:\n\t{"\n\t".join(self.nbconvert_template_paths)}') + self.log.debug(f'template paths:\n\t{"\n\t".join(self.template_paths)}') + self.log.debug(f'static paths:\n\t{"\n\t".join(self.static_paths)}') if self.notebook_path and not os.path.exists(self.notebook_path): - raise ValueError('Notebook not found: %s' % self.notebook_path) + raise ValueError(f'Notebook not found: {self.notebook_path}') def _handle_signal_stop(self, sig, frame): - self.log.info('Handle signal %s.' % sig) + self.log.info(f'Handle signal {sig}.') self.ioloop.add_callback_from_signal(self.ioloop.stop) def start(self): @@ -365,8 +365,8 @@ def start(self): prefix='voila_', dir=self.connection_dir_root ) - self.log.info('Storing connection files in %s.' % self.connection_dir) - self.log.info('Serving static files from %s.' % self.static_root) + self.log.info(f'Storing connection files in {self.connection_dir}.') + self.log.info(f'Serving static files from {self.static_root}.') self.kernel_spec_manager = KernelSpecManager( parent=self @@ -418,8 +418,8 @@ def start(self): handlers = [] handlers.extend([ - (url_path_join(self.server_url, r'/api/kernels/%s' % _kernel_id_regex), KernelHandler), - (url_path_join(self.server_url, r'/api/kernels/%s/channels' % _kernel_id_regex), ZMQChannelsHandler), + (url_path_join(self.server_url, fr'/api/kernels/{_kernel_id_regex}'), KernelHandler), + (url_path_join(self.server_url, fr'/api/kernels/{_kernel_id_regex}/channels'), ZMQChannelsHandler), ( url_path_join(self.server_url, r'/voila/static/(.*)'), MultiStaticFileHandler, @@ -469,7 +469,7 @@ def start(self): } )) else: - self.log.debug('serving directory: %r', self.root_dir) + self.log.debug(f'serving directory: {self.root_dir!r}) handlers.extend([ (self.server_url, VoilaTreeHandler, tree_handler_conf), (url_path_join(self.server_url, r'/voila/tree' + path_regex), VoilaTreeHandler, tree_handler_conf), @@ -490,7 +490,7 @@ def stop(self): def listen(self): self.app.listen(self.port) - self.log.info('Voila is running at:\n%s' % self.display_url) + self.log.info(f'Voila is running at:\n{self.display_url}') if self.open_browser: self.launch_browser() @@ -507,7 +507,7 @@ def launch_browser(self): try: browser = webbrowser.get(self.browser or None) except webbrowser.Error as e: - self.log.warning(_('No web browser found: %s.') % e) + self.log.warning(_(f'No web browser found: {e}.') browser = None if not browser: diff --git a/voila/execute.py b/voila/execute.py index 88c8d20fb..08508849d 100644 --- a/voila/execute.py +++ b/voila/execute.py @@ -59,7 +59,7 @@ def __init__(self, comm_id, state, kernel_client, executor): self.state = state self.kernel_client = kernel_client self.executor = executor - self.topic = ('comm-%s' % self.comm_id).encode('ascii') + self.topic = (f'comm-{self.comm_id).encode('ascii')}') self.outputs = self.state['outputs'] self.clear_before_next_output = False @@ -184,7 +184,7 @@ def output(self, outs, msg, display_id, cell_index): def handle_comm_msg(self, outs, msg, cell_index): super(VoilaExecutePreprocessor, self).handle_comm_msg(outs, msg, cell_index) - self.log.debug('comm msg: %r', msg) + self.log.debug(f'comm msg: {msg!r}') if msg['msg_type'] == 'comm_open' and msg['content'].get('target_name') == 'jupyter.widget': content = msg['content'] data = content['data'] diff --git a/voila/treehandler.py b/voila/treehandler.py index f6d791319..04a8f33d6 100644 --- a/voila/treehandler.py +++ b/voila/treehandler.py @@ -80,7 +80,7 @@ def allowed_content(content): url = url_path_join( self.base_url, service, url_escape(path), ) - self.log.debug("Redirecting %s to %s", self.request.path, url) + self.log.debug(f"Redirecting {self.request.path} to {url}") self.redirect(url) else: raise web.HTTPError(404) diff --git a/voila/utils.py b/voila/utils.py index 55cb9545e..704dfddd2 100644 --- a/voila/utils.py +++ b/voila/utils.py @@ -13,5 +13,5 @@ def get_server_root_dir(settings): home = os.path.expanduser('~') if root_dir.startswith(home + os.path.sep): # collapse $HOME to ~ - root_dir = '~' + root_dir[len(home):] + root_dir = f"~{root_dir[len(home):]}" return root_dir From aca3d58420220c3a198cc76fe5ff927165b1cab4 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 14 Jul 2020 18:28:17 +0200 Subject: [PATCH 02/12] Solve merge conflict in voila/app --- voila/app.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/voila/app.py b/voila/app.py index d956595ee..5c21fbe11 100644 --- a/voila/app.py +++ b/voila/app.py @@ -339,17 +339,6 @@ def initialize(self, argv=None): def setup_template_dirs(self): if self.voila_configuration.template: -<<<<<<< HEAD - collect_template_paths( - self.nbconvert_template_paths, - self.static_paths, - self.template_paths, - self.voila_configuration.template) - self.log.debug(f'using template: {self.voila_configuration.template}') - self.log.debug(f'nbconvert template paths:\n\t{"\n\t".join(self.nbconvert_template_paths)}') - self.log.debug(f'template paths:\n\t{"\n\t".join(self.template_paths)}') - self.log.debug(f'static paths:\n\t{"\n\t".join(self.static_paths)}') -======= template_name = self.voila_configuration.template self.template_paths = collect_template_paths(['voila', 'nbconvert'], template_name, prune=True) self.static_paths = collect_static_paths(['voila', 'nbconvert'], template_name) @@ -368,7 +357,6 @@ def setup_template_dirs(self): self.log.debug('using template: %s', self.voila_configuration.template) self.log.debug('template paths:\n\t%s', '\n\t'.join(self.template_paths)) self.log.debug('static paths:\n\t%s', '\n\t'.join(self.static_paths)) ->>>>>>> upstream/master if self.notebook_path and not os.path.exists(self.notebook_path): raise ValueError(f'Notebook not found: {self.notebook_path}') @@ -520,10 +508,6 @@ def random_ports(self, port, n): yield max(1, port + random.randint(-2*n, 2*n)) def listen(self): -<<<<<<< HEAD - self.app.listen(self.port) - self.log.info(f'Voila is running at:\n{self.display_url}') -======= for port in self.random_ports(self.port, self.port_retries+1): try: self.app.listen(port) @@ -547,7 +531,6 @@ def listen(self): self.log.critical(_('ERROR: the voila server could not be started because ' 'no available port could be found.')) self.exit(1) ->>>>>>> upstream/master if self.open_browser: self.launch_browser() From 23abbb6dc06e6c9aa8f1c5f71011fc79eebb0ffe Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 14 Jul 2020 18:57:35 +0200 Subject: [PATCH 03/12] Skip f-strings for logs --- setup.py | 2 +- voila/app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ec135e996..625ba06be 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def run(self): if strict or missing: log.warn('rebuilding js and css failed') if missing: - log.error(f'missing files: {missing}') + log.error('missing files: %s' % missing) raise e else: log.warn('rebuilding js and css failed (not a problem)') diff --git a/voila/app.py b/voila/app.py index 5c21fbe11..8c84e4f28 100644 --- a/voila/app.py +++ b/voila/app.py @@ -285,7 +285,7 @@ def _config_file_paths_default(self): @default('connection_dir_root') def _default_connection_dir(self): connection_dir = tempfile.gettempdir() - self.log.info(f'Using {connection_dir} to store connection files') + self.log.info('Using %s to store connection files' % connection_dir) return connection_dir @default('log_level') From 9fa478ad9dcc69740760d6c6b9a2b32ec5ad74c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Tue, 14 Jul 2020 19:01:07 +0200 Subject: [PATCH 04/12] Apply suggestions from code review --- voila/app.py | 10 +++++----- voila/treehandler.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/voila/app.py b/voila/app.py index 8c84e4f28..be4ddf69d 100644 --- a/voila/app.py +++ b/voila/app.py @@ -361,7 +361,7 @@ def setup_template_dirs(self): raise ValueError(f'Notebook not found: {self.notebook_path}') def _handle_signal_stop(self, sig, frame): - self.log.info(f'Handle signal {sig}.') + self.log.info('Handle signal %s.' % sig) self.ioloop.add_callback_from_signal(self.ioloop.stop) def start(self): @@ -369,8 +369,8 @@ def start(self): prefix='voila_', dir=self.connection_dir_root ) - self.log.info(f'Storing connection files in {self.connection_dir}.') - self.log.info(f'Serving static files from {self.static_root}.') + self.log.info('Storing connection files in %s.' % self.connection_dir) + self.log.info('Serving static files from %s.' % self.static_root) self.kernel_spec_manager = KernelSpecManager( parent=self @@ -475,7 +475,7 @@ def start(self): } )) else: - self.log.debug(f'serving directory: {self.root_dir!r}) + self.log.debug('serving directory: %r', self.root_dir) handlers.extend([ (self.server_url, VoilaTreeHandler, tree_handler_conf), (url_path_join(self.server_url, r'/voila/tree' + path_regex), @@ -547,7 +547,7 @@ def launch_browser(self): try: browser = webbrowser.get(self.browser or None) except webbrowser.Error as e: - self.log.warning(_(f'No web browser found: {e}.') + self.log.warning(_('No web browser found: %s.') % e) browser = None if not browser: diff --git a/voila/treehandler.py b/voila/treehandler.py index 04a8f33d6..f6d791319 100644 --- a/voila/treehandler.py +++ b/voila/treehandler.py @@ -80,7 +80,7 @@ def allowed_content(content): url = url_path_join( self.base_url, service, url_escape(path), ) - self.log.debug(f"Redirecting {self.request.path} to {url}") + self.log.debug("Redirecting %s to %s", self.request.path, url) self.redirect(url) else: raise web.HTTPError(404) From eaa3ba93b1e5a4f6bf58c8d87f92f22c5a9a0f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Tue, 14 Jul 2020 19:18:12 +0200 Subject: [PATCH 05/12] Apply suggestions from code review Co-authored-by: Jeremy Tuloup --- tests/app/template_cli_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/template_cli_test.py b/tests/app/template_cli_test.py index bf13caf94..e2b053e80 100644 --- a/tests/app/template_cli_test.py +++ b/tests/app/template_cli_test.py @@ -10,7 +10,7 @@ def voila_args_extra(): path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/')) path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default')) - return ['--template=None', f'--VoilaTest.template_paths=[{path_test_template, path_default}, {'--VoilaExecutor.timeout=240'}]' + return ['--template=None', f'--VoilaTest.template_paths=[{path_test_template}, {path_default}]', '--VoilaExecutor.timeout=240'] async def test_template_test(http_server_client, base_url): From 18e988d6df262f4750457cef874d08a709a59e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Tue, 14 Jul 2020 19:26:37 +0200 Subject: [PATCH 06/12] Apply suggestions from code review Co-authored-by: Jeremy Tuloup --- tests/app/template_cli_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/template_cli_test.py b/tests/app/template_cli_test.py index e2b053e80..2d9ed48d2 100644 --- a/tests/app/template_cli_test.py +++ b/tests/app/template_cli_test.py @@ -10,7 +10,7 @@ def voila_args_extra(): path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/')) path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default')) - return ['--template=None', f'--VoilaTest.template_paths=[{path_test_template}, {path_default}]', '--VoilaExecutor.timeout=240'] + return ['--template=None', f"--VoilaTest.template_paths=['{path_test_template}', '{path_default}']", '--VoilaExecutor.timeout=240'] async def test_template_test(http_server_client, base_url): From 4688f897208377114a54d5f1c2f666c69475056a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Tue, 14 Jul 2020 19:46:16 +0200 Subject: [PATCH 07/12] Apply suggestions from code review Co-authored-by: Jeremy Tuloup --- tests/app/execute_cpp_test.py | 2 +- tests/app/no_kernelspec_test.py | 2 +- tests/app/notebooks_test.py | 2 +- tests/app/template_cli_test.py | 2 +- tests/conftest.py | 2 +- tests/server/cwd_subdir_test.py | 2 +- tests/server/execute_cpp_test.py | 2 +- voila/execute.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/app/execute_cpp_test.py b/tests/app/execute_cpp_test.py index a425f872b..c7fbaddbd 100644 --- a/tests/app/execute_cpp_test.py +++ b/tests/app/execute_cpp_test.py @@ -6,7 +6,7 @@ @pytest.fixture def cpp_file_url(base_url): - return f"{base_url}/voila/render/print.xcpp" + return f"{base_url}voila/render/print.xcpp" @pytest.fixture diff --git a/tests/app/no_kernelspec_test.py b/tests/app/no_kernelspec_test.py index d5aac5c16..61c8c319e 100644 --- a/tests/app/no_kernelspec_test.py +++ b/tests/app/no_kernelspec_test.py @@ -3,7 +3,7 @@ @pytest.fixture def non_existing_kernel_notebook(base_url): - return f"{base_url}/voila/render/no_kernelspec.ipynb" + return f"{base_url}voila/render/no_kernelspec.ipynb" @pytest.fixture diff --git a/tests/app/notebooks_test.py b/tests/app/notebooks_test.py index c6d829c14..b2d5a6f7c 100644 --- a/tests/app/notebooks_test.py +++ b/tests/app/notebooks_test.py @@ -8,6 +8,6 @@ def voila_args(notebook_directory, voila_args_extra): async def test_other_comms(http_server_client, base_url): - response = await http_server_client.fetch(f'{base_url}/voila/render/other_comms.ipynb') + response = await http_server_client.fetch(f'{base_url}voila/render/other_comms.ipynb') html_text = response.body.decode('utf-8') assert 'This notebook executed' in html_text diff --git a/tests/app/template_cli_test.py b/tests/app/template_cli_test.py index 2d9ed48d2..9805a6aad 100644 --- a/tests/app/template_cli_test.py +++ b/tests/app/template_cli_test.py @@ -10,7 +10,7 @@ def voila_args_extra(): path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/')) path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default')) - return ['--template=None', f"--VoilaTest.template_paths=['{path_test_template}', '{path_default}']", '--VoilaExecutor.timeout=240'] + return ['--template=None', f'--VoilaTest.template_paths=[{path_test_template!r}, {path_default!r}]', '--VoilaExecutor.timeout=240'] async def test_template_test(http_server_client, base_url): diff --git a/tests/conftest.py b/tests/conftest.py index b87010208..decee3c09 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ def notebook_directory(): @pytest.fixture def print_notebook_url(base_url): - return f"{base_url}/voila/render/print.ipynb" + return f"{base_url}voila/render/print.ipynb" @pytest.fixture diff --git a/tests/server/cwd_subdir_test.py b/tests/server/cwd_subdir_test.py index 283410c03..d4285a6e5 100644 --- a/tests/server/cwd_subdir_test.py +++ b/tests/server/cwd_subdir_test.py @@ -5,7 +5,7 @@ @pytest.fixture def cwd_subdir_notebook_url(base_url): - return f"{base_url}/voila/render/subdir/cwd_subdir.ipynb" + return f"{base_url}voila/render/subdir/cwd_subdir.ipynb" @pytest.fixture diff --git a/tests/server/execute_cpp_test.py b/tests/server/execute_cpp_test.py index 8d1c878e1..7d8cfdcff 100644 --- a/tests/server/execute_cpp_test.py +++ b/tests/server/execute_cpp_test.py @@ -6,7 +6,7 @@ @pytest.fixture def cpp_file_url(base_url): - return f"{base_url}/voila/render/print.xcpp" + return f"{base_url}voila/render/print.xcpp" @pytest.fixture diff --git a/voila/execute.py b/voila/execute.py index 683384755..11ab774cf 100644 --- a/voila/execute.py +++ b/voila/execute.py @@ -109,7 +109,7 @@ def strip_code_cell_errors(self, cell): error_outputs = [output for output in outputs if output['output_type'] == 'error'] - error_message = 'There was an error when executing cell [{cell["execution_count"]}]. {self.cell_error_instruction}' + error_message = f'There was an error when executing cell [{cell["execution_count"]}]. {self.cell_error_instruction}' for output in error_outputs: output['ename'] = 'ExecutionError' From 55f5e5bde6521a0441e6b02b4c856c5395317585 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 14 Jul 2020 20:11:16 +0200 Subject: [PATCH 08/12] Apply suggestions from code review --- tests/app/cwd_subdir_test.py | 2 +- tests/app/non_existing_kernel_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/app/cwd_subdir_test.py b/tests/app/cwd_subdir_test.py index 8da8581c7..2439b1743 100644 --- a/tests/app/cwd_subdir_test.py +++ b/tests/app/cwd_subdir_test.py @@ -4,7 +4,7 @@ @pytest.fixture def cwd_subdir_notebook_url(base_url): - return f"{base_url}/voila/render/subdir/cwd_subdir.ipynb" + return f"{base_url}voila/render/subdir/cwd_subdir.ipynb" @pytest.fixture diff --git a/tests/app/non_existing_kernel_test.py b/tests/app/non_existing_kernel_test.py index ba4c04e20..9d1dd31af 100644 --- a/tests/app/non_existing_kernel_test.py +++ b/tests/app/non_existing_kernel_test.py @@ -3,7 +3,7 @@ @pytest.fixture def non_existing_kernel_notebook(base_url): - return f"{base_url}/voila/render/non_existing_kernel.ipynb" + return f"{base_url}voila/render/non_existing_kernel.ipynb" @pytest.fixture From 119f34dceaa6bfe94bbef05066c3feda79a13db5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:02:41 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/app/config_paths_test.py | 4 ++-- tests/app/nbextensions_test.py | 4 ++-- tests/server/tree_test.py | 2 +- voila/app.py | 20 ++++++++------------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/app/config_paths_test.py b/tests/app/config_paths_test.py index b6876ff2f..f412798ac 100644 --- a/tests/app/config_paths_test.py +++ b/tests/app/config_paths_test.py @@ -8,8 +8,8 @@ @pytest.fixture def voila_config_file_paths_arg(): - path = os.path.join(BASE_DIR, '..', 'configs', 'general') - return f'--VoilaTest.config_file_paths=[{path!r}]' + path = os.path.join(BASE_DIR, "..", "configs", "general") + return f"--VoilaTest.config_file_paths=[{path!r}]" def test_config_app(voila_app): diff --git a/tests/app/nbextensions_test.py b/tests/app/nbextensions_test.py index fa3b8eef4..735acae4e 100644 --- a/tests/app/nbextensions_test.py +++ b/tests/app/nbextensions_test.py @@ -19,8 +19,8 @@ def config(app): @pytest.fixture def voila_config_file_paths_arg(): # we don't want the tests to use any configuration on the system - path = os.path.abspath(os.path.join(BASE_DIR, '../configs/general')) - return f'--VoilaTest.config_file_paths=[{path!r}]' + path = os.path.abspath(os.path.join(BASE_DIR, "../configs/general")) + return f"--VoilaTest.config_file_paths=[{path!r}]" @pytest.mark.skip(reason="TODO: update for JupyterLab extensions") diff --git a/tests/server/tree_test.py b/tests/server/tree_test.py index 6831a1ce7..d7b3660ea 100644 --- a/tests/server/tree_test.py +++ b/tests/server/tree_test.py @@ -16,7 +16,7 @@ def jupyter_server_args_extra(): async def test_tree(http_server_client, base_url): - response = await http_server_client.fetch(f'{base_url}voila/tree') + response = await http_server_client.fetch(f"{base_url}voila/tree") assert response.code == 200 text = response.body.decode("utf-8") assert "print.ipynb" in text, "tree handler should render ipynb files" diff --git a/voila/app.py b/voila/app.py index cd35b59d1..ba937440a 100644 --- a/voila/app.py +++ b/voila/app.py @@ -387,7 +387,7 @@ def display_url(self): if not url.endswith("/"): url += "/" else: - if self.ip in ('', '0.0.0.0'): + if self.ip in ("", "0.0.0.0"): ip = socket.gethostname() else: ip = self.ip @@ -413,7 +413,7 @@ def connection_url(self): def _url(self, ip): # TODO: https / certfile # proto = 'https' if self.certfile else 'http' - proto = 'http' + proto = "http" return f"{proto}://{ip}:{self.port}{self.base_url}" config_file_paths = List( @@ -572,7 +572,7 @@ def setup_template_dirs(self): self.log.debug("template paths:\n\t%s", "\n\t".join(self.template_paths)) self.log.debug("static paths:\n\t%s", "\n\t".join(self.static_paths)) if self.notebook_path and not os.path.exists(self.notebook_path): - raise ValueError(f'Notebook not found: {self.notebook_path}') + raise ValueError(f"Notebook not found: {self.notebook_path}") def init_settings(self) -> Dict: """Initialize settings for Voila application.""" @@ -687,14 +687,12 @@ def init_handlers(self) -> List: handlers.extend( [ ( - url_path_join( - self.server_url, fr"/api/kernels/{_kernel_id_regex}" - ), + url_path_join(self.server_url, rf"/api/kernels/{_kernel_id_regex}"), KernelHandler, ), ( url_path_join( - self.server_url, fr"/api/kernels/{_kernel_id_regex}/channels" + self.server_url, rf"/api/kernels/{_kernel_id_regex}/channels" ), KernelWebsocketHandler, ), @@ -727,9 +725,7 @@ def init_handlers(self) -> List: if self.voila_configuration.preheat_kernel: handlers.append( ( - url_path_join( - self.server_url, fr"/voila/query/{_kernel_id_regex}" - ), + url_path_join(self.server_url, rf"/voila/query/{_kernel_id_regex}"), RequestInfoSocketHandler, ) ) @@ -778,7 +774,7 @@ def init_handlers(self) -> List: [ (self.server_url, TornadoVoilaTreeHandler, tree_handler_conf), ( - url_path_join(self.server_url, fr"/voila/tree{path_regex}"), + url_path_join(self.server_url, rf"/voila/tree{path_regex}"), TornadoVoilaTreeHandler, tree_handler_conf, ), @@ -795,7 +791,7 @@ def init_handlers(self) -> List: # On serving a directory, expose the content handler. ( url_path_join( - self.server_url, fr"/voila/api/contents{path_regex}" + self.server_url, rf"/voila/api/contents{path_regex}" ), VoilaContentsHandler, tree_handler_conf, From 67c74a812322e5721cc8c278745651ac754015f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Wed, 31 Jan 2024 16:37:23 +0100 Subject: [PATCH 10/12] Transform newly discovered strings into f-strings --- hatch_build.py | 6 +++--- tests/app/cgi-test.py | 2 +- tests/app/contents_handler_test.py | 2 +- tests/app/no_metadata.py | 2 +- tests/app/preheat_configuration_test.py | 2 +- tests/app/preheat_multiple_notebooks_test.py | 2 +- tests/app/show_traceback_test.py | 2 +- voila/app.py | 12 ++++++------ voila/notebook_renderer.py | 10 ++++------ voila/server_extension.py | 2 +- voila/tornado/contentshandler.py | 4 ++-- 11 files changed, 22 insertions(+), 24 deletions(-) diff --git a/hatch_build.py b/hatch_build.py index 9a695be06..ab12d1b19 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -31,7 +31,7 @@ def initialize(self, version, build_data): if not os.path.exists(".git") and os.path.exists(dest): # not running from git, nothing to do return - print("Downloading CSS: %s" % url) + print(f"Downloading CSS: {url}") try: css = urlopen(url).read() except Exception as e: @@ -39,11 +39,11 @@ def initialize(self, version, build_data): print(msg, file=sys.stderr) if os.path.exists(dest): - print("Already have CSS: %s, moving on." % dest) + print(f"Already have CSS: {dest}, moving on.") else: raise OSError("Need CSS to proceed.") return with open(dest, "wb") as f: f.write(css) - print("Downloaded Notebook CSS to %s" % dest) + print(f"Downloaded Notebook CSS to {dest}") diff --git a/tests/app/cgi-test.py b/tests/app/cgi-test.py index 2728d67f1..8721059f1 100644 --- a/tests/app/cgi-test.py +++ b/tests/app/cgi-test.py @@ -10,7 +10,7 @@ def notebook_cgi_path(base_url): @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ["--VoilaTest.root_dir=%r" % notebook_directory, *voila_args_extra] + return [f"--VoilaTest.root_dir={notebook_directory}", *voila_args_extra] async def test_cgi_using_query_parameters(http_server_client, notebook_cgi_path): diff --git a/tests/app/contents_handler_test.py b/tests/app/contents_handler_test.py index a8f7f75f8..afca933ec 100644 --- a/tests/app/contents_handler_test.py +++ b/tests/app/contents_handler_test.py @@ -15,7 +15,7 @@ def contents_prefix(base_url): @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ["--VoilaTest.root_dir=%r" % notebook_directory, *voila_args_extra] + return [f"--VoilaTest.root_dir={notebook_directory!r}", *voila_args_extra] @pytest.fixture diff --git a/tests/app/no_metadata.py b/tests/app/no_metadata.py index fe8fad17a..50c1b61b0 100644 --- a/tests/app/no_metadata.py +++ b/tests/app/no_metadata.py @@ -10,7 +10,7 @@ def non_existing_notebook_metadata(base_url): @pytest.fixture def voila_args(notebook_directory, voila_args_extra): - return ["--VoilaTest.root_dir=%r" % notebook_directory, *voila_args_extra] + return [f"--VoilaTest.root_dir={notebook_directory!r}", *voila_args_extra] async def test_non_existing_metadata( diff --git a/tests/app/preheat_configuration_test.py b/tests/app/preheat_configuration_test.py index 53cabe9f2..c2e9d1a86 100644 --- a/tests/app/preheat_configuration_test.py +++ b/tests/app/preheat_configuration_test.py @@ -13,7 +13,7 @@ @pytest.fixture def voila_config_file_paths_arg(): path = os.path.join(BASE_DIR, "..", "configs", "preheat") - return "--VoilaTest.config_file_paths=[%r]" % path + return f"--VoilaTest.config_file_paths=[{path!r}]" @pytest.fixture diff --git a/tests/app/preheat_multiple_notebooks_test.py b/tests/app/preheat_multiple_notebooks_test.py index 8e34f6131..bd395a2f2 100644 --- a/tests/app/preheat_multiple_notebooks_test.py +++ b/tests/app/preheat_multiple_notebooks_test.py @@ -13,7 +13,7 @@ @pytest.fixture def voila_config_file_paths_arg(): path = os.path.join(BASE_DIR, "..", "configs", "preheat") - return "--VoilaTest.config_file_paths=[%r]" % path + return f"--VoilaTest.config_file_paths=[{path!r}]" @pytest.fixture diff --git a/tests/app/show_traceback_test.py b/tests/app/show_traceback_test.py index bcdd8353e..cea9796f4 100644 --- a/tests/app/show_traceback_test.py +++ b/tests/app/show_traceback_test.py @@ -16,7 +16,7 @@ def notebook_show_traceback_path(base_url): @pytest.fixture def voila_args(notebook_directory, voila_args_extra, show_tracebacks): return [ - "--VoilaTest.root_dir=%r" % notebook_directory, + f"--VoilaTest.root_dir={notebook_directory!r}", f"--VoilaConfiguration.show_tracebacks={show_tracebacks}", *voila_args_extra, ] diff --git a/voila/app.py b/voila/app.py index ba937440a..7c46c08c5 100644 --- a/voila/app.py +++ b/voila/app.py @@ -435,7 +435,7 @@ def _config_file_paths_default(self): @default("connection_dir_root") def _default_connection_dir(self): connection_dir = tempfile.gettempdir() - self.log.info("Using %s to store connection files" % connection_dir) + self.log.info(f"Using {connection_dir} to store connection files") return connection_dir @default("log_level") @@ -532,7 +532,7 @@ def initialize(self, argv=None): f"argument is neither a file nor a directory: {arg!r}" ) elif len(self.extra_args) != 0: - raise ValueError("provided more than 1 argument: %r" % self.extra_args) + raise ValueError(f"provided more than 1 argument: {self.extra_args!r}") # then we load the config self.load_config_file("voila", path=self.config_file_paths) @@ -568,7 +568,7 @@ def setup_template_dirs(self): self.voila_configuration.config.VoilaConfiguration = Config( conf["traitlet_configuration"] ) - self.log.debug("using template: %s", self.voila_configuration.template) + self.log.debug(f"using template: {self.voila_configuration.template}") self.log.debug("template paths:\n\t%s", "\n\t".join(self.template_paths)) self.log.debug("static paths:\n\t%s", "\n\t".join(self.static_paths)) if self.notebook_path and not os.path.exists(self.notebook_path): @@ -844,14 +844,14 @@ def listen(self): except OSError as e: if e.errno == errno.EADDRINUSE: self.log.info( - _("The port %i is already in use, trying another port.") % port + _(f"The port {port} is already in use, trying another port.") ) continue elif e.errno in ( errno.EACCES, getattr(errno, "WSAEACCES", errno.EACCES), ): - self.log.warning(_("Permission to listen on port %i denied") % port) + self.log.warning(_(f"Permission to listen on port {port} denied")) continue else: raise @@ -884,7 +884,7 @@ def launch_browser(self): try: browser = webbrowser.get(self.browser or None) except webbrowser.Error as e: - self.log.warning(_("No web browser found: %s.") % e) + self.log.warning(_(f"No web browser found: {e}.")) browser = None if not browser: diff --git a/voila/notebook_renderer.py b/voila/notebook_renderer.py index 2ba094e59..167a999b1 100644 --- a/voila/notebook_renderer.py +++ b/voila/notebook_renderer.py @@ -266,7 +266,7 @@ async def _jinja_cell_generator(self, nb, kernel_id): break except CellExecutionError: self.log.exception( - "Error at server while executing cell: %r", input_cell + f"Error at server while executing cell: {input_cell!r}", ) if self.executor.should_strip_error(): strip_code_cell_warnings(input_cell) @@ -275,7 +275,7 @@ async def _jinja_cell_generator(self, nb, kernel_id): break except Exception as e: self.log.exception( - "Error at server while executing cell: %r", input_cell + f"Error at server while executing cell: {input_cell!r}", ) output_cell = nbformat.v4.new_code_cell() if self.executor.should_strip_error(): @@ -345,9 +345,7 @@ async def fix_notebook(self, notebook): language.lower(), kernel_specs=all_kernel_specs ) self.log.warning( - "Could not find a kernel named %r, will use %r", - missing_kernel_name, - kernel_name, + f"Could not find a kernel named {missing_kernel_name!r}, will use {kernel_name!r}", ) # We make sure the notebook's kernelspec is correct notebook.metadata.kernelspec.name = kernel_name @@ -397,5 +395,5 @@ async def find_kernel_name_for_language(self, kernel_language, kernel_specs=None return matches[0] else: raise tornado.web.HTTPError( - 500, "No Jupyter kernel for language %r found" % kernel_language + 500, f"No Jupyter kernel for language {kernel_language!r} found" ) diff --git a/voila/server_extension.py b/voila/server_extension.py index 959990c05..f335ffd4a 100644 --- a/voila/server_extension.py +++ b/voila/server_extension.py @@ -120,7 +120,7 @@ def _load_jupyter_server_extension(server_app): }, ), ( - url_path_join(base_url, r"/voila/api/contents%s" % path_regex), + url_path_join(base_url, fr"/voila/api/contents{path_regex}"), VoilaContentsHandler, tree_handler_conf, ), diff --git a/voila/tornado/contentshandler.py b/voila/tornado/contentshandler.py index b49dfc3e3..3665ed861 100644 --- a/voila/tornado/contentshandler.py +++ b/voila/tornado/contentshandler.py @@ -34,10 +34,10 @@ async def get(self, path=""): format = self.get_query_argument("format", default=None) if format not in {None, "text", "base64"}: - raise web.HTTPError(400, "Format %r is invalid" % format) + raise web.HTTPError(400, f"Format {format!r} is invalid") content_str = self.get_query_argument("content", default="1") if content_str not in {"0", "1"}: - raise web.HTTPError(400, "Content %r is invalid" % content_str) + raise web.HTTPError(400, f"Content {content_str!r} is invalid") content = int(content_str or "") if not cm.allow_hidden and await ensure_async(cm.is_hidden(path)): From 21fb1a9a5f878d57f31a6393610909ace1c50b92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:37:59 +0000 Subject: [PATCH 11/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- voila/server_extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voila/server_extension.py b/voila/server_extension.py index f335ffd4a..d57253088 100644 --- a/voila/server_extension.py +++ b/voila/server_extension.py @@ -120,7 +120,7 @@ def _load_jupyter_server_extension(server_app): }, ), ( - url_path_join(base_url, fr"/voila/api/contents{path_regex}"), + url_path_join(base_url, rf"/voila/api/contents{path_regex}"), VoilaContentsHandler, tree_handler_conf, ), From 0bca36e88e146b1f084f117db5d7ce1afb0cda74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Sun, 4 Feb 2024 22:57:04 +0100 Subject: [PATCH 12/12] Undo changes to log.* due to performance issues --- voila/app.py | 22 +++++++++++----------- voila/notebook_renderer.py | 8 +++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/voila/app.py b/voila/app.py index 7c46c08c5..24724effd 100644 --- a/voila/app.py +++ b/voila/app.py @@ -435,7 +435,7 @@ def _config_file_paths_default(self): @default("connection_dir_root") def _default_connection_dir(self): connection_dir = tempfile.gettempdir() - self.log.info(f"Using {connection_dir} to store connection files") + self.log.info("Using %s to store connection files" % connection_dir) return connection_dir @default("log_level") @@ -516,7 +516,7 @@ def _init_asyncio_patch(self): def initialize(self, argv=None): self._init_asyncio_patch() - self.log.debug(f"Searching path {self.config_file_paths} for config files") + self.log.debug("Searching path %s for config files", self.config_file_paths) # to make config_file_paths settable via cmd line, we first need to parse it super().initialize(argv) if len(self.extra_args) == 1: @@ -568,7 +568,7 @@ def setup_template_dirs(self): self.voila_configuration.config.VoilaConfiguration = Config( conf["traitlet_configuration"] ) - self.log.debug(f"using template: {self.voila_configuration.template}") + self.log.debug("using template: %s", self.voila_configuration.template) self.log.debug("template paths:\n\t%s", "\n\t".join(self.template_paths)) self.log.debug("static paths:\n\t%s", "\n\t".join(self.static_paths)) if self.notebook_path and not os.path.exists(self.notebook_path): @@ -769,7 +769,7 @@ def init_handlers(self) -> List: ) ) else: - self.log.debug(f"serving directory: {self.root_dir!r}") + self.log.debug("serving directory: %r", self.root_dir) handlers.extend( [ (self.server_url, TornadoVoilaTreeHandler, tree_handler_conf), @@ -804,8 +804,8 @@ def start(self): self.connection_dir = tempfile.mkdtemp( prefix="voila_", dir=self.connection_dir_root ) - self.log.info(f"Storing connection files in {self.connection_dir}.") - self.log.info(f"Serving static files from {self.static_root}.") + self.log.info("Storing connection files in %s." % self.connection_dir) + self.log.info("Serving static files from %s." % self.static_root) settings = self.init_settings() @@ -816,7 +816,7 @@ def start(self): self.listen() def _handle_signal_stop(self, sig, frame): - self.log.info(f"Handle signal {sig}.") + self.log.info("Handle signal %s." % sig) self.ioloop.add_callback_from_signal(self.ioloop.stop) def stop(self): @@ -840,18 +840,18 @@ def listen(self): try: self.app.listen(port, self.ip) self.port = port - self.log.info(f"VoilĂ  is running at:\n{self.display_url}") + self.log.info("VoilĂ  is running at:\n%s" % self.display_url) except OSError as e: if e.errno == errno.EADDRINUSE: self.log.info( - _(f"The port {port} is already in use, trying another port.") + _("The port %i is already in use, trying another port.") % port ) continue elif e.errno in ( errno.EACCES, getattr(errno, "WSAEACCES", errno.EACCES), ): - self.log.warning(_(f"Permission to listen on port {port} denied")) + self.log.warning(_("Permission to listen on port %i denied") % port) continue else: raise @@ -884,7 +884,7 @@ def launch_browser(self): try: browser = webbrowser.get(self.browser or None) except webbrowser.Error as e: - self.log.warning(_(f"No web browser found: {e}.")) + self.log.warning(_("No web browser found: %s.") % e) browser = None if not browser: diff --git a/voila/notebook_renderer.py b/voila/notebook_renderer.py index 167a999b1..079b8bb5f 100644 --- a/voila/notebook_renderer.py +++ b/voila/notebook_renderer.py @@ -266,7 +266,7 @@ async def _jinja_cell_generator(self, nb, kernel_id): break except CellExecutionError: self.log.exception( - f"Error at server while executing cell: {input_cell!r}", + "Error at server while executing cell: %r", input_cell ) if self.executor.should_strip_error(): strip_code_cell_warnings(input_cell) @@ -275,7 +275,7 @@ async def _jinja_cell_generator(self, nb, kernel_id): break except Exception as e: self.log.exception( - f"Error at server while executing cell: {input_cell!r}", + "Error at server while executing cell: %r", input_cell ) output_cell = nbformat.v4.new_code_cell() if self.executor.should_strip_error(): @@ -345,7 +345,9 @@ async def fix_notebook(self, notebook): language.lower(), kernel_specs=all_kernel_specs ) self.log.warning( - f"Could not find a kernel named {missing_kernel_name!r}, will use {kernel_name!r}", + "Could not find a kernel named %r, will use %r", + missing_kernel_name, + kernel_name, ) # We make sure the notebook's kernelspec is correct notebook.metadata.kernelspec.name = kernel_name