203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 | @app.command()
async def deploy(
entrypoint: str = typer.Argument(
None,
help=(
"The path to a flow entrypoint within a project, in the form of"
" `./path/to/file.py:flow_func_name`"
),
),
names: List[str] = typer.Option(
None,
"--name",
"-n",
help=(
"The name to give the deployment. Can be a pattern. Examples:"
" 'my-deployment', 'my-flow/my-deployment', 'my-deployment-*',"
" '*-flow-name/deployment*'"
),
),
description: str = typer.Option(
None,
"--description",
"-d",
help=(
"The description to give the deployment. If not provided, the description"
" will be populated from the flow's description."
),
),
version: str = typer.Option(
None, "--version", help="A version to give the deployment."
),
tags: List[str] = typer.Option(
None,
"-t",
"--tag",
help=(
"One or more optional tags to apply to the deployment. Note: tags are used"
" only for organizational purposes. For delegating work to agents, use the"
" --work-queue flag."
),
),
work_pool_name: str = SettingsOption(
PREFECT_DEFAULT_WORK_POOL_NAME,
"-p",
"--pool",
help="The work pool that will handle this deployment's runs.",
),
work_queue_name: str = typer.Option(
None,
"-q",
"--work-queue",
help=(
"The work queue that will handle this deployment's runs. "
"It will be created if it doesn't already exist. Defaults to `None`."
),
),
variables: List[str] = typer.Option(
None,
"-v",
"--variable",
help=("DEPRECATED: Please use --jv/--job-variable for similar functionality "),
),
job_variables: List[str] = typer.Option(
None,
"-jv",
"--job-variable",
help=(
"One or more job variable overrides for the work pool provided in the"
" format of key=value string or a JSON object"
),
),
cron: List[str] = typer.Option(
None,
"--cron",
help="A cron string that will be used to set a CronSchedule on the deployment.",
),
interval: List[int] = typer.Option(
None,
"--interval",
help=(
"An integer specifying an interval (in seconds) that will be used to set an"
" IntervalSchedule on the deployment."
),
),
interval_anchor: Optional[str] = typer.Option(
None, "--anchor-date", help="The anchor date for all interval schedules"
),
rrule: List[str] = typer.Option(
None,
"--rrule",
help="An RRule that will be used to set an RRuleSchedule on the deployment.",
),
timezone: str = typer.Option(
None,
"--timezone",
help="Deployment schedule timezone string e.g. 'America/New_York'",
),
trigger: List[str] = typer.Option(
None,
"--trigger",
help=(
"Specifies a trigger for the deployment. The value can be a"
" json string or path to `.yaml`/`.json` file. This flag can be used"
" multiple times."
),
),
param: List[str] = typer.Option(
None,
"--param",
help=(
"An optional parameter override, values are parsed as JSON strings e.g."
" --param question=ultimate --param answer=42"
),
),
params: str = typer.Option(
None,
"--params",
help=(
"An optional parameter override in a JSON string format e.g."
' --params=\'{"question": "ultimate", "answer": 42}\''
),
),
enforce_parameter_schema: bool = typer.Option(
False,
"--enforce-parameter-schema",
help=(
"Whether to enforce the parameter schema on this deployment. If set to"
" True, any parameters passed to this deployment must match the signature"
" of the flow."
),
),
deploy_all: bool = typer.Option(
False,
"--all",
help=(
"Deploy all flows in the project. If a flow name or entrypoint is also"
" provided, this flag will be ignored."
),
),
prefect_file: Path = typer.Option(
Path("prefect.yaml"),
"--prefect-file",
help="Specify a custom path to a prefect.yaml file",
),
):
"""
Deploy a flow from this project by creating a deployment.
Should be run from a project root directory.
"""
if variables is not None:
app.console.print(
generate_deprecation_message(
name="The `--variable` flag",
start_date="Mar 2024",
help=(
"Please use the `--job-variable foo=bar` argument instead: `prefect"
" deploy --job-variable`."
),
),
style="yellow",
)
if variables is None:
variables = list()
if job_variables is None:
job_variables = list()
job_variables.extend(variables)
options = {
"entrypoint": entrypoint,
"description": description,
"version": version,
"tags": tags,
"work_pool_name": work_pool_name,
"work_queue_name": work_queue_name,
"variables": job_variables,
"cron": cron,
"interval": interval,
"anchor_date": interval_anchor,
"rrule": rrule,
"timezone": timezone,
"triggers": trigger,
"param": param,
"params": params,
"enforce_parameter_schema": enforce_parameter_schema,
}
try:
deploy_configs, actions = _load_deploy_configs_and_actions(
prefect_file=prefect_file,
)
parsed_names = []
for name in names or []:
if "*" in name:
parsed_names.extend(_parse_name_from_pattern(deploy_configs, name))
else:
parsed_names.append(name)
deploy_configs = _pick_deploy_configs(
deploy_configs,
parsed_names,
deploy_all,
)
if len(deploy_configs) > 1:
if any(options.values()):
app.console.print(
(
"You have passed options to the deploy command, but you are"
" creating or updating multiple deployments. These options"
" will be ignored."
),
style="yellow",
)
await _run_multi_deploy(
deploy_configs=deploy_configs,
actions=actions,
deploy_all=deploy_all,
prefect_file=prefect_file,
)
else:
# Accommodate passing in -n flow-name/deployment-name as well as -n deployment-name
options["names"] = [
name.split("/", 1)[-1] if "/" in name else name for name in parsed_names
]
await _run_single_deploy(
deploy_config=deploy_configs[0] if deploy_configs else {},
actions=actions,
options=options,
prefect_file=prefect_file,
)
except ValueError as exc:
exit_with_error(str(exc))
|