@@ -36,112 +36,147 @@ def print_papermill_version(ctx, param, value):
36
36
ctx .exit ()
37
37
38
38
39
- @click .command (context_settings = dict (help_option_names = ['-h' , ' --help' ]))
39
+ @click .command (context_settings = dict (help_option_names = ["-h" , " --help" ]))
40
40
@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 = "" )
43
43
@click .option (
44
- ' --help-notebook' ,
44
+ " --help-notebook" ,
45
45
is_flag = True ,
46
46
default = False ,
47
- help = ' Display parameters information for the given notebook path.' ,
47
+ help = " Display parameters information for the given notebook path." ,
48
48
)
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.' )
54
49
@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" ,
56
83
is_flag = True ,
57
84
default = False ,
58
85
help = "Insert the path of the input notebook as PAPERMILL_INPUT_PATH as a notebook parameter." ,
59
86
)
60
87
@click .option (
61
- ' --inject-output-path' ,
88
+ " --inject-output-path" ,
62
89
is_flag = True ,
63
90
default = False ,
64
91
help = "Insert the path of the output notebook as PAPERMILL_OUTPUT_PATH as a notebook parameter." ,
65
92
)
66
93
@click .option (
67
- ' --inject-paths' ,
94
+ " --inject-paths" ,
68
95
is_flag = True ,
69
96
default = False ,
70
97
help = (
71
98
"Insert the paths of input/output notebooks as PAPERMILL_INPUT_PATH/PAPERMILL_OUTPUT_PATH"
72
99
" as notebook parameters."
73
100
),
74
101
)
75
- @click .option ('--engine' , help = 'The execution engine name to use in evaluating the notebook.' )
76
102
@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" ,
78
107
default = True ,
79
- help = ' Request save notebook after each cell execution' ,
108
+ help = " Request save notebook after each cell execution" ,
80
109
)
81
110
@click .option (
82
- ' --autosave-cell-every' ,
111
+ " --autosave-cell-every" ,
83
112
default = 30 ,
84
113
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)" ,
86
115
)
87
116
@click .option (
88
- ' --prepare-only/--prepare-execute' ,
117
+ " --prepare-only/--prepare-execute" ,
89
118
default = False ,
90
119
help = "Flag for outputting the notebook without execution, but with parameters applied." ,
91
120
)
92
121
@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." ,
96
130
)
131
+ @click .option ("--cwd" , default = None , help = "Working directory to run notebook in." )
97
132
@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." ,
101
136
)
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." )
104
137
@click .option (
105
- ' --log-output/--no-log-output' ,
138
+ " --log-output/--no-log-output" ,
106
139
default = False ,
107
140
help = "Flag for writing notebook output to the configured logger." ,
108
141
)
109
142
@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" ),
112
145
help = "File to write notebook stdout output to." ,
113
146
)
114
147
@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" ),
117
150
help = "File to write notebook stderr output to." ,
118
151
)
119
152
@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" ,
124
157
)
125
158
@click .option (
126
- ' --start-timeout' ,
127
- ' --start_timeout' , # Backwards compatible naming
159
+ " --start-timeout" ,
160
+ " --start_timeout" , # Backwards compatible naming
128
161
type = int ,
129
162
default = 60 ,
130
163
help = "Time in seconds to wait for kernel to start." ,
131
164
)
132
165
@click .option (
133
- ' --execution-timeout' ,
166
+ " --execution-timeout" ,
134
167
type = int ,
135
168
help = "Time in seconds to wait for each cell before failing execution (default: forever)" ,
136
169
)
137
- @click .option ('--report-mode/--no-report-mode' , default = False , help = "Flag for hiding input." )
138
170
@click .option (
139
- '--version' ,
171
+ "--report-mode/--no-report-mode" , default = False , help = "Flag for hiding input."
172
+ )
173
+ @click .option (
174
+ "--version" ,
140
175
is_flag = True ,
141
176
callback = print_papermill_version ,
142
177
expose_value = False ,
143
178
is_eager = True ,
144
- help = ' Flag for displaying the version.' ,
179
+ help = " Flag for displaying the version." ,
145
180
)
146
181
def papermill (
147
182
click_ctx ,
@@ -189,28 +224,28 @@ def papermill(
189
224
190
225
"""
191
226
# 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"
194
229
195
230
if not help_notebook :
196
231
required_output_path = not (INPUT_PIPED or OUTPUT_PIPED )
197
232
if required_output_path and not output_path :
198
233
raise click .UsageError ("Missing argument 'OUTPUT_PATH'" )
199
234
200
235
if INPUT_PIPED and notebook_path and not output_path :
201
- input_path = '-'
236
+ input_path = "-"
202
237
output_path = notebook_path
203
238
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 "-"
206
241
207
- if output_path == '-' :
242
+ if output_path == "-" :
208
243
# Save notebook to stdout just once
209
244
request_save_on_cell_execute = False
210
245
211
246
# 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"
214
249
215
250
elif progress_bar is None :
216
251
progress_bar = not log_output
@@ -220,11 +255,13 @@ def papermill(
220
255
# Read in Parameters
221
256
parameters_final = {}
222
257
if inject_input_path or inject_paths :
223
- parameters_final [' PAPERMILL_INPUT_PATH' ] = input_path
258
+ parameters_final [" PAPERMILL_INPUT_PATH" ] = input_path
224
259
if inject_output_path or inject_paths :
225
- parameters_final [' PAPERMILL_OUTPUT_PATH' ] = output_path
260
+ parameters_final [" PAPERMILL_OUTPUT_PATH" ] = output_path
226
261
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
+ )
228
265
for files in parameters_file or []:
229
266
parameters_final .update (read_yaml_file (files ) or {})
230
267
for params in parameters_yaml or []:
0 commit comments