Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python virtual environment #3305

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[python] setup venv and update pprzlink.
  • Loading branch information
Fabien-B authored and Fabien-B committed Oct 14, 2024
commit ba88c1a2cd57dca9c1cdf083587f58f0b0072ca7
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
.cache.xml
.directory

# python venv
pprzEnv/

# Eclipse IDE project files
*.cproject
*.project
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lxml
numpy
scipy
ivy-python
pyserial
PyQt5
PyQtWebEngine
pyqtgraph
unidecode
matplotlib
52 changes: 52 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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('-n', '--name', default='pprzEnv', help='environnment name')
parser.add_argument('-s', '--system', action='store_true', help="Use system site packages.")

parser.add_argument('-c', '--clean', action='store_true',
help="Clean aka delete the virtual environment and previous build results.")
args = parser.parse_args()

run(args)
11 changes: 4 additions & 7 deletions sw/supervision/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt5.QtWidgets import *
from typing import NamedTuple
from PyQt5.QtCore import QSettings
import subprocess


class GConfEntry(NamedTuple):
Expand Down Expand Up @@ -67,15 +68,11 @@ def get_build_version() -> str:
return version


def open_terminal(wd, command=None):
cmd = ""
if command is not None:
cmd = " -- {}".format(command)
def open_terminal(wd):
terminal_emulator = get_settings().value("terminal_emulator", "", str)
if terminal_emulator == "":
terminal_emulator = "gnome-terminal"
os.system("{}".format(terminal_emulator))

terminal_emulator = "x-terminal-emulator"
subprocess.Popen([terminal_emulator], cwd=wd)

def get_settings() -> QSettings:
return QSettings(os.path.join(CONF_DIR, "pprz_center_settings.ini"), QSettings.IniFormat)
Expand Down