Skip to content

Commit 7b508e0

Browse files
author
Ben Elam
committed
Address linting errors from black
1 parent c8075d5 commit 7b508e0

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

orchestrator/api/api_v1/endpoints/processes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,24 @@ def get_auth_callbacks(pstat: ProcessStat) -> tuple[Authorizer | None, Authorize
104104
auth_retry = pstat.workflow.retry_auth_callback if pstat.workflow.retry_auth_callback is not None else auth_resume
105105
# Iterate over previous steps to look for policy changes
106106
remaining_steps = pstat.log
107-
past_steps = pstat.workflow.steps[:-len(remaining_steps)]
107+
past_steps = pstat.workflow.steps[: -len(remaining_steps)]
108108
# Review last steps and current step
109109
for step in past_steps + [pstat.log[0]]:
110110
if step.resume_auth_callback and step.retry_auth_callback is None:
111111
# Set both to authorize_callback
112112
auth_resume = step.resume_auth_callback
113113
auth_retry = step.resume_auth_callback
114114
continue
115-
elif step.resume_auth_callback and step.retry_auth_callback:
115+
if step.resume_auth_callback and step.retry_auth_callback:
116116
auth_resume = step.resume_auth_callback
117117
auth_retry = step.retry_auth_callback
118118
continue
119-
elif step.resume_auth_callback is None and step.retry_auth_callback:
119+
if step.resume_auth_callback is None and step.retry_auth_callback:
120120
# Only update retry
121121
auth_retry = step.retry_auth_callback
122122
continue
123-
else: # Both None
124-
continue
123+
# Both None
124+
continue
125125
return auth_resume, auth_retry
126126

127127

orchestrator/services/celery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import structlog
1919
from celery.result import AsyncResult
2020
from kombu.exceptions import ConnectionError, OperationalError
21-
from oauth2_lib.fastapi import OIDCUserModel
2221

22+
from oauth2_lib.fastapi import OIDCUserModel
2323
from orchestrator import app_settings
2424
from orchestrator.api.error_handling import raise_status
2525
from orchestrator.db import ProcessTable, db
@@ -47,7 +47,7 @@ def _celery_start_process(
4747
user_inputs: list[State] | None,
4848
user: str = SYSTEM_USER,
4949
user_model: OIDCUserModel | None = None,
50-
**kwargs: Any
50+
**kwargs: Any,
5151
) -> UUID:
5252
"""Client side call of Celery."""
5353
from orchestrator.services.tasks import NEW_TASK, NEW_WORKFLOW, get_celery_task

orchestrator/workflow.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
import secrets
2020
from collections.abc import Callable
2121
from dataclasses import asdict, dataclass
22-
from functools import update_wrapper
23-
from http import HTTPStatus
2422
from itertools import dropwhile
2523
from typing import (
2624
Any,
2725
Generic,
2826
NoReturn,
2927
Protocol,
30-
TypeAlias,
3128
TypeVar,
3229
cast,
3330
overload,
@@ -42,7 +39,6 @@
4239

4340
from nwastdlib import const, identity
4441
from oauth2_lib.fastapi import OIDCUserModel
45-
from orchestrator.api.error_handling import raise_status
4642
from orchestrator.config.assignee import Assignee
4743
from orchestrator.db import db, transactional
4844
from orchestrator.services.settings import get_engine_settings
@@ -181,7 +177,7 @@ def __repr__(self) -> str:
181177

182178

183179
def _handle_simple_input_form_generator(f: StateInputStepFunc) -> StateInputFormGenerator:
184-
"""Processes f into a form generator and injects a pre-hook for user authorization"""
180+
"""Processes f into a form generator and injects a pre-hook for user authorization."""
185181
if inspect.isgeneratorfunction(f):
186182
return cast(StateInputFormGenerator, f)
187183
if inspect.isgenerator(f):
@@ -219,7 +215,9 @@ def wrapping_function() -> NoReturn:
219215
wrapping_function.description = description
220216
wrapping_function.authorize_callback = allow if authorize_callback is None else authorize_callback
221217
# If no retry auth policy is given, defer to policy for process creation.
222-
wrapping_function.retry_auth_callback = wrapping_function.authorize_callback if retry_auth_callback is None else retry_auth_callback
218+
wrapping_function.retry_auth_callback = (
219+
wrapping_function.authorize_callback if retry_auth_callback is None else retry_auth_callback
220+
)
223221

224222
if initial_input_form is None:
225223
# We always need a form to prevent starting a workflow when no input is needed.
@@ -288,8 +286,15 @@ def wrapper(state: State) -> Process:
288286
return decorator
289287

290288

291-
def inputstep(name: str, assignee: Assignee, resume_auth_callback: Authorizer | None = None, retry_auth_callback: Authorizer | None = None) -> Callable[[InputStepFunc], Step]:
289+
def inputstep(
290+
name: str,
291+
assignee: Assignee,
292+
resume_auth_callback: Authorizer | None = None,
293+
retry_auth_callback: Authorizer | None = None
294+
) -> Callable[[InputStepFunc], Step]:
292295
"""Add user input step to workflow.
296+
297+
Any authorization callbacks will be attached to the resulting Step.
293298
294299
IMPORTANT: In contrast to other workflow steps, the `@inputstep` wrapped function will not run in the
295300
workflow engine! This means that it must be free of side effects!
@@ -317,7 +322,14 @@ def wrapper(state: State) -> FormGenerator:
317322
def suspend(state: State) -> Process:
318323
return Suspend(state)
319324

320-
return make_step_function(suspend, name, wrapper, assignee, resume_auth_callback=resume_auth_callback, retry_auth_callback=retry_auth_callback)
325+
return make_step_function(
326+
suspend,
327+
name,
328+
wrapper,
329+
assignee,
330+
resume_auth_callback=resume_auth_callback,
331+
retry_auth_callback=retry_auth_callback
332+
)
321333

322334
return decorator
323335

@@ -497,8 +509,8 @@ def workflow(
497509
description: str,
498510
initial_input_form: InputStepFunc | None = None,
499511
target: Target = Target.SYSTEM,
500-
authorize_callback: Authorizer| None = None,
501-
retry_auth_callback: Authorizer| None = None,
512+
authorize_callback: Authorizer | None = None,
513+
retry_auth_callback: Authorizer | None = None,
502514
) -> Callable[[Callable[[], StepList]], Workflow]:
503515
"""Transform an initial_input_form and a step list into a workflow.
504516
@@ -519,7 +531,13 @@ def create_service_port():
519531

520532
def _workflow(f: Callable[[], StepList]) -> Workflow:
521533
return make_workflow(
522-
f, description, initial_input_form_in_form_inject_args, target, f(), authorize_callback=authorize_callback, retry_auth_callback=retry_auth_callback
534+
f,
535+
description,
536+
initial_input_form_in_form_inject_args,
537+
target,
538+
f(),
539+
authorize_callback=authorize_callback,
540+
retry_auth_callback=retry_auth_callback,
523541
)
524542

525543
return _workflow

orchestrator/workflows/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pydantic import field_validator, model_validator
2121
from sqlalchemy import select
2222

23-
from oauth2_lib.fastapi import OIDCUserModel
2423
from orchestrator.db import ProductTable, SubscriptionTable, db
2524
from orchestrator.forms.validators import ProductId
2625
from orchestrator.services import subscriptions
@@ -242,7 +241,7 @@ def _create_workflow(f: Callable[[], StepList]) -> Workflow:
242241
Target.CREATE,
243242
steplist,
244243
authorize_callback=authorize_callback,
245-
retry_auth_callback=retry_auth_callback
244+
retry_auth_callback=retry_auth_callback,
246245
)
247246

248247
return _create_workflow

test/unit_tests/api/test_processes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from uuid import uuid4
77

88
import pytest
9-
from pydantic_forms.core import FormPage
109
from sqlalchemy import select
1110

1211
from oauth2_lib.fastapi import OIDCUserModel
@@ -24,6 +23,7 @@
2423
from orchestrator.settings import app_settings
2524
from orchestrator.targets import Target
2625
from orchestrator.workflow import ProcessStatus, done, init, inputstep, step, workflow
26+
from pydantic_forms.core import FormPage
2727
from test.unit_tests.helpers import URL_STR_TYPE
2828
from test.unit_tests.workflows import WorkflowInstanceForTests
2929

@@ -599,7 +599,7 @@ def unauthorized_workflow():
599599
def test_inputstep_authorization(test_client):
600600
def disallow(_: OIDCUserModel | None = None) -> bool:
601601
return False
602-
602+
603603
def allow(_: OIDCUserModel | None = None) -> bool:
604604
return True
605605

@@ -639,5 +639,5 @@ def test_auth_workflow():
639639
response = test_client.put(f"/api/processes/{process_id}/resume", json=[{"confirm": True}])
640640
assert HTTPStatus.FORBIDDEN == response.status_code
641641

642-
#TODO test how this interacts with passing a different callback to @authorize_workflow
643-
# These should be as functionally independent as possible.
642+
# TODO test how this interacts with passing a different callback to @authorize_workflow
643+
# These should be as functionally independent as possible.

0 commit comments

Comments
 (0)