From 48976b2947cab193368b892b3dedb508350cc8cf Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Sat, 20 Jul 2024 16:29:45 -0400 Subject: [PATCH] sdk: add env to FFmpegInput + fix python parameterized class generator (#1532) * sdk: add env to FFmpegInput + fix python parameterized class generator * downgrade node for gh actions --- .github/workflows/build-sdk.yml | 6 ++--- .../scrypted_python/scrypted_sdk/types.py | 3 ++- sdk/types/src/build.ts | 22 +++++++------------ sdk/types/src/types.input.ts | 4 ++++ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-sdk.yml b/.github/workflows/build-sdk.yml index 68e55fac5..90c0289d8 100644 --- a/.github/workflows/build-sdk.yml +++ b/.github/workflows/build-sdk.yml @@ -7,7 +7,7 @@ on: pull_request: paths: ["sdk/**"] workflow_dispatch: - + jobs: build: name: Build @@ -15,11 +15,11 @@ jobs: defaults: run: working-directory: ./sdk - + steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22 + node-version: 22.4.1 - run: npm ci - run: npm run build diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index fafd46499..bf599ff00 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -518,6 +518,7 @@ class FFmpegInput(TypedDict): container: str destinationVideoBitrate: float + env: Any # Environment variables to set when launching FFmpeg. h264EncoderArguments: list[str] h264FilterArguments: list[str] inputArguments: list[str] @@ -1465,7 +1466,7 @@ class StartStop: class StreamService: """Generic bidirectional stream connection.""" - async def connectStream(self, input: AsyncGenerator[Input, None] = None, options: Any = None) -> AsyncGenerator[Output, None]: + async def connectStream(self, input: AsyncGenerator[Any, None] = None, options: Any = None) -> AsyncGenerator[Any, None]: pass diff --git a/sdk/types/src/build.ts b/sdk/types/src/build.ts index 9fe03647f..f1b4fcf53 100644 --- a/sdk/types/src/build.ts +++ b/sdk/types/src/build.ts @@ -142,24 +142,11 @@ function toPythonMethodDeclaration(method: any) { } function selfSignature(method: any) { - for (const typeParameter of method.signatures[0].typeParameter || []) { - parameterTypes.add(typeParameter.name); - } const params = (method.signatures[0].parameters || []).map((p: any) => toPythonParameter(p)); - parameterTypes.clear(); params.unshift('self'); return params.join(', '); } -function selfReturnType(method: any) { - for (const typeParameter of method.signatures[0].typeParameter || []) { - parameterTypes.add(typeParameter.name); - } - const retType = toPythonReturnType(method.signatures[0].type); - parameterTypes.clear(); - return retType -} - const enums = schema.children?.filter((child: any) => child.kindString === 'Enumeration') ?? []; const interfaces = schema.children?.filter((child: any) => Object.values(ScryptedInterface).includes(child.name)) ?? []; let python = ''; @@ -223,6 +210,10 @@ function addNonDictionaryType(td: any) { class ${td.name}: ${toDocstring(td)} `; + // cache type parameters so underlying generators can map them to Any + for (const typeParameter of td.typeParameters || []) { + parameterTypes.add(typeParameter.name); + } const children = td.children || []; const properties = children.filter((child: any) => child.kindString === 'Property'); @@ -232,7 +223,7 @@ ${toDocstring(td)} ` } for (const method of methods) { - python += ` ${toPythonMethodDeclaration(method)} ${method.name}(${selfSignature(method)}) -> ${selfReturnType(method)}: + python += ` ${toPythonMethodDeclaration(method)} ${method.name}(${selfSignature(method)}) -> ${toPythonReturnType(method.signatures[0].type)}: ${toDocstring(method, true)} ` @@ -241,6 +232,9 @@ ${toDocstring(td)} python += ` pass ` + + // reset for the next type + parameterTypes.clear(); } for (const td of interfaces) { diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index 8b94cc070..caca537fc 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -1703,6 +1703,10 @@ export interface FFmpegInput extends MediaContainer { h264EncoderArguments?: string[]; videoDecoderArguments?: string[]; h264FilterArguments?: string[]; + /** + * Environment variables to set when launching FFmpeg. + */ + env?: { [key: string]: string }; } export interface DeviceInformation { model?: string;