diff --git a/modules/restricted-guests/synapse/package.json b/modules/restricted-guests/synapse/package.json index 05cfd61802..397948309c 100644 --- a/modules/restricted-guests/synapse/package.json +++ b/modules/restricted-guests/synapse/package.json @@ -13,10 +13,10 @@ "tsc": "echo \"Nothing to tsc\"", "lint": "echo \"Nothing to lint\"", "lint:ts": "echo \"Nothing to lint:ts\"", - "types:py": "node ./scripts/run_in_venv.js tox -e check_types", - "lint:py": "node ./scripts/run_in_venv.js tox -e check_codestyle", - "lint:fix": "node ./scripts/run_in_venv.js tox -e fix_codestyle", - "test": "node ./scripts/run_in_venv.js tox -e py", + "types:py": "./scripts/run_in_venv.sh tox -e check_types", + "lint:py": "./scripts/run_in_venv.sh tox -e check_codestyle", + "lint:fix": "./scripts/run_in_venv.sh tox -e fix_codestyle", + "test": "./scripts/run_in_venv.sh tox -e py", "depcheck": "echo \"Nothing to check\"", "package": "yarn docker:build" } diff --git a/modules/restricted-guests/synapse/scripts/run_in_venv.js b/modules/restricted-guests/synapse/scripts/run_in_venv.js deleted file mode 100644 index 472d471c32..0000000000 --- a/modules/restricted-guests/synapse/scripts/run_in_venv.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2023 Nordeck IT + Consulting GmbH - * Copyright 2025 New Vector Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// A script to run a command in a python virtual environment that is stored in -// `/.venv`. If the virtual environment doesn't exist yet, it will -// be created. -// -// Example: $ node ./run_in_venv.js python --version - -const fs = require("fs"); -const path = require("path"); -const child_process = require("child_process"); - -const cwd = path.resolve(__dirname, ".."); -const venvPath = path.resolve(__dirname, "../../../.venv"); -const venvRelativeToCwd = path.relative(cwd, venvPath); - -function run(command) { - return new Promise((resolve) => { - const proc = child_process.spawn(`source ${venvRelativeToCwd}/bin/activate && ${command}`, [], { - cwd, - stdio: "inherit", - shell: true, - }); - - proc.on("close", (code) => { - console.log("command terminated:", code); - resolve(); - }); - }); -} - -async function main() { - if (!fs.existsSync(venvPath) || !fs.lstatSync(venvPath).isDirectory()) { - child_process.execSync(`python3 -m venv ${venvRelativeToCwd}`, { cwd }); - await run("pip install tox"); - await run('pip install -e ."[dev]"'); - } - - const command = process.argv.slice(2).join(" "); - - await run(command); -} - -main(); diff --git a/modules/restricted-guests/synapse/scripts/run_in_venv.sh b/modules/restricted-guests/synapse/scripts/run_in_venv.sh new file mode 100755 index 0000000000..fb20a0a6d4 --- /dev/null +++ b/modules/restricted-guests/synapse/scripts/run_in_venv.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env sh + +# Copyright 2023 Nordeck IT + Consulting GmbH +# Copyright 2025 New Vector Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A script to run a command in a python virtual environment that is stored in +# `/.venv`. If the virtual environment doesn't exist yet, it will +# be created. +# +# Example: $ ./run_in_venv.sh python --version + +set -e + +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." + +repo_root=$(git rev-parse --show-cdup) +venv_path=${repo_root:-./}.venv + +[ -d "$venv_path" ] || python3.11 -m venv "$venv_path" +source "$venv_path/bin/activate" + +pip install -e ."[dev]" + +[ $# -gt 1 ] && $*