From 12b01cb423e0af73f31636589d1ffb4c64378dac Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:29:38 +0100 Subject: [PATCH] update Black with line 120 (#755) * update Black with line 120 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixing --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 1 - docs/conf.py | 4 +- papermill/cli.py | 24 +++------- papermill/engines.py | 8 +--- papermill/exceptions.py | 4 +- papermill/execute.py | 8 +--- papermill/inspection.py | 9 +--- papermill/iorw.py | 13 ++---- papermill/s3.py | 12 ++--- papermill/tests/test_abs.py | 32 ++++--------- papermill/tests/test_adl.py | 8 +--- papermill/tests/test_autosave.py | 4 +- papermill/tests/test_cli.py | 60 ++++++------------------ papermill/tests/test_engines.py | 56 ++++++----------------- papermill/tests/test_execute.py | 68 +++++++--------------------- papermill/tests/test_gcs.py | 20 ++------ papermill/tests/test_hdfs.py | 8 +--- papermill/tests/test_iorw.py | 12 ++--- papermill/tests/test_parameterize.py | 16 ++----- papermill/tests/test_s3.py | 4 +- papermill/tests/test_translators.py | 34 ++++---------- papermill/translators.py | 24 +++------- pyproject.toml | 29 +----------- setup.py | 4 +- 24 files changed, 109 insertions(+), 353 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cbd9ba92..adb877b6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,6 @@ repos: hooks: - id: black name: Black code - args: ["-S"] - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 diff --git a/docs/conf.py b/docs/conf.py index 00ddfde6..20405878 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -132,9 +132,7 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, 'papermill.tex', 'papermill Documentation', 'nteract team', 'manual') -] +latex_documents = [(master_doc, 'papermill.tex', 'papermill Documentation', 'nteract team', 'manual')] # -- Options for manual page output --------------------------------------- diff --git a/papermill/cli.py b/papermill/cli.py index 7d86e038..8593f543 100755 --- a/papermill/cli.py +++ b/papermill/cli.py @@ -44,21 +44,11 @@ def print_papermill_version(ctx, param, value): default=False, help='Display parameters information for the given notebook path.', ) -@click.option( - '--parameters', '-p', nargs=2, multiple=True, help='Parameters to pass to the parameters cell.' -) -@click.option( - '--parameters_raw', '-r', nargs=2, multiple=True, help='Parameters to be read as raw string.' -) -@click.option( - '--parameters_file', '-f', multiple=True, help='Path to YAML file containing parameters.' -) -@click.option( - '--parameters_yaml', '-y', multiple=True, help='YAML string to be used as parameters.' -) -@click.option( - '--parameters_base64', '-b', multiple=True, help='Base64 encoded YAML string as parameters.' -) +@click.option('--parameters', '-p', nargs=2, multiple=True, help='Parameters to pass to the parameters cell.') +@click.option('--parameters_raw', '-r', nargs=2, multiple=True, help='Parameters to be read as raw string.') +@click.option('--parameters_file', '-f', multiple=True, help='Path to YAML file containing parameters.') +@click.option('--parameters_yaml', '-y', multiple=True, help='YAML string to be used as parameters.') +@click.option('--parameters_base64', '-b', multiple=True, help='Base64 encoded YAML string as parameters.') @click.option( '--inject-input-path', is_flag=True, @@ -108,9 +98,7 @@ def print_papermill_version(ctx, param, value): help='Language for notebook execution. Ignores language in the notebook document metadata.', ) @click.option('--cwd', default=None, help='Working directory to run notebook in.') -@click.option( - '--progress-bar/--no-progress-bar', default=None, help="Flag for turning on the progress bar." -) +@click.option('--progress-bar/--no-progress-bar', default=None, help="Flag for turning on the progress bar.") @click.option( '--log-output/--no-log-output', default=False, diff --git a/papermill/engines.py b/papermill/engines.py index bb936025..ba075615 100644 --- a/papermill/engines.py +++ b/papermill/engines.py @@ -95,9 +95,7 @@ class NotebookExecutionManager: COMPLETED = "completed" FAILED = "failed" - def __init__( - self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30 - ): + def __init__(self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30): self.nb = nb self.output_path = output_path self.log_output = log_output @@ -278,9 +276,7 @@ def notebook_complete(self, **kwargs): self.end_time = self.now() self.nb.metadata.papermill['end_time'] = self.end_time.isoformat() if self.nb.metadata.papermill.get('start_time'): - self.nb.metadata.papermill['duration'] = ( - self.end_time - self.start_time - ).total_seconds() + self.nb.metadata.papermill['duration'] = (self.end_time - self.start_time).total_seconds() # Cleanup cell statuses in case callbacks were never called for cell in self.nb.cells: diff --git a/papermill/exceptions.py b/papermill/exceptions.py index 73ed4574..26b68cf8 100644 --- a/papermill/exceptions.py +++ b/papermill/exceptions.py @@ -60,9 +60,7 @@ def missing_dependency_generator(package, dep): def missing_dep(): raise PapermillOptionalDependencyException( "The {package} optional dependency is missing. " - "Please run pip install papermill[{dep}] to install this dependency".format( - package=package, dep=dep - ) + "Please run pip install papermill[{dep}] to install this dependency".format(package=package, dep=dep) ) return missing_dep diff --git a/papermill/execute.py b/papermill/execute.py index 930f4a43..27e5e493 100644 --- a/papermill/execute.py +++ b/papermill/execute.py @@ -110,9 +110,7 @@ def execute_notebook( if not prepare_only: # Dropdown to the engine to fetch the kernel name from the notebook document - kernel_name = papermill_engines.nb_kernel_name( - engine_name=engine_name, nb=nb, name=kernel_name - ) + kernel_name = papermill_engines.nb_kernel_name(engine_name=engine_name, nb=nb, name=kernel_name) # Execute the Notebook in `cwd` if it is set with chdir(cwd): nb = papermill_engines.execute_notebook_with_engine( @@ -168,9 +166,7 @@ def prepare_notebook_metadata(nb, input_path, output_path, report_mode=False): ERROR_MARKER_TAG = "papermill-error-cell-tag" -ERROR_STYLE = ( - 'style="color:red; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; font-size:2em;"' -) +ERROR_STYLE = 'style="color:red; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; font-size:2em;"' ERROR_MESSAGE_TEMPLATE = ( '' diff --git a/papermill/inspection.py b/papermill/inspection.py index 08e38648..36527bb0 100644 --- a/papermill/inspection.py +++ b/papermill/inspection.py @@ -46,11 +46,7 @@ def _infer_parameters(nb, name=None, language=None): try: params = translator.inspect(parameter_cell) except NotImplementedError: - logger.warning( - "Translator for '{}' language does not support parameter introspection.".format( - language - ) - ) + logger.warning(f"Translator for '{language}' language does not support parameter introspection.") return params @@ -93,8 +89,7 @@ def display_notebook_help(ctx, notebook_path, parameters): click.echo(param_help) else: click.echo( - "\n Can't infer anything about this notebook's parameters. " - "It may not have any parameter defined." + "\n Can't infer anything about this notebook's parameters. " "It may not have any parameter defined." ) return 0 diff --git a/papermill/iorw.py b/papermill/iorw.py index 529026f4..653d9bbe 100644 --- a/papermill/iorw.py +++ b/papermill/iorw.py @@ -146,13 +146,8 @@ def get_handler(self, path, extensions=None): if extensions: if not fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*.*'): - warnings.warn( - "the file is not specified with any extension : " + os.path.basename(path) - ) - elif not any( - fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*' + ext) - for ext in extensions - ): + warnings.warn("the file is not specified with any extension : " + os.path.basename(path)) + elif not any(fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*' + ext) for ext in extensions): warnings.warn(f"The specified file ({path}) does not end in one of {extensions}") local_handler = None @@ -319,9 +314,7 @@ def write(self, buf, path): @retry( retry=retry_if_exception_type(PapermillRateLimitException), stop=stop_after_attempt(self.RATE_LIMIT_RETRIES), - wait=wait_exponential( - multiplier=self.RETRY_MULTIPLIER, min=self.RETRY_DELAY, max=self.RETRY_MAX_DELAY - ), + wait=wait_exponential(multiplier=self.RETRY_MULTIPLIER, min=self.RETRY_DELAY, max=self.RETRY_MAX_DELAY), reraise=True, ) def retry_write(): diff --git a/papermill/s3.py b/papermill/s3.py index 6032f541..04b61627 100644 --- a/papermill/s3.py +++ b/papermill/s3.py @@ -32,9 +32,7 @@ def __init__(self, name, service=None): def list(self, prefix='', delimiter=None): """Limits a list of Bucket's objects based on prefix and delimiter.""" - return self.service._list( - bucket=self.name, prefix=prefix, delimiter=delimiter, objects=True - ) + return self.service._list(bucket=self.name, prefix=prefix, delimiter=delimiter, objects=True) class Prefix: @@ -210,9 +208,7 @@ def sort(item): return item['Prefix'] for page in page_iterator: - locations = sorted( - [i for i in page.get('Contents', []) + page.get('CommonPrefixes', [])], key=sort - ) + locations = sorted([i for i in page.get('Contents', []) + page.get('CommonPrefixes', [])], key=sort) for item in locations: if objects or keys: @@ -244,9 +240,7 @@ def _put(self, source, dest, num_callbacks=10, policy='bucket-owner-full-control obj.upload_file(source, ExtraArgs={'ACL': policy}) return key - def _put_string( - self, source, dest, num_callbacks=10, policy='bucket-owner-full-control', **kwargs - ): + def _put_string(self, source, dest, num_callbacks=10, policy='bucket-owner-full-control', **kwargs): key = self._get_key(dest) obj = self.s3.Object(key.bucket.name, key.name) diff --git a/papermill/tests/test_abs.py b/papermill/tests/test_abs.py index eda1a94e..57dff73f 100644 --- a/papermill/tests/test_abs.py +++ b/papermill/tests/test_abs.py @@ -42,23 +42,17 @@ def setUp(self): def test_split_url_raises_exception_on_invalid_url(self): with self.assertRaises(Exception) as context: AzureBlobStore._split_url("this_is_not_a_valid_url") - self.assertTrue( - "Invalid azure blob url 'this_is_not_a_valid_url'" in str(context.exception) - ) + self.assertTrue("Invalid azure blob url 'this_is_not_a_valid_url'" in str(context.exception)) def test_split_url_splits_valid_url(self): - params = AzureBlobStore._split_url( - "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken" - ) + params = AzureBlobStore._split_url("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken") self.assertEqual(params["account"], "myaccount") self.assertEqual(params["container"], "sascontainer") self.assertEqual(params["blob"], "sasblob.txt") self.assertEqual(params["sas_token"], "sastoken") def test_split_url_splits_valid_url_no_sas(self): - params = AzureBlobStore._split_url( - "abs://myaccount.blob.core.windows.net/container/blob.txt" - ) + params = AzureBlobStore._split_url("abs://myaccount.blob.core.windows.net/container/blob.txt") self.assertEqual(params["account"], "myaccount") self.assertEqual(params["container"], "container") self.assertEqual(params["blob"], "blob.txt") @@ -75,9 +69,7 @@ def test_split_url_splits_valid_url_with_prefix(self): def test_listdir_calls(self): self.assertEqual( - self.abs.listdir( - "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken" - ), + self.abs.listdir("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"), ["foo", "bar", "baz"], ) self._blob_service_client.get_container_client.assert_called_once_with("sascontainer") @@ -86,23 +78,15 @@ def test_listdir_calls(self): @patch("papermill.abs.io.BytesIO", side_effect=MockBytesIO) def test_reads_file(self, mockBytesIO): self.assertEqual( - self.abs.read( - "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken" - ), + self.abs.read("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"), ["hello", "world!"], ) - self._blob_service_client.get_blob_client.assert_called_once_with( - "sascontainer", "sasblob.txt" - ) + self._blob_service_client.get_blob_client.assert_called_once_with("sascontainer", "sasblob.txt") self.download_blob.assert_called_once_with() def test_write_file(self): - self.abs.write( - "hello world", "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken" - ) - self._blob_service_client.get_blob_client.assert_called_once_with( - "sascontainer", "sasblob.txt" - ) + self.abs.write("hello world", "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken") + self._blob_service_client.get_blob_client.assert_called_once_with("sascontainer", "sasblob.txt") self.upload_blob.assert_called_once_with(data="hello world", overwrite=True) def test_blob_service_client(self): diff --git a/papermill/tests/test_adl.py b/papermill/tests/test_adl.py index d0848998..454f38fb 100644 --- a/papermill/tests/test_adl.py +++ b/papermill/tests/test_adl.py @@ -12,9 +12,7 @@ class ADLTest(unittest.TestCase): """ def setUp(self): - self.ls = Mock( - return_value=["path/to/directory/foo", "path/to/directory/bar", "path/to/directory/baz"] - ) + self.ls = Mock(return_value=["path/to/directory/foo", "path/to/directory/bar", "path/to/directory/baz"]) self.fakeFile = MagicMock() self.fakeFile.__iter__.return_value = [b"a", b"b", b"c"] self.fakeFile.__enter__.return_value = self.fakeFile @@ -45,9 +43,7 @@ def test_listdir_calls_ls_on_adl_adapter(self): self.ls.assert_called_once_with("path/to/directory") def test_read_opens_and_reads_file(self): - self.assertEqual( - self.adl.read("adl://foo_store.azuredatalakestore.net/path/to/file"), ["a", "b", "c"] - ) + self.assertEqual(self.adl.read("adl://foo_store.azuredatalakestore.net/path/to/file"), ["a", "b", "c"]) self.fakeFile.__iter__.assert_called_once_with() def test_write_opens_file_and_writes_to_it(self): diff --git a/papermill/tests/test_autosave.py b/papermill/tests/test_autosave.py index c5fa553e..74ae06e8 100644 --- a/papermill/tests/test_autosave.py +++ b/papermill/tests/test_autosave.py @@ -19,9 +19,7 @@ def setUp(self): self.nb = nbformat.read(self.notebook_path, as_version=4) def test_autosave_not_too_fast(self): - nb_man = NotebookExecutionManager( - self.nb, output_path='test.ipynb', autosave_cell_every=0.5 - ) + nb_man = NotebookExecutionManager(self.nb, output_path='test.ipynb', autosave_cell_every=0.5) with patch.object(engines, 'write_ipynb') as write_mock: write_mock.reset_mock() assert write_mock.call_count == 0 # check that the mock is sane diff --git a/papermill/tests/test_cli.py b/papermill/tests/test_cli.py index 095ad710..c7ffadaf 100755 --- a/papermill/tests/test_cli.py +++ b/papermill/tests/test_cli.py @@ -99,12 +99,8 @@ def setUp(self): self.default_execute_kwargs['input_path'], self.default_execute_kwargs['output_path'], ] - self.sample_yaml_file = os.path.join( - os.path.dirname(__file__), 'parameters', 'example.yaml' - ) - self.sample_json_file = os.path.join( - os.path.dirname(__file__), 'parameters', 'example.json' - ) + self.sample_yaml_file = os.path.join(os.path.dirname(__file__), 'parameters', 'example.yaml') + self.sample_json_file = os.path.join(os.path.dirname(__file__), 'parameters', 'example.json') def augment_execute_kwargs(self, **new_kwargs): kwargs = self.default_execute_kwargs.copy() @@ -113,21 +109,13 @@ def augment_execute_kwargs(self, **new_kwargs): @patch(cli.__name__ + '.execute_notebook') def test_parameters(self, execute_patch): - self.runner.invoke( - papermill, self.default_args + ['-p', 'foo', 'bar', '--parameters', 'baz', '42'] - ) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'foo': 'bar', 'baz': 42}) - ) + self.runner.invoke(papermill, self.default_args + ['-p', 'foo', 'bar', '--parameters', 'baz', '42']) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'foo': 'bar', 'baz': 42})) @patch(cli.__name__ + '.execute_notebook') def test_parameters_raw(self, execute_patch): - self.runner.invoke( - papermill, self.default_args + ['-r', 'foo', 'bar', '--parameters_raw', 'baz', '42'] - ) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'foo': 'bar', 'baz': '42'}) - ) + self.runner.invoke(papermill, self.default_args + ['-r', 'foo', 'bar', '--parameters_raw', 'baz', '42']) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'foo': 'bar', 'baz': '42'})) @patch(cli.__name__ + '.execute_notebook') def test_parameters_file(self, execute_patch): @@ -151,16 +139,12 @@ def test_parameters_yaml(self, execute_patch): papermill, self.default_args + ['-y', '{"foo": "bar"}', '--parameters_yaml', '{"foo2": ["baz"]}'], ) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'foo': 'bar', 'foo2': ['baz']}) - ) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'foo': 'bar', 'foo2': ['baz']})) @patch(cli.__name__ + '.execute_notebook') def test_parameters_yaml_date(self, execute_patch): self.runner.invoke(papermill, self.default_args + ['-y', 'a_date: 2019-01-01']) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'a_date': '2019-01-01'}) - ) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'a_date': '2019-01-01'})) @patch(cli.__name__ + '.execute_notebook') def test_parameters_empty(self, execute_patch): @@ -200,9 +184,7 @@ def test_parameters_yaml_override(self, execute_patch): ) ) - @patch( - cli.__name__ + '.execute_notebook', side_effect=nbclient.exceptions.DeadKernelError("Fake") - ) + @patch(cli.__name__ + '.execute_notebook', side_effect=nbclient.exceptions.DeadKernelError("Fake")) def test_parameters_dead_kernel(self, execute_patch): result = self.runner.invoke( papermill, @@ -219,18 +201,12 @@ def test_parameters_base64(self, execute_patch): 'eydmb28nOiAxfQ==', ] self.runner.invoke(papermill, self.default_args + extra_args) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'foo': 1, 'bar': 2}) - ) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'foo': 1, 'bar': 2})) @patch(cli.__name__ + '.execute_notebook') def test_parameters_base64_date(self, execute_patch): - self.runner.invoke( - papermill, self.default_args + ['--parameters_base64', 'YV9kYXRlOiAyMDE5LTAxLTAx'] - ) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(parameters={'a_date': '2019-01-01'}) - ) + self.runner.invoke(papermill, self.default_args + ['--parameters_base64', 'YV9kYXRlOiAyMDE5LTAxLTAx']) + execute_patch.assert_called_with(**self.augment_execute_kwargs(parameters={'a_date': '2019-01-01'})) @patch(cli.__name__ + '.execute_notebook') def test_inject_input_path(self, execute_patch): @@ -261,9 +237,7 @@ def test_inject_paths(self, execute_patch): @patch(cli.__name__ + '.execute_notebook') def test_engine(self, execute_patch): self.runner.invoke(papermill, self.default_args + ['--engine', 'engine-that-could']) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(engine_name='engine-that-could') - ) + execute_patch.assert_called_with(**self.augment_execute_kwargs(engine_name='engine-that-could')) @patch(cli.__name__ + '.execute_notebook') def test_prepare_only(self, execute_patch): @@ -308,9 +282,7 @@ def test_log_output(self, execute_patch): @patch(cli.__name__ + '.execute_notebook') def test_log_output_plus_progress(self, execute_patch): self.runner.invoke(papermill, self.default_args + ['--log-output', '--progress-bar']) - execute_patch.assert_called_with( - **self.augment_execute_kwargs(log_output=True, progress_bar=True) - ) + execute_patch.assert_called_with(**self.augment_execute_kwargs(log_output=True, progress_bar=True)) @patch(cli.__name__ + '.execute_notebook') def test_no_log_output(self, execute_patch): @@ -447,9 +419,7 @@ def notebook(): ) -require_papermill_installed = pytest.mark.skipif( - not papermill_version(), reason='papermill is not installed' -) +require_papermill_installed = pytest.mark.skipif(not papermill_version(), reason='papermill is not installed') @require_papermill_installed diff --git a/papermill/tests/test_engines.py b/papermill/tests/test_engines.py index 1d2de022..db5ee17c 100644 --- a/papermill/tests/test_engines.py +++ b/papermill/tests/test_engines.py @@ -168,9 +168,7 @@ def test_cell_complete_after_cell_start(self): start_time = dateutil.parser.parse(cell.metadata.papermill['start_time']) self.assertEqual(cell.metadata.papermill['end_time'], fixed_now.isoformat()) - self.assertEqual( - cell.metadata.papermill['duration'], (fixed_now - start_time).total_seconds() - ) + self.assertEqual(cell.metadata.papermill['duration'], (fixed_now - start_time).total_seconds()) self.assertFalse(cell.metadata.papermill['exception']) self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED) @@ -217,9 +215,7 @@ def test_cell_complete_after_cell_exception(self): start_time = dateutil.parser.parse(cell.metadata.papermill['start_time']) self.assertEqual(cell.metadata.papermill['end_time'], fixed_now.isoformat()) - self.assertEqual( - cell.metadata.papermill['duration'], (fixed_now - start_time).total_seconds() - ) + self.assertEqual(cell.metadata.papermill['duration'], (fixed_now - start_time).total_seconds()) self.assertTrue(cell.metadata.papermill['exception']) self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.FAILED) @@ -251,9 +247,7 @@ def test_notebook_complete(self): start_time = dateutil.parser.parse(nb_man.nb.metadata.papermill['start_time']) self.assertEqual(nb_man.nb.metadata.papermill['end_time'], fixed_now.isoformat()) - self.assertEqual( - nb_man.nb.metadata.papermill['duration'], (fixed_now - start_time).total_seconds() - ) + self.assertEqual(nb_man.nb.metadata.papermill['duration'], (fixed_now - start_time).total_seconds()) self.assertFalse(nb_man.nb.metadata.papermill['exception']) nb_man.save.assert_called_once() @@ -279,12 +273,8 @@ def test_notebook_complete_cell_status_with_failed(self): nb_man.notebook_start() nb_man.cell_exception(nb_man.nb.cells[1]) nb_man.notebook_complete() - self.assertEqual( - nb_man.nb.cells[0].metadata.papermill['status'], NotebookExecutionManager.COMPLETED - ) - self.assertEqual( - nb_man.nb.cells[1].metadata.papermill['status'], NotebookExecutionManager.FAILED - ) + self.assertEqual(nb_man.nb.cells[0].metadata.papermill['status'], NotebookExecutionManager.COMPLETED) + self.assertEqual(nb_man.nb.cells[1].metadata.papermill['status'], NotebookExecutionManager.FAILED) for cell in nb_man.nb.cells[2:]: self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.PENDING) @@ -319,9 +309,7 @@ def test_wrap_and_execute_notebook(self): autosave_cell_every=30, ) wrap_mock.return_value.notebook_start.assert_called_once() - exec_mock.assert_called_once_with( - wrap_mock.return_value, 'python', log_output=True, bar='baz' - ) + exec_mock.assert_called_once_with(wrap_mock.return_value, 'python', log_output=True, bar='baz') wrap_mock.return_value.notebook_complete.assert_called_once() wrap_mock.return_value.cleanup_pbar.assert_called_once() @@ -334,9 +322,7 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs): nb_man.cell_complete(cell) with patch.object(NotebookExecutionManager, 'save') as save_mock: - nb = CellCallbackEngine.execute_notebook( - copy.deepcopy(self.nb), 'python', output_path='foo.ipynb' - ) + nb = CellCallbackEngine.execute_notebook(copy.deepcopy(self.nb), 'python', output_path='foo.ipynb') self.assertEqual(nb, AnyMock(NotebookNode)) self.assertNotEqual(self.nb, nb) @@ -353,9 +339,7 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs): self.assertIsNotNone(cell.metadata.papermill['end_time']) self.assertEqual(cell.metadata.papermill['duration'], AnyMock(float)) self.assertFalse(cell.metadata.papermill['exception']) - self.assertEqual( - cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED - ) + self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED) def test_no_cell_callback_execute(self): class NoCellCallbackEngine(Engine): @@ -365,9 +349,7 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs): with patch.object(NotebookExecutionManager, 'save') as save_mock: with patch.object(NotebookExecutionManager, 'complete_pbar') as pbar_comp_mock: - nb = NoCellCallbackEngine.execute_notebook( - copy.deepcopy(self.nb), 'python', output_path='foo.ipynb' - ) + nb = NoCellCallbackEngine.execute_notebook(copy.deepcopy(self.nb), 'python', output_path='foo.ipynb') self.assertEqual(nb, AnyMock(NotebookNode)) self.assertNotEqual(self.nb, nb) @@ -385,9 +367,7 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs): self.assertIsNone(cell.metadata.papermill['end_time']) self.assertIsNone(cell.metadata.papermill['duration']) self.assertIsNone(cell.metadata.papermill['exception']) - self.assertEqual( - cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED - ) + self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED) class TestNBClientEngine(unittest.TestCase): @@ -449,9 +429,7 @@ def test_nb_convert_engine_execute(self): self.assertIsNotNone(cell.metadata.papermill['end_time']) self.assertEqual(cell.metadata.papermill['duration'], AnyMock(float)) self.assertFalse(cell.metadata.papermill['exception']) - self.assertEqual( - cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED - ) + self.assertEqual(cell.metadata.papermill['status'], NotebookExecutionManager.COMPLETED) def test_nb_convert_log_outputs(self): with patch.object(logger, 'info') as info_mock: @@ -508,19 +486,13 @@ def test_getting(self): retrieved_engine = self.papermill_engines.get_engine("mock_engine") self.assertIs(mock_engine, retrieved_engine) # test you can't retrieve a non-registered engine - self.assertRaises( - exceptions.PapermillException, self.papermill_engines.get_engine, "non-existent" - ) + self.assertRaises(exceptions.PapermillException, self.papermill_engines.get_engine, "non-existent") def test_registering_entry_points(self): fake_entrypoint = Mock(load=Mock()) fake_entrypoint.name = "fake-engine" - with patch( - "entrypoints.get_group_all", return_value=[fake_entrypoint] - ) as mock_get_group_all: + with patch("entrypoints.get_group_all", return_value=[fake_entrypoint]) as mock_get_group_all: self.papermill_engines.register_entry_points() mock_get_group_all.assert_called_once_with("papermill.engine") - self.assertEqual( - self.papermill_engines.get_engine("fake-engine"), fake_entrypoint.load.return_value - ) + self.assertEqual(self.papermill_engines.get_engine("fake-engine"), fake_entrypoint.load.return_value) diff --git a/papermill/tests/test_execute.py b/papermill/tests/test_execute.py index 930e8a2d..39a3d6c8 100644 --- a/papermill/tests/test_execute.py +++ b/papermill/tests/test_execute.py @@ -66,9 +66,7 @@ def test_default_start_timeout(self, preproc_mock): def test_cell_insertion(self): execute_notebook(self.notebook_path, self.nb_test_executed_fname, {'msg': 'Hello'}) test_nb = load_notebook_node(self.nb_test_executed_fname) - self.assertListEqual( - test_nb.cells[1].get('source').split('\n'), ['# Parameters', 'msg = "Hello"', ''] - ) + self.assertListEqual(test_nb.cells[1].get('source').split('\n'), ['# Parameters', 'msg = "Hello"', '']) self.assertEqual(test_nb.metadata.papermill.parameters, {'msg': 'Hello'}) def test_no_tags(self): @@ -76,23 +74,17 @@ def test_no_tags(self): nb_test_executed_fname = os.path.join(self.test_dir, f'output_{notebook_name}') execute_notebook(get_notebook_path(notebook_name), nb_test_executed_fname, {'msg': 'Hello'}) test_nb = load_notebook_node(nb_test_executed_fname) - self.assertListEqual( - test_nb.cells[0].get('source').split('\n'), ['# Parameters', 'msg = "Hello"', ''] - ) + self.assertListEqual(test_nb.cells[0].get('source').split('\n'), ['# Parameters', 'msg = "Hello"', '']) self.assertEqual(test_nb.metadata.papermill.parameters, {'msg': 'Hello'}) def test_quoted_params(self): execute_notebook(self.notebook_path, self.nb_test_executed_fname, {'msg': '"Hello"'}) test_nb = load_notebook_node(self.nb_test_executed_fname) - self.assertListEqual( - test_nb.cells[1].get('source').split('\n'), ['# Parameters', r'msg = "\"Hello\""', ''] - ) + self.assertListEqual(test_nb.cells[1].get('source').split('\n'), ['# Parameters', r'msg = "\"Hello\""', '']) self.assertEqual(test_nb.metadata.papermill.parameters, {'msg': '"Hello"'}) def test_backslash_params(self): - execute_notebook( - self.notebook_path, self.nb_test_executed_fname, {'foo': r'do\ not\ crash'} - ) + execute_notebook(self.notebook_path, self.nb_test_executed_fname, {'foo': r'do\ not\ crash'}) test_nb = load_notebook_node(self.nb_test_executed_fname) self.assertListEqual( test_nb.cells[1].get('source').split('\n'), @@ -155,9 +147,7 @@ def test(self): execute_notebook(path, result_path) nb = load_notebook_node(result_path) self.assertEqual(nb.cells[0].cell_type, "markdown") - self.assertRegex( - nb.cells[0].source, r'^$' - ) + self.assertRegex(nb.cells[0].source, r'^$') self.assertEqual(nb.cells[0].metadata["tags"], ["papermill-error-cell-tag"]) self.assertEqual(nb.cells[1].cell_type, "markdown") @@ -174,9 +164,7 @@ def test(self): self.assertEqual(nb.cells[7].execution_count, None) # double check the removal (the new cells above should be the only two tagged ones) - self.assertEqual( - sum("papermill-error-cell-tag" in cell.metadata.get("tags", []) for cell in nb.cells), 2 - ) + self.assertEqual(sum("papermill-error-cell-tag" in cell.metadata.get("tags", []) for cell in nb.cells), 2) class TestBrokenNotebook2(unittest.TestCase): @@ -193,9 +181,7 @@ def test(self): execute_notebook(path, result_path) nb = load_notebook_node(result_path) self.assertEqual(nb.cells[0].cell_type, "markdown") - self.assertRegex( - nb.cells[0].source, r'^.*In \[2\].*$' - ) + self.assertRegex(nb.cells[0].source, r'^.*In \[2\].*$') self.assertEqual(nb.cells[1].execution_count, 1) self.assertEqual(nb.cells[2].cell_type, "markdown") @@ -218,9 +204,7 @@ def tearDown(self): shutil.rmtree(self.test_dir) def test_report_mode(self): - nb = execute_notebook( - self.notebook_path, self.nb_test_executed_fname, {'a': 0}, report_mode=True - ) + nb = execute_notebook(self.notebook_path, self.nb_test_executed_fname, {'a': 0}, report_mode=True) for cell in nb.cells: if cell.cell_type == 'code': self.assertEqual(cell.metadata.get('jupyter', {}).get('source_hidden'), True) @@ -260,22 +244,14 @@ def tearDown(self): def test_local_save_ignores_cwd_assignment(self): with chdir(self.base_test_dir): # Both paths are relative - execute_notebook( - self.simple_notebook_name, self.nb_test_executed_fname, cwd=self.test_dir - ) - self.assertTrue( - os.path.isfile(os.path.join(self.base_test_dir, self.nb_test_executed_fname)) - ) + execute_notebook(self.simple_notebook_name, self.nb_test_executed_fname, cwd=self.test_dir) + self.assertTrue(os.path.isfile(os.path.join(self.base_test_dir, self.nb_test_executed_fname))) def test_execution_respects_cwd_assignment(self): with chdir(self.base_test_dir): # Both paths are relative - execute_notebook( - self.check_notebook_name, self.nb_test_executed_fname, cwd=self.test_dir - ) - self.assertTrue( - os.path.isfile(os.path.join(self.base_test_dir, self.nb_test_executed_fname)) - ) + execute_notebook(self.check_notebook_name, self.nb_test_executed_fname, cwd=self.test_dir) + self.assertTrue(os.path.isfile(os.path.join(self.base_test_dir, self.nb_test_executed_fname))) def test_pathlib_paths(self): # Copy of test_execution_respects_cwd_assignment but with `Path`s @@ -328,9 +304,7 @@ def test_sys_exit1(self): execute_notebook(get_notebook_path(notebook_name), result_path) nb = load_notebook_node(result_path) self.assertEqual(nb.cells[0].cell_type, "markdown") - self.assertRegex( - nb.cells[0].source, r'^$' - ) + self.assertRegex(nb.cells[0].source, r'^$') self.assertEqual(nb.cells[1].execution_count, 1) self.assertEqual(nb.cells[2].cell_type, "markdown") @@ -401,25 +375,19 @@ def nb_language(cls, nb, language=None): def setUp(self): self.test_dir = tempfile.mkdtemp() self.notebook_path = get_notebook_path('simple_execute.ipynb') - self.nb_test_executed_fname = os.path.join( - self.test_dir, 'output_{}'.format('simple_execute.ipynb') - ) + self.nb_test_executed_fname = os.path.join(self.test_dir, 'output_{}'.format('simple_execute.ipynb')) self._orig_papermill_engines = deepcopy(engines.papermill_engines) self._orig_translators = deepcopy(translators.papermill_translators) engines.papermill_engines.register("custom_engine", self.CustomEngine) - translators.papermill_translators.register( - "my_custom_language", translators.PythonTranslator() - ) + translators.papermill_translators.register("my_custom_language", translators.PythonTranslator()) def tearDown(self): shutil.rmtree(self.test_dir) engines.papermill_engines = self._orig_papermill_engines translators.papermill_translators = self._orig_translators - @patch.object( - CustomEngine, "execute_managed_notebook", wraps=CustomEngine.execute_managed_notebook - ) + @patch.object(CustomEngine, "execute_managed_notebook", wraps=CustomEngine.execute_managed_notebook) @patch("papermill.parameterize.translate_parameters", wraps=translators.translate_parameters) def test_custom_kernel_name_and_language(self, translate_parameters, execute_managed_notebook): """Tests execute against engine with custom implementations to fetch @@ -432,9 +400,7 @@ def test_custom_kernel_name_and_language(self, translate_parameters, execute_man parameters={"msg": "fake msg"}, ) self.assertEqual(execute_managed_notebook.call_args[0], (ANY, "my_custom_kernel")) - self.assertEqual( - translate_parameters.call_args[0], (ANY, 'my_custom_language', {"msg": "fake msg"}, ANY) - ) + self.assertEqual(translate_parameters.call_args[0], (ANY, 'my_custom_language', {"msg": "fake msg"}, ANY)) class TestNotebookNodeInput(unittest.TestCase): diff --git a/papermill/tests/test_gcs.py b/papermill/tests/test_gcs.py index 4b50d922..ebd635a0 100644 --- a/papermill/tests/test_gcs.py +++ b/papermill/tests/test_gcs.py @@ -92,9 +92,7 @@ def test_gcs_listdir(self, mock_gcs_filesystem): @patch( 'papermill.iorw.GCSFileSystem', - side_effect=mock_gcs_fs_wrapper( - GCSRateLimitException({"message": "test", "code": 429}), 10 - ), + side_effect=mock_gcs_fs_wrapper(GCSRateLimitException({"message": "test", "code": 429}), 10), ) def test_gcs_handle_exception(self, mock_gcs_filesystem): with patch.object(GCSHandler, 'RETRY_DELAY', 0): @@ -111,9 +109,7 @@ def test_gcs_retry(self, mock_gcs_filesystem): with patch.object(GCSHandler, 'RETRY_DELAY', 0): with patch.object(GCSHandler, 'RETRY_MULTIPLIER', 0): with patch.object(GCSHandler, 'RETRY_MAX_DELAY', 0): - self.assertEqual( - self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2 - ) + self.assertEqual(self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2) @patch( 'papermill.iorw.GCSFileSystem', @@ -123,24 +119,18 @@ def test_gcs_retry_older_exception(self, mock_gcs_filesystem): with patch.object(GCSHandler, 'RETRY_DELAY', 0): with patch.object(GCSHandler, 'RETRY_MULTIPLIER', 0): with patch.object(GCSHandler, 'RETRY_MAX_DELAY', 0): - self.assertEqual( - self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2 - ) + self.assertEqual(self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2) @patch('papermill.iorw.gs_is_retriable', side_effect=fallback_gs_is_retriable) @patch( 'papermill.iorw.GCSFileSystem', - side_effect=mock_gcs_fs_wrapper( - GCSRateLimitException({"message": "test", "code": None}), 1 - ), + side_effect=mock_gcs_fs_wrapper(GCSRateLimitException({"message": "test", "code": None}), 1), ) def test_gcs_fallback_retry_unknown_failure_code(self, mock_gcs_filesystem, mock_gcs_retriable): with patch.object(GCSHandler, 'RETRY_DELAY', 0): with patch.object(GCSHandler, 'RETRY_MULTIPLIER', 0): with patch.object(GCSHandler, 'RETRY_MAX_DELAY', 0): - self.assertEqual( - self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2 - ) + self.assertEqual(self.gcs_handler.write('raise_limit_exception', 'gs://bucket/test.ipynb'), 2) @patch('papermill.iorw.gs_is_retriable', return_value=False) @patch( diff --git a/papermill/tests/test_hdfs.py b/papermill/tests/test_hdfs.py index 23c96feb..36a5a361 100644 --- a/papermill/tests/test_hdfs.py +++ b/papermill/tests/test_hdfs.py @@ -48,17 +48,13 @@ def setUp(self): def test_hdfs_listdir(self, mock_hdfs_filesystem): client = self.hdfs_handler._get_client() - self.assertEqual( - self.hdfs_handler.listdir("hdfs:///Projects/"), ['test1.ipynb', 'test2.ipynb'] - ) + self.assertEqual(self.hdfs_handler.listdir("hdfs:///Projects/"), ['test1.ipynb', 'test2.ipynb']) # Check if client is the same after calling self.assertIs(client, self.hdfs_handler._get_client()) def test_hdfs_read(self, mock_hdfs_filesystem): client = self.hdfs_handler._get_client() - self.assertEqual( - self.hdfs_handler.read("hdfs:///Projects/test1.ipynb"), b'Content of notebook' - ) + self.assertEqual(self.hdfs_handler.read("hdfs:///Projects/test1.ipynb"), b'Content of notebook') self.assertIs(client, self.hdfs_handler._get_client()) def test_hdfs_write(self, mock_hdfs_filesystem): diff --git a/papermill/tests/test_iorw.py b/papermill/tests/test_iorw.py index b8e73e1e..f5d6ae66 100644 --- a/papermill/tests/test_iorw.py +++ b/papermill/tests/test_iorw.py @@ -103,9 +103,7 @@ def test_entrypoint_register(self): fake_entrypoint = Mock(load=Mock()) fake_entrypoint.name = "fake-from-entry-point://" - with patch( - "entrypoints.get_group_all", return_value=[fake_entrypoint] - ) as mock_get_group_all: + with patch("entrypoints.get_group_all", return_value=[fake_entrypoint]) as mock_get_group_all: self.papermill_io.register_entry_points() mock_get_group_all.assert_called_once_with("papermill.io") fake_ = self.papermill_io.get_handler("fake-from-entry-point://") @@ -125,14 +123,10 @@ def test_register_ordering(self): self.assertEqual(self.papermill_io.get_handler("fake2/path"), self.fake2) def test_read(self): - self.assertEqual( - self.papermill_io.read("fake/path"), "contents from fake/path for version 1" - ) + self.assertEqual(self.papermill_io.read("fake/path"), "contents from fake/path for version 1") def test_read_bytes(self): - self.assertIsNotNone( - self.papermill_io_bytes.read("notebooks/gcs/gcs_in/gcs-simple_notebook.ipynb") - ) + self.assertIsNotNone(self.papermill_io_bytes.read("notebooks/gcs/gcs_in/gcs-simple_notebook.ipynb")) def test_read_with_no_file_extension(self): with pytest.warns(UserWarning): diff --git a/papermill/tests/test_parameterize.py b/papermill/tests/test_parameterize.py index fcb05ffe..431caa12 100644 --- a/papermill/tests/test_parameterize.py +++ b/papermill/tests/test_parameterize.py @@ -9,9 +9,7 @@ class TestNotebookParametrizing(unittest.TestCase): def count_nb_injected_parameter_cells(self, nb): - return len( - [c for c in nb.cells if 'injected-parameters' in c.get('metadata', {}).get('tags', [])] - ) + return len([c for c in nb.cells if 'injected-parameters' in c.get('metadata', {}).get('tags', [])]) def test_no_tag_copying(self): # Test that injected cell does not copy other tags @@ -77,9 +75,7 @@ def test_repeated_run_no_parameters_tag(self): def test_custom_comment(self): test_nb = load_notebook_node(get_notebook_path("simple_execute.ipynb")) - test_nb = parameterize_notebook( - test_nb, {'msg': 'Hello'}, comment='This is a custom comment' - ) + test_nb = parameterize_notebook(test_nb, {'msg': 'Hello'}, comment='This is a custom comment') cell_one = test_nb.cells[1] first_line = cell_one['source'].split('\n')[0] @@ -132,9 +128,7 @@ def test_path_with_boolean_parameter(self): self.assertEqual(parameterize_path("foo/bar/{baz}", {"baz": False}), "foo/bar/False") def test_path_with_dict_parameter(self): - self.assertEqual( - parameterize_path("foo/{bar[baz]}/", {"bar": {"baz": "quux"}}), "foo/quux/" - ) + self.assertEqual(parameterize_path("foo/{bar[baz]}/", {"bar": {"baz": "quux"}}), "foo/quux/") def test_path_with_list_parameter(self): self.assertEqual(parameterize_path("foo/{bar[0]}/", {"bar": [1, 2, 3]}), "foo/1/") @@ -153,9 +147,7 @@ def test_path_with_float_format_string(self): self.assertEqual(parameterize_path("foo/bar/{baz:.03f}", {"baz": 0.3}), "foo/bar/0.300") def test_path_with_multiple_parameter(self): - self.assertEqual( - parameterize_path("{foo}/{baz}", {"foo": "bar", "baz": "quux"}), "bar/quux" - ) + self.assertEqual(parameterize_path("{foo}/{baz}", {"foo": "bar", "baz": "quux"}), "bar/quux") def test_parameterized_path_with_undefined_parameter(self): with self.assertRaises(PapermillMissingParameterException) as context: diff --git a/papermill/tests/test_s3.py b/papermill/tests/test_s3.py index c95cd4d2..d19e025b 100644 --- a/papermill/tests/test_s3.py +++ b/papermill/tests/test_s3.py @@ -168,9 +168,7 @@ def s3_client(): mock_s3.start() client = boto3.client('s3') - client.create_bucket( - Bucket=test_bucket_name, CreateBucketConfiguration={'LocationConstraint': 'us-west-2'} - ) + client.create_bucket(Bucket=test_bucket_name, CreateBucketConfiguration={'LocationConstraint': 'us-west-2'}) client.put_object(Bucket=test_bucket_name, Key=test_file_path, Body=test_nb_content) client.put_object(Bucket=test_bucket_name, Key=test_empty_file_path, Body='') yield S3() diff --git a/papermill/tests/test_translators.py b/papermill/tests/test_translators.py index a5d07669..232630ae 100644 --- a/papermill/tests/test_translators.py +++ b/papermill/tests/test_translators.py @@ -58,9 +58,7 @@ def test_translate_codify_python(parameters, expected): assert translators.PythonTranslator.codify(parameters) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")] -) +@pytest.mark.parametrize("test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")]) def test_translate_comment_python(test_input, expected): assert translators.PythonTranslator.comment(test_input) == expected @@ -82,11 +80,7 @@ def test_translate_comment_python(test_input, expected): ), ( "a: List[str] = ['this', 'is', 'a', 'string', 'list'] # Nice variable a", - [ - Parameter( - "a", "List[str]", "['this', 'is', 'a', 'string', 'list']", "Nice variable a" - ) - ], + [Parameter("a", "List[str]", "['this', 'is', 'a', 'string', 'list']", "Nice variable a")], ), ( "a: List[str] = [\n 'this', # First\n 'is',\n 'a',\n 'string',\n 'list' # Last\n] # Nice variable a", # noqa @@ -147,9 +141,7 @@ def test_translate_type_r(test_input, expected): assert translators.RTranslator.translate(test_input) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")] -) +@pytest.mark.parametrize("test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")]) def test_translate_comment_r(test_input, expected): assert translators.RTranslator.comment(test_input) == expected @@ -360,9 +352,7 @@ def test_translate_assign_powershell(input_name, input_value, expected): assert translators.PowershellTranslator.assign(input_name, input_value) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")] -) +@pytest.mark.parametrize("test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")]) def test_translate_comment_powershell(test_input, expected): assert translators.PowershellTranslator.comment(test_input) == expected @@ -472,9 +462,7 @@ def test_translate_codify_julia(parameters, expected): assert translators.JuliaTranslator.codify(parameters) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '#'), ("foo", '# foo'), ('["best effort"]', '# ["best effort"]')] -) +@pytest.mark.parametrize("test_input,expected", [("", '#'), ("foo", '# foo'), ('["best effort"]', '# ["best effort"]')]) def test_translate_comment_julia(test_input, expected): assert translators.JuliaTranslator.comment(test_input) == expected @@ -535,9 +523,7 @@ def test_translate_codify_matlab(parameters, expected): assert translators.MatlabTranslator.codify(parameters) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '%'), ("foo", '% foo'), ("['best effort']", "% ['best effort']")] -) +@pytest.mark.parametrize("test_input,expected", [("", '%'), ("foo", '% foo'), ("['best effort']", "% ['best effort']")]) def test_translate_comment_matlab(test_input, expected): assert translators.MatlabTranslator.comment(test_input) == expected @@ -564,9 +550,7 @@ def test_find_translator_with_exact_language(): def test_find_translator_with_no_such_kernel_or_language(): with pytest.raises(PapermillException): - translators.papermill_translators.find_translator( - "unregistered_kernel", "unregistered_language" - ) + translators.papermill_translators.find_translator("unregistered_kernel", "unregistered_language") def test_translate_uses_str_representation_of_unknown_types(): @@ -623,9 +607,7 @@ def test_translate_type_sh(test_input, expected): assert translators.BashTranslator.translate(test_input) == expected -@pytest.mark.parametrize( - "test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")] -) +@pytest.mark.parametrize("test_input,expected", [("", '#'), ("foo", '# foo'), ("['best effort']", "# ['best effort']")]) def test_translate_comment_sh(test_input, expected): assert translators.BashTranslator.comment(test_input) == expected diff --git a/papermill/translators.py b/papermill/translators.py index 490e2d5f..1002cf7b 100644 --- a/papermill/translators.py +++ b/papermill/translators.py @@ -28,9 +28,7 @@ def find_translator(self, kernel_name, language): elif language in self._translators: return self._translators[language] raise PapermillException( - "No parameter translator functions specified for kernel '{}' or language '{}'".format( - kernel_name, language - ) + f"No parameter translator functions specified for kernel '{kernel_name}' or language '{language}'" ) @@ -289,9 +287,7 @@ def translate_bool(cls, val): @classmethod def translate_dict(cls, val): - escaped = ', '.join( - [f'{cls.translate_str(k)} = {cls.translate(v)}' for k, v in val.items()] - ) + escaped = ', '.join([f'{cls.translate_str(k)} = {cls.translate(v)}' for k, v in val.items()]) return f'list({escaped})' @classmethod @@ -320,9 +316,7 @@ def translate_int(cls, val): @classmethod def translate_dict(cls, val): """Translate dicts to scala Maps""" - escaped = ', '.join( - [f"{cls.translate_str(k)} -> {cls.translate(v)}" for k, v in val.items()] - ) + escaped = ', '.join([f"{cls.translate_str(k)} -> {cls.translate(v)}" for k, v in val.items()]) return f'Map({escaped})' @classmethod @@ -347,9 +341,7 @@ def translate_none(cls, val): @classmethod def translate_dict(cls, val): - escaped = ', '.join( - [f"{cls.translate_str(k)} => {cls.translate(v)}" for k, v in val.items()] - ) + escaped = ', '.join([f"{cls.translate_str(k)} => {cls.translate(v)}" for k, v in val.items()]) return f'Dict({escaped})' @classmethod @@ -427,9 +419,7 @@ def translate_int(cls, val): def translate_dict(cls, val): """Translate dicts to nontyped dictionary""" - kvps = ', '.join( - [f"{{ {cls.translate_str(k)} , {cls.translate(v)} }}" for k, v in val.items()] - ) + kvps = ', '.join([f"{{ {cls.translate_str(k)} , {cls.translate(v)} }}" for k, v in val.items()]) return f'new Dictionary{{ {kvps} }}' @classmethod @@ -463,9 +453,7 @@ def translate_int(cls, val): @classmethod def translate_dict(cls, val): - tuples = '; '.join( - [f"({cls.translate_str(k)}, {cls.translate(v)} :> IComparable)" for k, v in val.items()] - ) + tuples = '; '.join([f"({cls.translate_str(k)}, {cls.translate(v)} :> IComparable)" for k, v in val.items()]) return f'[ {tuples} ] |> Map.ofList' @classmethod diff --git a/pyproject.toml b/pyproject.toml index a10411ab..4aa6e16c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,34 +6,9 @@ universal = true # Example configuration for Black. - -# NOTE: you have to use single-quoted strings in TOML for regular expressions. -# It's the equivalent of r-strings in Python. Multiline strings are treated as -# verbose regular expressions by Black. Use [ ] to denote a significant space -# character. - [tool.black] -line-length = 100 -target-version = ['py312'] -include = '\.pyi?$' -exclude = ''' -/( - \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - - # The following are specific to Black, you probably don't want those. - | blib2to3 - | tests/data - | profiling -)/ -''' +line-length = 120 +target-version = ['py311'] skip-string-normalization = true diff --git a/setup.py b/setup.py index d5e3f956..7a4eb315 100644 --- a/setup.py +++ b/setup.py @@ -48,9 +48,7 @@ def read_reqs(fname, folder=None): all_reqs = s3_reqs + azure_reqs + gcs_reqs + hdfs_reqs + github_reqs + black_reqs docs_reqs = all_reqs + docs_only_reqs # Temporarily remove hdfs_reqs from dev deps until the pyarrow package is available for Python 3.12 -dev_reqs = ( - read_reqs('dev.txt', folder='requirements') + s3_reqs + azure_reqs + gcs_reqs + black_reqs -) # all_reqs +dev_reqs = read_reqs('dev.txt', folder='requirements') + s3_reqs + azure_reqs + gcs_reqs + black_reqs # all_reqs extras_require = { "test": dev_reqs, "dev": dev_reqs,