Skip to content

Commit 89fc91b

Browse files
authored
refactor: Add native Python runner runtime env var (#19109)
1 parent 63a3502 commit 89fc91b

File tree

6 files changed

+42
-40
lines changed

6 files changed

+42
-40
lines changed

packages/@n8n/api-types/src/frontend-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface FrontendSettings {
6060
versionCli: string;
6161
nodeJsVersion: string;
6262
concurrency: number;
63+
isNativePythonRunnerEnabled: boolean;
6364
authCookie: {
6465
secure: boolean;
6566
};

packages/cli/src/services/frontend.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export class FrontendService {
131131
nodeJsVersion: process.version.replace(/^v/, ''),
132132
versionCli: N8N_VERSION,
133133
concurrency: this.globalConfig.executions.concurrency.productionLimit,
134+
isNativePythonRunnerEnabled:
135+
this.globalConfig.taskRunners.enabled && process.env.N8N_NATIVE_PYTHON_RUNNER === 'true',
134136
authCookie: {
135137
secure: this.globalConfig.auth.cookie.secure,
136138
},

packages/frontend/editor-ui/src/__tests__/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const defaultSettings: FrontendSettings = {
102102
versionCli: '',
103103
nodeJsVersion: '',
104104
concurrency: -1,
105+
isNativePythonRunnerEnabled: false,
105106
versionNotifications: {
106107
enabled: true,
107108
endpoint: '',

packages/frontend/editor-ui/src/components/ParameterInput.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ const parameterOptions = computed(() => {
241241
const options = hasRemoteMethod.value ? remoteParameterOptions.value : props.parameter.options;
242242
const safeOptions = (options ?? []).filter(isValidParameterOption);
243243
244+
// temporary filter until native Python runner is GA
245+
if (props.parameter.name === 'language' && !settingsStore.isNativePythonRunnerEnabled) {
246+
return safeOptions.filter((o) => o.value !== 'pythonNative');
247+
}
248+
244249
return safeOptions;
245250
});
246251

packages/frontend/editor-ui/src/stores/settings.store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
7070

7171
const concurrency = computed(() => settings.value.concurrency);
7272

73+
const isNativePythonRunnerEnabled = computed(() => settings.value.isNativePythonRunnerEnabled);
74+
7375
const isConcurrencyEnabled = computed(() => concurrency.value !== -1);
7476

7577
const isPublicApiEnabled = computed(() => api.value.enabled);
@@ -329,6 +331,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
329331
security,
330332
nodeJsVersion,
331333
concurrency,
334+
isNativePythonRunnerEnabled,
332335
isConcurrencyEnabled,
333336
isPublicApiEnabled,
334337
isSwaggerUIEnabled,

packages/nodes-base/nodes/Code/Code.node.ts

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { NodesConfig, TaskRunnersConfig } from '@n8n/config';
33
import { Container } from '@n8n/di';
44
import set from 'lodash/set';
55
import {
6-
type INodeProperties,
76
NodeConnectionTypes,
87
UserError,
98
type CodeExecutionMode,
@@ -26,7 +25,7 @@ import { PythonTaskRunnerSandbox } from './PythonTaskRunnerSandbox';
2625
import { getSandboxContext } from './Sandbox';
2726
import { addPostExecutionWarning, standardizeOutput } from './utils';
2827

29-
const { CODE_ENABLE_STDOUT, N8N_NATIVE_PYTHON_RUNNER } = process.env;
28+
const { CODE_ENABLE_STDOUT } = process.env;
3029

3130
class PythonDisabledError extends UserError {
3231
constructor() {
@@ -36,43 +35,6 @@ class PythonDisabledError extends UserError {
3635
}
3736
}
3837

39-
const getV2LanguageProperty = (): INodeProperties => {
40-
const options = [
41-
{
42-
name: 'JavaScript',
43-
value: 'javaScript',
44-
action: 'Code in JavaScript',
45-
},
46-
{
47-
name: 'Python (Beta)',
48-
value: 'python',
49-
action: 'Code in Python (Beta)',
50-
},
51-
];
52-
53-
if (N8N_NATIVE_PYTHON_RUNNER === 'true') {
54-
options.push({
55-
name: 'Python (Native) (Beta)',
56-
value: 'pythonNative',
57-
action: 'Code in Python (Native) (Beta)',
58-
});
59-
}
60-
61-
return {
62-
displayName: 'Language',
63-
name: 'language',
64-
type: 'options',
65-
noDataExpression: true,
66-
displayOptions: {
67-
show: {
68-
'@version': [2],
69-
},
70-
},
71-
options,
72-
default: 'javaScript',
73-
};
74-
};
75-
7638
export class Code implements INodeType {
7739
description: INodeTypeDescription = {
7840
displayName: 'Code',
@@ -108,7 +70,35 @@ export class Code implements INodeType {
10870
],
10971
default: 'runOnceForAllItems',
11072
},
111-
getV2LanguageProperty(),
73+
{
74+
displayName: 'Language',
75+
name: 'language',
76+
type: 'options',
77+
noDataExpression: true,
78+
displayOptions: {
79+
show: {
80+
'@version': [2],
81+
},
82+
},
83+
options: [
84+
{
85+
name: 'JavaScript',
86+
value: 'javaScript',
87+
action: 'Code in JavaScript',
88+
},
89+
{
90+
name: 'Python (Beta)',
91+
value: 'python',
92+
action: 'Code in Python (Beta)',
93+
},
94+
{
95+
name: 'Python (Native) (Beta)',
96+
value: 'pythonNative',
97+
action: 'Code in Python (Native) (Beta)',
98+
},
99+
],
100+
default: 'javaScript',
101+
},
112102
{
113103
displayName: 'Language',
114104
name: 'language',

0 commit comments

Comments
 (0)