Skip to content

Commit d38bb62

Browse files
authored
Louis/update-setup-script (#71)
* Add loop for installing packages Loops through array of packages and attempts to install them one by one. * Run venv script on post-install
1 parent 1729dfd commit d38bb62

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

bin/pyvenv.sh

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,32 @@ else
3535
echo "Using virtual environment at $venv"
3636
fi
3737

38-
# Check if Qiskit package is installed. If yes, exit successfully.
39-
if [[ -x "$python_path" ]]; then
40-
if "$python_path" -c "import qiskit" &>/dev/null; then
41-
echo "Qiskit is installed"
42-
exit 0
38+
39+
# Install package dependencies.
40+
declare -a packages=("qiskit" "matplotlib" "pylatexenc")
41+
for i in "${packages[@]}"; do
42+
# Check if the package is installed. If yes, exit successfully.
43+
if [[ -x "$python_path" ]]; then
44+
if "$python_path" -c "import $i" &>/dev/null; then
45+
echo "$i is installed"
46+
continue
47+
fi
48+
else
49+
echo "Error: failed to execute $python_path"
50+
exit 1
4351
fi
44-
else
45-
echo "Error: failed to execute $python_path"
46-
exit 1
47-
fi
4852

49-
# Install Qiskit within the virtual environment using pip.
50-
if [[ -x "$pip_path" ]]; then
51-
echo "Installing Qiskit..."
52-
if "$pip_path" install --quiet qiskit; then
53-
echo "Successfully installed Qiskit"
53+
# Install package within the virtual environment using pip.
54+
if [[ -x "$pip_path" ]]; then
55+
echo "Installing $i..."
56+
if "$pip_path" install --quiet "$i"; then
57+
echo "Successfully installed $i"
58+
else
59+
echo "Error: failed to install $i"
60+
continue
61+
fi
5462
else
55-
echo "Error: failed to install Qiskit"
63+
echo "Error: failed to execute $pip_path"
5664
exit 1
5765
fi
58-
else
59-
echo "Error: failed to execute $pip_path"
60-
exit 1
61-
fi
66+
done

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"venv": "bash bin/pyvenv.sh || bin/pyvenv.sh",
3232
"test": "mocha \"test/**/*_spec.js\"",
3333
"clean": "rm -r venv/ & npm uninstall --prefix ~/.node-red/ node-red-contrib-quantum",
34-
"lint": "eslint --fix --ignore-path .gitignore ."
34+
"lint": "eslint --fix --ignore-path .gitignore .",
35+
"postinstall": "npm run venv"
3536
},
3637
"dependencies": {
3738
"app-root-path": "^3.0.0",

0 commit comments

Comments
 (0)