You've already forked OpenUxAS-bootstrap
mirror of
https://github.com/AdaCore/OpenUxAS-bootstrap.git
synced 2026-02-12 13:07:23 -08:00
Make sure references to python in shebangs and in text specify python3 rather than simply python. This better supports convention of fresh machines.
162 lines
4.2 KiB
Python
Executable File
162 lines
4.2 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
"""
|
|
Install anod virtual environment script.
|
|
|
|
This script automates the installation of the anod virtual environment, which
|
|
is required to build OpenUxAS using anod. You should generally run this script
|
|
from the root of bootstrap, like this:
|
|
|
|
python3 util/install-anod-venv
|
|
|
|
To get more information and to control the script's behavior, run:
|
|
|
|
python3 util/install-anod-venv --help
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
import shutil
|
|
|
|
from support.arguments import (
|
|
add_logging_group,
|
|
add_interactive_group,
|
|
add_apt_group,
|
|
add_force_argument,
|
|
add_dry_run_argument,
|
|
add_print_env_argument,
|
|
)
|
|
from support.commands import Command, run_command_and_exit_on_fail
|
|
from support.log import configure_logging, log_wrap
|
|
|
|
|
|
# Directory in which this script is executing.
|
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
CWD = os.getcwd()
|
|
SOFTWARE_DIR = os.path.join(CWD, "software")
|
|
|
|
APT_UPDATE = Command(cmd=["sudo", "apt", "update"], description="Updating apt",)
|
|
|
|
APT_INSTALL = Command(
|
|
cmd=[
|
|
"sudo",
|
|
"apt",
|
|
"install",
|
|
"-y",
|
|
"cmake",
|
|
"g++",
|
|
"pkg-config",
|
|
"uuid-dev",
|
|
"libyaml-dev",
|
|
"python3-dev",
|
|
"python3-distutils",
|
|
"python3-venv",
|
|
"python3-pip",
|
|
],
|
|
description="Installing dependencies",
|
|
)
|
|
|
|
VENV_DIR = os.path.join(CWD, "vpython")
|
|
VENV_PIP = os.path.join(VENV_DIR, "bin", "pip")
|
|
VENV_INSTALL = Command(
|
|
cmd=[sys.executable, "-m", "venv", "--clear", VENV_DIR],
|
|
description="Create python virtual environment",
|
|
)
|
|
|
|
WHEEL_INSTALL = Command(
|
|
cmd=[VENV_PIP, "install", "wheel"],
|
|
description="Installing wheel in the virtual environment",
|
|
)
|
|
|
|
E3_INSTALL = Command(
|
|
cmd=[VENV_PIP, "install", "e3-core", "e3-testsuite"],
|
|
description="Installing e3-core and e3-testsuite in the virtual environment",
|
|
)
|
|
|
|
ZMQ_INSTALL = Command(
|
|
cmd=[VENV_PIP, "install", "pyzmq"],
|
|
description="Install pyzmq in the virtual environment",
|
|
)
|
|
|
|
|
|
ENV_COMMANDS = f"""\
|
|
PATH={os.path.join(VENV_DIR, 'bin')}:$PATH\
|
|
"""
|
|
|
|
DESCRIPTION = """\
|
|
This script automates the installation of the anod virtual environment, which
|
|
is required to build OpenUxAS using anod. You should generally run this script
|
|
from the root of bootstrap, like this:
|
|
|
|
`python3 util/install-anod-venv`
|
|
"""
|
|
|
|
if __name__ == "__main__":
|
|
from argparse import ArgumentParser
|
|
|
|
argument_parser = ArgumentParser(description=DESCRIPTION,)
|
|
add_print_env_argument(argument_parser)
|
|
add_dry_run_argument(argument_parser)
|
|
add_force_argument(argument_parser)
|
|
|
|
add_interactive_group(argument_parser)
|
|
|
|
add_apt_group(argument_parser)
|
|
|
|
add_logging_group(argument_parser)
|
|
|
|
(args, _) = argument_parser.parse_known_args()
|
|
|
|
configure_logging(args)
|
|
|
|
if args.printenv:
|
|
print(ENV_COMMANDS)
|
|
exit(0)
|
|
|
|
skip_install_venv = False
|
|
|
|
if os.path.exists(VENV_DIR):
|
|
if args.force:
|
|
if args.dry_run:
|
|
print(f"rm -rf {VENV_DIR}")
|
|
else:
|
|
shutil.rmtree(VENV_DIR)
|
|
else:
|
|
logging.warning(
|
|
log_wrap(
|
|
"""\
|
|
The anod virtual environment already exists; skipping this
|
|
step. Remove it manually or use `--force` if you wish to
|
|
reinstall the virtual environment.\
|
|
"""
|
|
)
|
|
)
|
|
skip_install_venv = True
|
|
|
|
if skip_install_venv:
|
|
exit(0)
|
|
|
|
if args.update_apt and (
|
|
not args.interactive
|
|
or input("Update apt before installing packages? [Y/n] ") != "n"
|
|
):
|
|
run_command_and_exit_on_fail(APT_UPDATE, args.dry_run)
|
|
|
|
if args.install_packages and (
|
|
not args.interactive
|
|
or input("Install packages needed for anod virtual environment? " "[Y/n] ")
|
|
!= "n"
|
|
):
|
|
run_command_and_exit_on_fail(APT_INSTALL, args.dry_run)
|
|
|
|
if sys.platform == "linux":
|
|
assert os.path.isfile("/usr/include/uuid/uuid.h"), "Missing uuid.h"
|
|
|
|
run_command_and_exit_on_fail(VENV_INSTALL, args.dry_run)
|
|
run_command_and_exit_on_fail(WHEEL_INSTALL, args.dry_run)
|
|
run_command_and_exit_on_fail(E3_INSTALL, args.dry_run)
|
|
run_command_and_exit_on_fail(ZMQ_INSTALL, args.dry_run)
|