Skip to content

Commit

Permalink
update Black with line 120 (#755)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Borda and pre-commit-ci[bot] authored Nov 21, 2023
1 parent b9b43bf commit 12b01cb
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 353 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ repos:
hooks:
- id: black
name: Black code
args: ["-S"]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------
Expand Down
24 changes: 6 additions & 18 deletions papermill/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions papermill/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions papermill/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions papermill/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = (
'<span ' + ERROR_STYLE + '>'
Expand Down
9 changes: 2 additions & 7 deletions papermill/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions papermill/iorw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
12 changes: 3 additions & 9 deletions papermill/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
32 changes: 8 additions & 24 deletions papermill/tests/test_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions papermill/tests/test_adl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions papermill/tests/test_autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 12b01cb

Please sign in to comment.