본문으로 건너뛰기

Plain Python helper

Decorator 없는 일반 Python 함수는 @px.function 또는 @px.component 구현에서 반복되는 계산을 나누는 helper입니다. Function이 부르는 helper는 @px.function(..., helpers=[...])로 선언합니다. 선언한 helper의 소스는 그 Function revision에 함께 저장되어 실행 시 존재하고, 선언하지 않은 module-level 함수는 실행 시 존재하지 않습니다. Component 구현 module 안의 helper는 module이 통째로 실행되므로 선언 없이 사용합니다.

무엇을 만드나요?

일반 Python 값과 타입을 받는 내부 구현 함수를 만듭니다. helper는 SDK definition이나 Node target을 등록하지 않습니다.

Studio에서는 어디에 보이나요?

별도 항목으로 보이지 않습니다. Canvas에는 helper를 호출하는 @px.function 또는 @px.component target을 flow.node(...)로 배치한 Node만 보입니다.

문법

python
def function_name(
    value: ValueType,
) -> ReturnType:
    ...

최소 예제

python
from pipelinexlab import px


def rectangular_area(width: float, depth: float) -> float:
    return width * depth


class AreaResults(px.Results):
    area: float


@px.function(
    key="calculate_area",
    version="1.0.0",
    description="Calculates the area of a rectangular section.",
    helpers=[rectangular_area],
)
def calculate_area(width: float, depth: float) -> AreaResults:
    return AreaResults(area=rectangular_area(width, depth))

매개변수

위치설명
helper parameter annotation내부에서 전달할 Python 값 타입
helper bodytarget 구현을 나눈 일반 Python 계산
helper 반환 annotationtarget body가 받을 Python 반환 타입

반환값과 handle

helper는 호출한 Function 또는 Component body에 Python 값을 반환합니다. Node handle과 port는 decorated target을 flow.node(...)로 배치할 때 만들어집니다.

규칙과 진단

  • helper에는 px.input(...), px.result(...), px.setting(...) 같은 public 계약 marker를 사용하지 않습니다.
  • helper를 flow.node(...)에 직접 전달하지 않습니다.
  • Function이 부르는 helper는 helpers=[...]에 선언합니다. 선언은 helper의 소스를 그 Function revision에 저장하고, helper가 바뀌면 새 revision(새 versionRef)이 됩니다.
  • helper 자체는 decorator 없이 둡니다. 등록된 target을 helper로 선언하면 이름 있는 거부를 받습니다.
  • Canvas에서 실행할 계산은 @px.function, 설치 Component companion은 @px.component로 정의합니다. 후속 V2 Canvas UI는 host-owned component.declarative@2만 사용하고 settings를 component-declared-settings@1로 선언당 최대 8개까지 받고 host control registry가 그립니다. rich surface는 RFC-016의 component-rich-surface-declaration@1이 소유합니다.
  • helper 이름, 호출 순서와 내부 반환값은 public Flow key나 port identity가 아닙니다.

다음