Skip to content

Commit 7284dc6

Browse files
committed
black files
1 parent cc52363 commit 7284dc6

20 files changed

+105
-319
lines changed

papermill/cli.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,11 @@ def print_papermill_version(ctx, param, value):
4646
default=False,
4747
help='Display parameters information for the given notebook path.',
4848
)
49-
@click.option(
50-
'--parameters', '-p', nargs=2, multiple=True, help='Parameters to pass to the parameters cell.'
51-
)
52-
@click.option(
53-
'--parameters_raw', '-r', nargs=2, multiple=True, help='Parameters to be read as raw string.'
54-
)
55-
@click.option(
56-
'--parameters_file', '-f', multiple=True, help='Path to YAML file containing parameters.'
57-
)
58-
@click.option(
59-
'--parameters_yaml', '-y', multiple=True, help='YAML string to be used as parameters.'
60-
)
61-
@click.option(
62-
'--parameters_base64', '-b', multiple=True, help='Base64 encoded YAML string as parameters.'
63-
)
49+
@click.option('--parameters', '-p', nargs=2, multiple=True, help='Parameters to pass to the parameters cell.')
50+
@click.option('--parameters_raw', '-r', nargs=2, multiple=True, help='Parameters to be read as raw string.')
51+
@click.option('--parameters_file', '-f', multiple=True, help='Path to YAML file containing parameters.')
52+
@click.option('--parameters_yaml', '-y', multiple=True, help='YAML string to be used as parameters.')
53+
@click.option('--parameters_base64', '-b', multiple=True, help='Base64 encoded YAML string as parameters.')
6454
@click.option(
6555
'--inject-input-path',
6656
is_flag=True,
@@ -110,9 +100,7 @@ def print_papermill_version(ctx, param, value):
110100
help='Language for notebook execution. Ignores language in the notebook document metadata.',
111101
)
112102
@click.option('--cwd', default=None, help='Working directory to run notebook in.')
113-
@click.option(
114-
'--progress-bar/--no-progress-bar', default=None, help="Flag for turning on the progress bar."
115-
)
103+
@click.option('--progress-bar/--no-progress-bar', default=None, help="Flag for turning on the progress bar.")
116104
@click.option(
117105
'--log-output/--no-log-output',
118106
default=False,

papermill/engines.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ class NotebookExecutionManager:
9595
COMPLETED = "completed"
9696
FAILED = "failed"
9797

98-
def __init__(
99-
self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30
100-
):
98+
def __init__(self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30):
10199
self.nb = nb
102100
self.output_path = output_path
103101
self.log_output = log_output
@@ -278,9 +276,7 @@ def notebook_complete(self, **kwargs):
278276
self.end_time = self.now()
279277
self.nb.metadata.papermill['end_time'] = self.end_time.isoformat()
280278
if self.nb.metadata.papermill.get('start_time'):
281-
self.nb.metadata.papermill['duration'] = (
282-
self.end_time - self.start_time
283-
).total_seconds()
279+
self.nb.metadata.papermill['duration'] = (self.end_time - self.start_time).total_seconds()
284280

285281
# Cleanup cell statuses in case callbacks were never called
286282
for cell in self.nb.cells:

papermill/exceptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def missing_dependency_generator(package, dep):
6060
def missing_dep():
6161
raise PapermillOptionalDependencyException(
6262
"The {package} optional dependency is missing. "
63-
"Please run pip install papermill[{dep}] to install this dependency".format(
64-
package=package, dep=dep
65-
)
63+
"Please run pip install papermill[{dep}] to install this dependency".format(package=package, dep=dep)
6664
)
6765

6866
return missing_dep

papermill/execute.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def execute_notebook(
109109

110110
if not prepare_only:
111111
# Dropdown to the engine to fetch the kernel name from the notebook document
112-
kernel_name = papermill_engines.nb_kernel_name(
113-
engine_name=engine_name, nb=nb, name=kernel_name
114-
)
112+
kernel_name = papermill_engines.nb_kernel_name(engine_name=engine_name, nb=nb, name=kernel_name)
115113
# Execute the Notebook in `cwd` if it is set
116114
with chdir(cwd):
117115
nb = papermill_engines.execute_notebook_with_engine(
@@ -167,9 +165,7 @@ def prepare_notebook_metadata(nb, input_path, output_path, report_mode=False):
167165

168166
ERROR_MARKER_TAG = "papermill-error-cell-tag"
169167

170-
ERROR_STYLE = (
171-
'style="color:red; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; font-size:2em;"'
172-
)
168+
ERROR_STYLE = 'style="color:red; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; font-size:2em;"'
173169

174170
ERROR_MESSAGE_TEMPLATE = (
175171
'<span ' + ERROR_STYLE + '>'

papermill/inspection.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def _infer_parameters(nb, name=None, language=None):
4545
try:
4646
params = translator.inspect(parameter_cell)
4747
except NotImplementedError:
48-
logger.warning(
49-
"Translator for '{}' language does not support parameter introspection.".format(
50-
language
51-
)
52-
)
48+
logger.warning("Translator for '{}' language does not support parameter introspection.".format(language))
5349

5450
return params
5551

@@ -92,8 +88,7 @@ def display_notebook_help(ctx, notebook_path, parameters):
9288
click.echo(param_help)
9389
else:
9490
click.echo(
95-
"\n Can't infer anything about this notebook's parameters. "
96-
"It may not have any parameter defined."
91+
"\n Can't infer anything about this notebook's parameters. " "It may not have any parameter defined."
9792
)
9893

9994
return 0

papermill/iorw.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,8 @@ def get_handler(self, path, extensions=None):
147147

148148
if extensions:
149149
if not fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*.*'):
150-
warnings.warn(
151-
"the file is not specified with any extension : " + os.path.basename(path)
152-
)
153-
elif not any(
154-
fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*' + ext)
155-
for ext in extensions
156-
):
150+
warnings.warn("the file is not specified with any extension : " + os.path.basename(path))
151+
elif not any(fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*' + ext) for ext in extensions):
157152
warnings.warn(f"The specified file ({path}) does not end in one of {extensions}")
158153

159154
local_handler = None
@@ -320,9 +315,7 @@ def write(self, buf, path):
320315
@retry(
321316
retry=retry_if_exception_type(PapermillRateLimitException),
322317
stop=stop_after_attempt(self.RATE_LIMIT_RETRIES),
323-
wait=wait_exponential(
324-
multiplier=self.RETRY_MULTIPLIER, min=self.RETRY_DELAY, max=self.RETRY_MAX_DELAY
325-
),
318+
wait=wait_exponential(multiplier=self.RETRY_MULTIPLIER, min=self.RETRY_DELAY, max=self.RETRY_MAX_DELAY),
326319
reraise=True,
327320
)
328321
def retry_write():

papermill/s3.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def __init__(self, name, service=None):
3434

3535
def list(self, prefix='', delimiter=None):
3636
"""Limits a list of Bucket's objects based on prefix and delimiter."""
37-
return self.service._list(
38-
bucket=self.name, prefix=prefix, delimiter=delimiter, objects=True
39-
)
37+
return self.service._list(bucket=self.name, prefix=prefix, delimiter=delimiter, objects=True)
4038

4139

4240
class Prefix:
@@ -212,9 +210,7 @@ def sort(item):
212210
return item['Prefix']
213211

214212
for page in page_iterator:
215-
locations = sorted(
216-
[i for i in page.get('Contents', []) + page.get('CommonPrefixes', [])], key=sort
217-
)
213+
locations = sorted([i for i in page.get('Contents', []) + page.get('CommonPrefixes', [])], key=sort)
218214

219215
for item in locations:
220216
if objects or keys:
@@ -246,9 +242,7 @@ def _put(self, source, dest, num_callbacks=10, policy='bucket-owner-full-control
246242
obj.upload_file(source, ExtraArgs={'ACL': policy})
247243
return key
248244

249-
def _put_string(
250-
self, source, dest, num_callbacks=10, policy='bucket-owner-full-control', **kwargs
251-
):
245+
def _put_string(self, source, dest, num_callbacks=10, policy='bucket-owner-full-control', **kwargs):
252246
key = self._get_key(dest)
253247
obj = self.s3.Object(key.bucket.name, key.name)
254248

papermill/tests/test_abs.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,17 @@ def setUp(self):
4141
def test_split_url_raises_exception_on_invalid_url(self):
4242
with self.assertRaises(Exception) as context:
4343
AzureBlobStore._split_url("this_is_not_a_valid_url")
44-
self.assertTrue(
45-
"Invalid azure blob url 'this_is_not_a_valid_url'" in str(context.exception)
46-
)
44+
self.assertTrue("Invalid azure blob url 'this_is_not_a_valid_url'" in str(context.exception))
4745

4846
def test_split_url_splits_valid_url(self):
49-
params = AzureBlobStore._split_url(
50-
"abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"
51-
)
47+
params = AzureBlobStore._split_url("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken")
5248
self.assertEqual(params["account"], "myaccount")
5349
self.assertEqual(params["container"], "sascontainer")
5450
self.assertEqual(params["blob"], "sasblob.txt")
5551
self.assertEqual(params["sas_token"], "sastoken")
5652

5753
def test_split_url_splits_valid_url_no_sas(self):
58-
params = AzureBlobStore._split_url(
59-
"abs://myaccount.blob.core.windows.net/container/blob.txt"
60-
)
54+
params = AzureBlobStore._split_url("abs://myaccount.blob.core.windows.net/container/blob.txt")
6155
self.assertEqual(params["account"], "myaccount")
6256
self.assertEqual(params["container"], "container")
6357
self.assertEqual(params["blob"], "blob.txt")
@@ -74,9 +68,7 @@ def test_split_url_splits_valid_url_with_prefix(self):
7468

7569
def test_listdir_calls(self):
7670
self.assertEqual(
77-
self.abs.listdir(
78-
"abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"
79-
),
71+
self.abs.listdir("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"),
8072
["foo", "bar", "baz"],
8173
)
8274
self._blob_service_client.get_container_client.assert_called_once_with("sascontainer")
@@ -85,23 +77,15 @@ def test_listdir_calls(self):
8577
@patch("papermill.abs.io.BytesIO", side_effect=MockBytesIO)
8678
def test_reads_file(self, mockBytesIO):
8779
self.assertEqual(
88-
self.abs.read(
89-
"abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"
90-
),
80+
self.abs.read("abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"),
9181
["hello", "world!"],
9282
)
93-
self._blob_service_client.get_blob_client.assert_called_once_with(
94-
"sascontainer", "sasblob.txt"
95-
)
83+
self._blob_service_client.get_blob_client.assert_called_once_with("sascontainer", "sasblob.txt")
9684
self.download_blob.assert_called_once_with()
9785

9886
def test_write_file(self):
99-
self.abs.write(
100-
"hello world", "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken"
101-
)
102-
self._blob_service_client.get_blob_client.assert_called_once_with(
103-
"sascontainer", "sasblob.txt"
104-
)
87+
self.abs.write("hello world", "abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken")
88+
self._blob_service_client.get_blob_client.assert_called_once_with("sascontainer", "sasblob.txt")
10589
self.upload_blob.assert_called_once_with(data="hello world", overwrite=True)
10690

10791
def test_blob_service_client(self):

papermill/tests/test_adl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ class ADLTest(unittest.TestCase):
1111
"""
1212

1313
def setUp(self):
14-
self.ls = Mock(
15-
return_value=["path/to/directory/foo", "path/to/directory/bar", "path/to/directory/baz"]
16-
)
14+
self.ls = Mock(return_value=["path/to/directory/foo", "path/to/directory/bar", "path/to/directory/baz"])
1715
self.fakeFile = MagicMock()
1816
self.fakeFile.__iter__.return_value = [b"a", b"b", b"c"]
1917
self.fakeFile.__enter__.return_value = self.fakeFile
@@ -44,9 +42,7 @@ def test_listdir_calls_ls_on_adl_adapter(self):
4442
self.ls.assert_called_once_with("path/to/directory")
4543

4644
def test_read_opens_and_reads_file(self):
47-
self.assertEqual(
48-
self.adl.read("adl://foo_store.azuredatalakestore.net/path/to/file"), ["a", "b", "c"]
49-
)
45+
self.assertEqual(self.adl.read("adl://foo_store.azuredatalakestore.net/path/to/file"), ["a", "b", "c"])
5046
self.fakeFile.__iter__.assert_called_once_with()
5147

5248
def test_write_opens_file_and_writes_to_it(self):

papermill/tests/test_autosave.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def setUp(self):
1919
self.nb = nbformat.read(self.notebook_path, as_version=4)
2020

2121
def test_autosave_not_too_fast(self):
22-
nb_man = NotebookExecutionManager(
23-
self.nb, output_path='test.ipynb', autosave_cell_every=0.5
24-
)
22+
nb_man = NotebookExecutionManager(self.nb, output_path='test.ipynb', autosave_cell_every=0.5)
2523
with patch.object(engines, 'write_ipynb') as write_mock:
2624
write_mock.reset_mock()
2725
assert write_mock.call_count == 0 # check that the mock is sane

0 commit comments

Comments
 (0)