motia 0.2.1-beta.49 → 0.2.1-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,14 +10,20 @@ const executeCommand_1 = require("./utils/executeCommand");
10
10
  const activatePythonEnv_1 = require("./utils/activatePythonEnv");
11
11
  const installLambdaPythonPackages_1 = require("./utils/installLambdaPythonPackages");
12
12
  const generate_locked_data_1 = require("./generate-locked-data");
13
+ const pythonVersionUtils_1 = require("./utils/pythonVersionUtils");
13
14
  const pythonInstall = async ({ baseDir, isVerbose = false, pythonVersion = '3.13' }) => {
14
15
  const venvPath = path_1.default.join(baseDir, 'python_modules');
15
16
  console.log('📦 Installing Python dependencies...', venvPath);
16
17
  try {
18
+ // Get the appropriate Python command
19
+ const pythonCmd = await (0, pythonVersionUtils_1.getPythonCommand)(pythonVersion, baseDir);
20
+ if (isVerbose) {
21
+ console.log(`🐍 Using Python command: ${pythonCmd}`);
22
+ }
17
23
  // Check if virtual environment exists
18
24
  if (!fs_1.default.existsSync(venvPath)) {
19
25
  console.log('📦 Creating Python virtual environment...');
20
- await (0, executeCommand_1.executeCommand)(`python${pythonVersion} -m venv python_modules`, baseDir);
26
+ await (0, executeCommand_1.executeCommand)(`${pythonCmd} -m venv python_modules`, baseDir);
21
27
  }
22
28
  (0, activatePythonEnv_1.activatePythonVenv)({ baseDir, isVerbose, pythonVersion });
23
29
  (0, installLambdaPythonPackages_1.installLambdaPythonPackages)({ baseDir, isVerbose });
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.activatePythonVenv = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const pythonVersionUtils_1 = require("./pythonVersionUtils");
9
10
  const activatePythonVenv = ({ baseDir, isVerbose = false, pythonVersion = '3.13' }) => {
10
11
  // Set the virtual environment path
11
12
  const venvPath = path_1.default.join(baseDir, 'python_modules');
12
13
  const venvBinPath = path_1.default.join(venvPath, process.platform === 'win32' ? 'Scripts' : 'bin');
13
- const sitePackagesPath = path_1.default.join(venvPath, 'lib', `python${pythonVersion}`, 'site-packages');
14
+ const libPath = path_1.default.join(venvPath, 'lib');
15
+ // Find the Python version directory using the utility function
16
+ const actualPythonVersionPath = (0, pythonVersionUtils_1.findPythonSitePackagesDir)(libPath, pythonVersion, isVerbose);
17
+ const sitePackagesPath = path_1.default.join(venvPath, 'lib', actualPythonVersionPath, 'site-packages');
14
18
  // Verify that the virtual environment exists
15
19
  if (fs_1.default.existsSync(venvPath)) {
16
20
  // Add virtual environment to PATH
@@ -1 +1,5 @@
1
- export declare const executeCommand: (command: string, rootDir: string) => Promise<unknown>;
1
+ interface ExecuteCommandOptions {
2
+ silent?: boolean;
3
+ }
4
+ export declare const executeCommand: (command: string, rootDir: string, options?: ExecuteCommandOptions) => Promise<string>;
5
+ export {};
@@ -2,19 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeCommand = void 0;
4
4
  const child_process_1 = require("child_process");
5
- const executeCommand = async (command, rootDir) => {
5
+ const executeCommand = async (command, rootDir, options) => {
6
+ const { silent = false } = options || {};
6
7
  return new Promise((resolve, reject) => {
7
8
  (0, child_process_1.exec)(command, { cwd: rootDir }, (error, stdout, stderr) => {
8
9
  if (error) {
9
- console.error(`exec error: ${error}`);
10
+ if (!silent) {
11
+ console.error(`exec error: ${error}`);
12
+ }
10
13
  reject(error);
11
14
  return;
12
15
  }
13
- if (stdout)
14
- console.log(stdout.toString());
15
- if (stderr)
16
- console.error(stderr.toString());
17
- resolve(stdout);
16
+ if (!silent) {
17
+ if (stdout)
18
+ console.log(stdout.toString());
19
+ if (stderr)
20
+ console.error(stderr.toString());
21
+ }
22
+ resolve(stdout.toString());
18
23
  });
19
24
  });
20
25
  };
@@ -0,0 +1,3 @@
1
+ export declare function checkPythonVersionExists(pythonCmd: string, baseDir: string): Promise<boolean>;
2
+ export declare function getPythonCommand(requestedVersion: string, baseDir: string): Promise<string>;
3
+ export declare function findPythonSitePackagesDir(venvLibPath: string, pythonVersion: string, isVerbose?: boolean): string;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.checkPythonVersionExists = checkPythonVersionExists;
7
+ exports.getPythonCommand = getPythonCommand;
8
+ exports.findPythonSitePackagesDir = findPythonSitePackagesDir;
9
+ const executeCommand_1 = require("./executeCommand");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ async function checkPythonVersionExists(pythonCmd, baseDir) {
13
+ try {
14
+ await (0, executeCommand_1.executeCommand)(`${pythonCmd} --version`, baseDir, { silent: true });
15
+ return true;
16
+ }
17
+ catch (error) {
18
+ return false;
19
+ }
20
+ }
21
+ async function getPythonCommand(requestedVersion, baseDir) {
22
+ // Check if python{version} exists (e.g., python3.13)
23
+ const specificPythonCmd = `python${requestedVersion}`;
24
+ if (await checkPythonVersionExists(specificPythonCmd, baseDir)) {
25
+ return specificPythonCmd;
26
+ }
27
+ // Check if python exists and is version 3+
28
+ try {
29
+ const result = await (0, executeCommand_1.executeCommand)('python --version', baseDir, { silent: true });
30
+ const versionMatch = result.match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
31
+ if (versionMatch && parseInt(versionMatch[1], 10) >= 3) {
32
+ return 'python';
33
+ }
34
+ }
35
+ catch (error) {
36
+ // If error, python command doesn't exist or can't be executed
37
+ }
38
+ throw new Error('No compatible Python 3 installation found. Please install Python 3.');
39
+ }
40
+ function findPythonSitePackagesDir(venvLibPath, pythonVersion, isVerbose = false) {
41
+ let pythonVersionPath = `python${pythonVersion}`;
42
+ if (!venvLibPath || !pythonVersion) {
43
+ return pythonVersionPath;
44
+ }
45
+ try {
46
+ // Check if the exact version exists
47
+ if (venvLibPath && !fs_1.default.existsSync(path_1.default.join(venvLibPath, pythonVersionPath))) {
48
+ // Try to find any python3.x directory
49
+ const libContents = fs_1.default.readdirSync(venvLibPath);
50
+ const pythonDirs = libContents.filter(item => item.startsWith('python3'));
51
+ if (pythonDirs.length > 0) {
52
+ // Use the first python3.x directory found
53
+ pythonVersionPath = pythonDirs[0];
54
+ if (isVerbose) {
55
+ console.log(`Found Python directory: ${pythonVersionPath}`);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ catch (error) {
61
+ if (isVerbose) {
62
+ console.warn(`Warning: Could not determine Python version directory: ${error}`);
63
+ }
64
+ }
65
+ return pythonVersionPath;
66
+ }
@@ -4,14 +4,20 @@ import { executeCommand } from './utils/executeCommand';
4
4
  import { activatePythonVenv } from './utils/activatePythonEnv';
5
5
  import { installLambdaPythonPackages } from './utils/installLambdaPythonPackages';
6
6
  import { getStepFiles } from './generate-locked-data';
7
+ import { getPythonCommand } from './utils/pythonVersionUtils';
7
8
  const pythonInstall = async ({ baseDir, isVerbose = false, pythonVersion = '3.13' }) => {
8
9
  const venvPath = path.join(baseDir, 'python_modules');
9
10
  console.log('📦 Installing Python dependencies...', venvPath);
10
11
  try {
12
+ // Get the appropriate Python command
13
+ const pythonCmd = await getPythonCommand(pythonVersion, baseDir);
14
+ if (isVerbose) {
15
+ console.log(`🐍 Using Python command: ${pythonCmd}`);
16
+ }
11
17
  // Check if virtual environment exists
12
18
  if (!fs.existsSync(venvPath)) {
13
19
  console.log('📦 Creating Python virtual environment...');
14
- await executeCommand(`python${pythonVersion} -m venv python_modules`, baseDir);
20
+ await executeCommand(`${pythonCmd} -m venv python_modules`, baseDir);
15
21
  }
16
22
  activatePythonVenv({ baseDir, isVerbose, pythonVersion });
17
23
  installLambdaPythonPackages({ baseDir, isVerbose });
@@ -1,10 +1,14 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
+ import { findPythonSitePackagesDir } from './pythonVersionUtils';
3
4
  export const activatePythonVenv = ({ baseDir, isVerbose = false, pythonVersion = '3.13' }) => {
4
5
  // Set the virtual environment path
5
6
  const venvPath = path.join(baseDir, 'python_modules');
6
7
  const venvBinPath = path.join(venvPath, process.platform === 'win32' ? 'Scripts' : 'bin');
7
- const sitePackagesPath = path.join(venvPath, 'lib', `python${pythonVersion}`, 'site-packages');
8
+ const libPath = path.join(venvPath, 'lib');
9
+ // Find the Python version directory using the utility function
10
+ const actualPythonVersionPath = findPythonSitePackagesDir(libPath, pythonVersion, isVerbose);
11
+ const sitePackagesPath = path.join(venvPath, 'lib', actualPythonVersionPath, 'site-packages');
8
12
  // Verify that the virtual environment exists
9
13
  if (fs.existsSync(venvPath)) {
10
14
  // Add virtual environment to PATH
@@ -1 +1,5 @@
1
- export declare const executeCommand: (command: string, rootDir: string) => Promise<unknown>;
1
+ interface ExecuteCommandOptions {
2
+ silent?: boolean;
3
+ }
4
+ export declare const executeCommand: (command: string, rootDir: string, options?: ExecuteCommandOptions) => Promise<string>;
5
+ export {};
@@ -1,17 +1,22 @@
1
1
  import { exec } from 'child_process';
2
- export const executeCommand = async (command, rootDir) => {
2
+ export const executeCommand = async (command, rootDir, options) => {
3
+ const { silent = false } = options || {};
3
4
  return new Promise((resolve, reject) => {
4
5
  exec(command, { cwd: rootDir }, (error, stdout, stderr) => {
5
6
  if (error) {
6
- console.error(`exec error: ${error}`);
7
+ if (!silent) {
8
+ console.error(`exec error: ${error}`);
9
+ }
7
10
  reject(error);
8
11
  return;
9
12
  }
10
- if (stdout)
11
- console.log(stdout.toString());
12
- if (stderr)
13
- console.error(stderr.toString());
14
- resolve(stdout);
13
+ if (!silent) {
14
+ if (stdout)
15
+ console.log(stdout.toString());
16
+ if (stderr)
17
+ console.error(stderr.toString());
18
+ }
19
+ resolve(stdout.toString());
15
20
  });
16
21
  });
17
22
  };
@@ -0,0 +1,3 @@
1
+ export declare function checkPythonVersionExists(pythonCmd: string, baseDir: string): Promise<boolean>;
2
+ export declare function getPythonCommand(requestedVersion: string, baseDir: string): Promise<string>;
3
+ export declare function findPythonSitePackagesDir(venvLibPath: string, pythonVersion: string, isVerbose?: boolean): string;
@@ -0,0 +1,58 @@
1
+ import { executeCommand } from './executeCommand';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ export async function checkPythonVersionExists(pythonCmd, baseDir) {
5
+ try {
6
+ await executeCommand(`${pythonCmd} --version`, baseDir, { silent: true });
7
+ return true;
8
+ }
9
+ catch (error) {
10
+ return false;
11
+ }
12
+ }
13
+ export async function getPythonCommand(requestedVersion, baseDir) {
14
+ // Check if python{version} exists (e.g., python3.13)
15
+ const specificPythonCmd = `python${requestedVersion}`;
16
+ if (await checkPythonVersionExists(specificPythonCmd, baseDir)) {
17
+ return specificPythonCmd;
18
+ }
19
+ // Check if python exists and is version 3+
20
+ try {
21
+ const result = await executeCommand('python --version', baseDir, { silent: true });
22
+ const versionMatch = result.match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
23
+ if (versionMatch && parseInt(versionMatch[1], 10) >= 3) {
24
+ return 'python';
25
+ }
26
+ }
27
+ catch (error) {
28
+ // If error, python command doesn't exist or can't be executed
29
+ }
30
+ throw new Error('No compatible Python 3 installation found. Please install Python 3.');
31
+ }
32
+ export function findPythonSitePackagesDir(venvLibPath, pythonVersion, isVerbose = false) {
33
+ let pythonVersionPath = `python${pythonVersion}`;
34
+ if (!venvLibPath || !pythonVersion) {
35
+ return pythonVersionPath;
36
+ }
37
+ try {
38
+ // Check if the exact version exists
39
+ if (venvLibPath && !fs.existsSync(path.join(venvLibPath, pythonVersionPath))) {
40
+ // Try to find any python3.x directory
41
+ const libContents = fs.readdirSync(venvLibPath);
42
+ const pythonDirs = libContents.filter(item => item.startsWith('python3'));
43
+ if (pythonDirs.length > 0) {
44
+ // Use the first python3.x directory found
45
+ pythonVersionPath = pythonDirs[0];
46
+ if (isVerbose) {
47
+ console.log(`Found Python directory: ${pythonVersionPath}`);
48
+ }
49
+ }
50
+ }
51
+ }
52
+ catch (error) {
53
+ if (isVerbose) {
54
+ console.warn(`Warning: Could not determine Python version directory: ${error}`);
55
+ }
56
+ }
57
+ return pythonVersionPath;
58
+ }
@@ -1 +1,5 @@
1
- export declare const executeCommand: (command: string, rootDir: string) => Promise<unknown>;
1
+ interface ExecuteCommandOptions {
2
+ silent?: boolean;
3
+ }
4
+ export declare const executeCommand: (command: string, rootDir: string, options?: ExecuteCommandOptions) => Promise<string>;
5
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare function checkPythonVersionExists(pythonCmd: string, baseDir: string): Promise<boolean>;
2
+ export declare function getPythonCommand(requestedVersion: string, baseDir: string): Promise<string>;
3
+ export declare function findPythonSitePackagesDir(venvLibPath: string, pythonVersion: string, isVerbose?: boolean): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "motia",
3
3
  "description": "Code-first framework for intelligent workflows",
4
- "version": "0.2.1-beta.49",
4
+ "version": "0.2.1-beta.50",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -42,9 +42,9 @@
42
42
  "inquirer": "^8.2.5",
43
43
  "ts-node": "^10.9.2",
44
44
  "yaml": "^2.7.0",
45
- "@motiadev/core": "0.2.1-beta.49",
46
- "motia": "0.2.1-beta.49",
47
- "@motiadev/workbench": "0.2.1-beta.49"
45
+ "@motiadev/core": "0.2.1-beta.50",
46
+ "@motiadev/workbench": "0.2.1-beta.50",
47
+ "motia": "0.2.1-beta.50"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/archiver": "^6.0.3",