Skip to content

Commit 09572be

Browse files
committed
align black and ruff
1 parent 7284dc6 commit 09572be

35 files changed

+1848
-1167
lines changed

Diff for: papermill/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from papermill.cli import papermill
22

3-
if __name__ == '__main__':
3+
if __name__ == "__main__":
44
papermill()

Diff for: papermill/abs.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def _split_url(self, url):
3232
see: https://docs.microsoft.com/en-us/azure/storage/common/storage-dotnet-shared-access-signature-part-1 # noqa: E501
3333
abs://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sastoken
3434
"""
35-
match = re.match(r"abs://(.*)\.blob\.core\.windows\.net\/(.*?)\/([^\?]*)\??(.*)$", url)
35+
match = re.match(
36+
r"abs://(.*)\.blob\.core\.windows\.net\/(.*?)\/([^\?]*)\??(.*)$", url
37+
)
3638
if not match:
3739
raise Exception(f"Invalid azure blob url '{url}'")
3840
else:
@@ -48,22 +50,32 @@ def read(self, url):
4850
"""Read storage at a given url"""
4951
params = self._split_url(url)
5052
output_stream = io.BytesIO()
51-
blob_service_client = self._blob_service_client(params["account"], params["sas_token"])
52-
blob_client = blob_service_client.get_blob_client(params['container'], params['blob'])
53+
blob_service_client = self._blob_service_client(
54+
params["account"], params["sas_token"]
55+
)
56+
blob_client = blob_service_client.get_blob_client(
57+
params["container"], params["blob"]
58+
)
5359
blob_client.download_blob().readinto(output_stream)
5460
output_stream.seek(0)
5561
return [line.decode("utf-8") for line in output_stream]
5662

5763
def listdir(self, url):
5864
"""Returns a list of the files under the specified path"""
5965
params = self._split_url(url)
60-
blob_service_client = self._blob_service_client(params["account"], params["sas_token"])
66+
blob_service_client = self._blob_service_client(
67+
params["account"], params["sas_token"]
68+
)
6169
container_client = blob_service_client.get_container_client(params["container"])
6270
return list(container_client.list_blobs(params["blob"]))
6371

6472
def write(self, buf, url):
6573
"""Write buffer to storage at a given url"""
6674
params = self._split_url(url)
67-
blob_service_client = self._blob_service_client(params["account"], params["sas_token"])
68-
blob_client = blob_service_client.get_blob_client(params['container'], params['blob'])
75+
blob_service_client = self._blob_service_client(
76+
params["account"], params["sas_token"]
77+
)
78+
blob_client = blob_service_client.get_blob_client(
79+
params["container"], params["blob"]
80+
)
6981
blob_client.upload_blob(data=buf, overwrite=True)

Diff for: papermill/adl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121

2222
@classmethod
2323
def _split_url(cls, url):
24-
match = re.match(r'adl://(.*)\.azuredatalakestore\.net\/(.*)$', url)
24+
match = re.match(r"adl://(.*)\.azuredatalakestore\.net\/(.*)$", url)
2525
if not match:
2626
raise Exception(f"Invalid ADL url '{url}'")
2727
else:
@@ -60,5 +60,5 @@ def write(self, buf, url):
6060
"""Write buffer to storage at a given url"""
6161
(store_name, path) = self._split_url(url)
6262
adapter = self._create_adapter(store_name)
63-
with adapter.open(path, 'wb') as f:
63+
with adapter.open(path, "wb") as f:
6464
f.write(buf.encode())

Diff for: papermill/cli.py

+90-53
Original file line numberDiff line numberDiff line change
@@ -36,112 +36,147 @@ def print_papermill_version(ctx, param, value):
3636
ctx.exit()
3737

3838

39-
@click.command(context_settings=dict(help_option_names=['-h', '--help']))
39+
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
4040
@click.pass_context
41-
@click.argument('notebook_path', required=not INPUT_PIPED)
42-
@click.argument('output_path', default="")
41+
@click.argument("notebook_path", required=not INPUT_PIPED)
42+
@click.argument("output_path", default="")
4343
@click.option(
44-
'--help-notebook',
44+
"--help-notebook",
4545
is_flag=True,
4646
default=False,
47-
help='Display parameters information for the given notebook path.',
47+
help="Display parameters information for the given notebook path.",
4848
)
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.')
5449
@click.option(
55-
'--inject-input-path',
50+
"--parameters",
51+
"-p",
52+
nargs=2,
53+
multiple=True,
54+
help="Parameters to pass to the parameters cell.",
55+
)
56+
@click.option(
57+
"--parameters_raw",
58+
"-r",
59+
nargs=2,
60+
multiple=True,
61+
help="Parameters to be read as raw string.",
62+
)
63+
@click.option(
64+
"--parameters_file",
65+
"-f",
66+
multiple=True,
67+
help="Path to YAML file containing parameters.",
68+
)
69+
@click.option(
70+
"--parameters_yaml",
71+
"-y",
72+
multiple=True,
73+
help="YAML string to be used as parameters.",
74+
)
75+
@click.option(
76+
"--parameters_base64",
77+
"-b",
78+
multiple=True,
79+
help="Base64 encoded YAML string as parameters.",
80+
)
81+
@click.option(
82+
"--inject-input-path",
5683
is_flag=True,
5784
default=False,
5885
help="Insert the path of the input notebook as PAPERMILL_INPUT_PATH as a notebook parameter.",
5986
)
6087
@click.option(
61-
'--inject-output-path',
88+
"--inject-output-path",
6289
is_flag=True,
6390
default=False,
6491
help="Insert the path of the output notebook as PAPERMILL_OUTPUT_PATH as a notebook parameter.",
6592
)
6693
@click.option(
67-
'--inject-paths',
94+
"--inject-paths",
6895
is_flag=True,
6996
default=False,
7097
help=(
7198
"Insert the paths of input/output notebooks as PAPERMILL_INPUT_PATH/PAPERMILL_OUTPUT_PATH"
7299
" as notebook parameters."
73100
),
74101
)
75-
@click.option('--engine', help='The execution engine name to use in evaluating the notebook.')
76102
@click.option(
77-
'--request-save-on-cell-execute/--no-request-save-on-cell-execute',
103+
"--engine", help="The execution engine name to use in evaluating the notebook."
104+
)
105+
@click.option(
106+
"--request-save-on-cell-execute/--no-request-save-on-cell-execute",
78107
default=True,
79-
help='Request save notebook after each cell execution',
108+
help="Request save notebook after each cell execution",
80109
)
81110
@click.option(
82-
'--autosave-cell-every',
111+
"--autosave-cell-every",
83112
default=30,
84113
type=int,
85-
help='How often in seconds to autosave the notebook during long cell executions (0 to disable)',
114+
help="How often in seconds to autosave the notebook during long cell executions (0 to disable)",
86115
)
87116
@click.option(
88-
'--prepare-only/--prepare-execute',
117+
"--prepare-only/--prepare-execute",
89118
default=False,
90119
help="Flag for outputting the notebook without execution, but with parameters applied.",
91120
)
92121
@click.option(
93-
'--kernel',
94-
'-k',
95-
help='Name of kernel to run. Ignores kernel name in the notebook document metadata.',
122+
"--kernel",
123+
"-k",
124+
help="Name of kernel to run. Ignores kernel name in the notebook document metadata.",
125+
)
126+
@click.option(
127+
"--language",
128+
"-l",
129+
help="Language for notebook execution. Ignores language in the notebook document metadata.",
96130
)
131+
@click.option("--cwd", default=None, help="Working directory to run notebook in.")
97132
@click.option(
98-
'--language',
99-
'-l',
100-
help='Language for notebook execution. Ignores language in the notebook document metadata.',
133+
"--progress-bar/--no-progress-bar",
134+
default=None,
135+
help="Flag for turning on the progress bar.",
101136
)
102-
@click.option('--cwd', default=None, help='Working directory to run notebook in.')
103-
@click.option('--progress-bar/--no-progress-bar', default=None, help="Flag for turning on the progress bar.")
104137
@click.option(
105-
'--log-output/--no-log-output',
138+
"--log-output/--no-log-output",
106139
default=False,
107140
help="Flag for writing notebook output to the configured logger.",
108141
)
109142
@click.option(
110-
'--stdout-file',
111-
type=click.File(mode='w', encoding='utf-8'),
143+
"--stdout-file",
144+
type=click.File(mode="w", encoding="utf-8"),
112145
help="File to write notebook stdout output to.",
113146
)
114147
@click.option(
115-
'--stderr-file',
116-
type=click.File(mode='w', encoding='utf-8'),
148+
"--stderr-file",
149+
type=click.File(mode="w", encoding="utf-8"),
117150
help="File to write notebook stderr output to.",
118151
)
119152
@click.option(
120-
'--log-level',
121-
type=click.Choice(['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']),
122-
default='INFO',
123-
help='Set log level',
153+
"--log-level",
154+
type=click.Choice(["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
155+
default="INFO",
156+
help="Set log level",
124157
)
125158
@click.option(
126-
'--start-timeout',
127-
'--start_timeout', # Backwards compatible naming
159+
"--start-timeout",
160+
"--start_timeout", # Backwards compatible naming
128161
type=int,
129162
default=60,
130163
help="Time in seconds to wait for kernel to start.",
131164
)
132165
@click.option(
133-
'--execution-timeout',
166+
"--execution-timeout",
134167
type=int,
135168
help="Time in seconds to wait for each cell before failing execution (default: forever)",
136169
)
137-
@click.option('--report-mode/--no-report-mode', default=False, help="Flag for hiding input.")
138170
@click.option(
139-
'--version',
171+
"--report-mode/--no-report-mode", default=False, help="Flag for hiding input."
172+
)
173+
@click.option(
174+
"--version",
140175
is_flag=True,
141176
callback=print_papermill_version,
142177
expose_value=False,
143178
is_eager=True,
144-
help='Flag for displaying the version.',
179+
help="Flag for displaying the version.",
145180
)
146181
def papermill(
147182
click_ctx,
@@ -189,28 +224,28 @@ def papermill(
189224
190225
"""
191226
# Jupyter deps use frozen modules, so we disable the python 3.11+ warning about debugger if running the CLI
192-
if 'PYDEVD_DISABLE_FILE_VALIDATION' not in os.environ:
193-
os.environ['PYDEVD_DISABLE_FILE_VALIDATION'] = '1'
227+
if "PYDEVD_DISABLE_FILE_VALIDATION" not in os.environ:
228+
os.environ["PYDEVD_DISABLE_FILE_VALIDATION"] = "1"
194229

195230
if not help_notebook:
196231
required_output_path = not (INPUT_PIPED or OUTPUT_PIPED)
197232
if required_output_path and not output_path:
198233
raise click.UsageError("Missing argument 'OUTPUT_PATH'")
199234

200235
if INPUT_PIPED and notebook_path and not output_path:
201-
input_path = '-'
236+
input_path = "-"
202237
output_path = notebook_path
203238
else:
204-
input_path = notebook_path or '-'
205-
output_path = output_path or '-'
239+
input_path = notebook_path or "-"
240+
output_path = output_path or "-"
206241

207-
if output_path == '-':
242+
if output_path == "-":
208243
# Save notebook to stdout just once
209244
request_save_on_cell_execute = False
210245

211246
# Reduce default log level if we pipe to stdout
212-
if log_level == 'INFO':
213-
log_level = 'ERROR'
247+
if log_level == "INFO":
248+
log_level = "ERROR"
214249

215250
elif progress_bar is None:
216251
progress_bar = not log_output
@@ -220,11 +255,13 @@ def papermill(
220255
# Read in Parameters
221256
parameters_final = {}
222257
if inject_input_path or inject_paths:
223-
parameters_final['PAPERMILL_INPUT_PATH'] = input_path
258+
parameters_final["PAPERMILL_INPUT_PATH"] = input_path
224259
if inject_output_path or inject_paths:
225-
parameters_final['PAPERMILL_OUTPUT_PATH'] = output_path
260+
parameters_final["PAPERMILL_OUTPUT_PATH"] = output_path
226261
for params in parameters_base64 or []:
227-
parameters_final.update(yaml.load(base64.b64decode(params), Loader=NoDatesSafeLoader) or {})
262+
parameters_final.update(
263+
yaml.load(base64.b64decode(params), Loader=NoDatesSafeLoader) or {}
264+
)
228265
for files in parameters_file or []:
229266
parameters_final.update(read_yaml_file(files) or {})
230267
for params in parameters_yaml or []:

Diff for: papermill/clientwrap.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def __init__(self, nb_man, km=None, raise_on_iopub_timeout=True, **kw):
2727
Optional kernel manager. If none is provided, a kernel manager will
2828
be created.
2929
"""
30-
super().__init__(nb_man.nb, km=km, raise_on_iopub_timeout=raise_on_iopub_timeout, **kw)
30+
super().__init__(
31+
nb_man.nb, km=km, raise_on_iopub_timeout=raise_on_iopub_timeout, **kw
32+
)
3133
self.nb_man = nb_man
3234

3335
def execute(self, **kwargs):
@@ -37,14 +39,18 @@ def execute(self, **kwargs):
3739
self.reset_execution_trackers()
3840

3941
# See https://bugs.python.org/issue37373 :(
40-
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
42+
if (
43+
sys.version_info[0] == 3
44+
and sys.version_info[1] >= 8
45+
and sys.platform.startswith("win")
46+
):
4147
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
4248

4349
with self.setup_kernel(**kwargs):
4450
self.log.info("Executing notebook with kernel: %s" % self.kernel_name)
4551
self.papermill_execute_cells()
4652
info_msg = self.wait_for_reply(self.kc.kernel_info())
47-
self.nb.metadata['language_info'] = info_msg['content']['language_info']
53+
self.nb.metadata["language_info"] = info_msg["content"]["language_info"]
4854
self.set_widgets_metadata()
4955

5056
return self.nb
@@ -71,7 +77,9 @@ def papermill_execute_cells(self):
7177
self.nb_man.cell_start(cell, index)
7278
self.execute_cell(cell, index)
7379
except CellExecutionError as ex:
74-
self.nb_man.cell_exception(self.nb.cells[index], cell_index=index, exception=ex)
80+
self.nb_man.cell_exception(
81+
self.nb.cells[index], cell_index=index, exception=ex
82+
)
7583
break
7684
finally:
7785
self.nb_man.cell_complete(self.nb.cells[index], cell_index=index)
@@ -100,7 +108,7 @@ def log_output_message(self, output):
100108
self.stderr_file.write(content)
101109
self.stderr_file.flush()
102110
elif self.log_output and ("data" in output and "text/plain" in output.data):
103-
self.log.info("".join(output.data['text/plain']))
111+
self.log.info("".join(output.data["text/plain"]))
104112

105113
def process_message(self, *arg, **kwargs):
106114
output = super().process_message(*arg, **kwargs)

0 commit comments

Comments
 (0)