From eb8040c7975079339a50402e87d794c78df93fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= <ibc@aliax.net>
Date: Thu, 17 Oct 2024 18:44:20 +0200
Subject: [PATCH] let's try

---
 npm-scripts.mjs | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/npm-scripts.mjs b/npm-scripts.mjs
index f589338..d1b9376 100644
--- a/npm-scripts.mjs
+++ b/npm-scripts.mjs
@@ -240,10 +240,19 @@ function installPythonDeps() {
 
 	// Install PIP deps into custom location, so we don't depend on system-wide
 	// installation.
-	executeCmd(
-		`"${PYTHON}" -m pip install --upgrade --no-user --target="${PIP_DEPS_DIR}" --break-system-packages worker/`,
-		/* exitOnError */ true
+	// However this may fail due to different PIP and OS versions, so let's do a
+	// best effort.
+	const res = executeCmd(
+		`"${PYTHON}" -m pip install --upgrade --no-user --target="${PIP_DEPS_DIR}" ${args} worker/`,
+		/* exitOnError */ false
 	);
+
+	if (!res) {
+		executeCmd(
+			`"${PYTHON}" -m pip install --upgrade --no-user --target="${PIP_DEPS_DIR}" ${args} --break-system-packages worker/`,
+			/* exitOnError */ true
+		);
+	}
 }
 
 function installPythonDevDeps() {
@@ -275,11 +284,19 @@ function checkRelease() {
 	}
 }
 
+/**
+ * Returns true if the command succeeded, 0 otherwise.
+ *
+ * If exitOnError is set and command fails, then process is terminated with
+ * error.
+ */
 function executeCmd(command, exitOnError = true) {
 	logInfo(`executeCmd(): ${command}`);
 
 	try {
 		execSync(command, { stdio: ['ignore', process.stdout, process.stderr] });
+
+		return true;
 	} catch (error) {
 		if (exitOnError) {
 			logError(`executeCmd() failed, exiting: ${error}`);
@@ -287,6 +304,8 @@ function executeCmd(command, exitOnError = true) {
 			exitWithError();
 		} else {
 			logInfo(`executeCmd() failed, ignoring: ${error}`);
+
+			return false;
 		}
 	}
 }