Convert run_in_venv Node script to Bash
The work done by the script is simpler to achieve in Bash, and avoids a potential mis-parsing of arguments.
This commit is contained in:
@@ -13,10 +13,10 @@
|
|||||||
"tsc": "echo \"Nothing to tsc\"",
|
"tsc": "echo \"Nothing to tsc\"",
|
||||||
"lint": "echo \"Nothing to lint\"",
|
"lint": "echo \"Nothing to lint\"",
|
||||||
"lint:ts": "echo \"Nothing to lint:ts\"",
|
"lint:ts": "echo \"Nothing to lint:ts\"",
|
||||||
"types:py": "node ./scripts/run_in_venv.js tox -e check_types",
|
"types:py": "./scripts/run_in_venv.sh tox -e check_types",
|
||||||
"lint:py": "node ./scripts/run_in_venv.js tox -e check_codestyle",
|
"lint:py": "./scripts/run_in_venv.sh tox -e check_codestyle",
|
||||||
"lint:fix": "node ./scripts/run_in_venv.js tox -e fix_codestyle",
|
"lint:fix": "./scripts/run_in_venv.sh tox -e fix_codestyle",
|
||||||
"test": "node ./scripts/run_in_venv.js tox -e py",
|
"test": "./scripts/run_in_venv.sh tox -e py",
|
||||||
"depcheck": "echo \"Nothing to check\"",
|
"depcheck": "echo \"Nothing to check\"",
|
||||||
"package": "yarn docker:build"
|
"package": "yarn docker:build"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
// `<repo-root>/.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();
|
|
||||||
@@ -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
|
||||||
|
# `<repo-root>/.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 ] && $*
|
||||||
Reference in New Issue
Block a user