forked from paparazzi/paparazzi
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python virtual environment (paparazzi#3305)
* [python] setup venv and update pprzlink. * [supervision] open terminal in the venv if it exists. * clean setup.py * guard venv boostrap * [install] Use distro instead of lsb_release. --------- Co-authored-by: Fabien-B <[email protected]>
- Loading branch information
Showing
7 changed files
with
155 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ | |
.cache.xml | ||
.directory | ||
|
||
# python venv | ||
pprzEnv/ | ||
|
||
# Eclipse IDE project files | ||
*.cproject | ||
*.project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
source ~/.profile | ||
|
||
if [ -d "$PAPARAZZI_HOME/pprzEnv" ]; then | ||
source $PAPARAZZI_HOME/pprzEnv/bin/activate | ||
fi | ||
|
||
shell=$(echo $SHELL | cut -d / -f 3) | ||
|
||
if [ "$shell" = "bash" ]; then | ||
# enter bash specific commands here | ||
echo $shell > /dev/null | ||
elif [ "$shell" = "zsh" ]; then | ||
# enter zsh specific commands here | ||
echo $shell > /dev/null | ||
else | ||
# fallback commands | ||
echo $shell > /dev/null | ||
fi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,60 @@ | ||
#!/bin/bash | ||
|
||
sudo apt-get install -f -y python3 python3-pyqt5 | ||
USE_VENV=true | ||
BASHRC_SOURCE_VENV=false | ||
|
||
# exit on error | ||
set -e | ||
|
||
for arg in "$@" | ||
do | ||
if [ "$arg" = "-h" ] || [ "$arg" = "--help" ] | ||
then | ||
echo "Usage: ./install.sh [-n|--no-venv] [-h|---help]" | ||
echo " -n, --no-venv Do not use python virtual environment" | ||
echo " -s, --source Add venv source in ~/.bashrc" | ||
echo " -h, --help Print this help" | ||
exit 0 | ||
fi | ||
|
||
if [ "$arg" = "-n" ] || [ "$arg" = "--no-venv" ] | ||
then | ||
USE_VENV=false | ||
echo "the venv will not be installed!" | ||
fi | ||
|
||
if [ "$arg" = "-s" ] || [ "$arg" = "--source" ] | ||
then | ||
BASHRC_SOURCE_VENV=true | ||
fi | ||
|
||
done | ||
|
||
|
||
if [ $VIRTUAL_ENV ] | ||
then | ||
echo "Cannot create venv from itself! Run 'deactivate' first if you want to recreate the venv." | ||
USE_VENV = false | ||
BASHRC_SOURCE_VENV=false | ||
fi | ||
|
||
|
||
if [ "$USE_VENV" = true ] | ||
then | ||
sudo apt install -y python3 python3-venv | ||
python3 setup.py | ||
source pprzEnv/bin/activate | ||
|
||
if [ "$BASHRC_SOURCE_VENV" = true ] | ||
then | ||
echo "venv source will be added to ~/.bashrc" | ||
echo "source $(pwd)/pprzEnv/bin/activate" >> ~/.bashrc | ||
fi | ||
|
||
else | ||
sudo apt-get install -f -y python3 python3-pyqt5 | ||
fi | ||
|
||
python3 ./sw/tools/install.py | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
lxml | ||
numpy | ||
scipy | ||
ivy-python | ||
pyserial | ||
PyQt5 | ||
PyQtWebEngine | ||
pyqtgraph | ||
unidecode | ||
matplotlib | ||
distro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import venv | ||
import os | ||
import sys | ||
import subprocess | ||
import argparse | ||
import shutil | ||
|
||
ENV_NAME = 'pprzEnv' | ||
|
||
|
||
def run(args): | ||
if args.clean: | ||
if os.path.exists(ENV_NAME): | ||
print("Cleaning previous venv.") | ||
shutil.rmtree(ENV_NAME) | ||
else: | ||
print("No previous venv to clean.") | ||
|
||
print("Creating a virtual environment for Paparazzi...") | ||
venv.create(ENV_NAME, with_pip=True, system_site_packages=args.system) | ||
|
||
# installing requirements | ||
cmd = [f'./{ENV_NAME}/bin/pip', 'install', '-r' , 'requirements.txt'] | ||
result = subprocess.run(cmd, check=False) | ||
if result.returncode: | ||
print("Failed to create venv!") | ||
else: | ||
print("venv successfully created.") | ||
|
||
# installing pprzlink | ||
print("Installing pprzlink...") | ||
cmd = [f'./{ENV_NAME}/bin/pip', 'install', '-e' , 'sw/ext/pprzlink/lib/v2.0/python'] | ||
result = subprocess.run(cmd, check=False) | ||
if result.returncode: | ||
print("Failed to install pprzlink!") | ||
else: | ||
print("pprzlink successfully installed.") | ||
|
||
if not os.path.exists(f'./{ENV_NAME}/bin/calibrate.py'): | ||
os.symlink('../../sw/tools/calibration/calibrate.py', f'./{ENV_NAME}/bin/calibrate.py') | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="This script will setup the python environment for Paparazzi") | ||
parser.add_argument('-s', '--system', action='store_true', help="Use system site packages.") | ||
parser.add_argument('-c', '--clean', action='store_true', help="Delete the previous virtual environment before recreating it.") | ||
args = parser.parse_args() | ||
|
||
run(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters