From 5ec28c1e51e022579633353383c456696299bef6 Mon Sep 17 00:00:00 2001 From: BjoernAtBosch Date: Wed, 4 Sep 2024 10:32:36 +0200 Subject: [PATCH] Velocitas offline (#89) Prepare Velocitas offline mode (enabling Python venv usage) --- .github/workflows/ci.yml | 4 +- build-system/cpp-cmake-conan/requirements.txt | 2 +- conan-setup/requirements.txt | 1 + grpc-interface-support/requirements.txt | 2 +- grpc-interface-support/src/python.py | 4 +- manifest.json | 54 +++++++++++--- sdk-installer/requirements.txt | 2 +- sdk-installer/src/run.py | 2 +- setup/requirements.txt | 2 +- setup/src/common/scripts/onCreateCommand.sh | 2 + vehicle-model-lifecycle/requirements.txt | 2 +- vehicle-model-lifecycle/src/install_deps.py | 70 ------------------- 12 files changed, 57 insertions(+), 90 deletions(-) create mode 100644 conan-setup/requirements.txt delete mode 100644 vehicle-model-lifecycle/src/install_deps.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61989697..fe12d780 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,6 +157,6 @@ jobs: export VELOCITAS_COMPONENT_PATH=${VELOCITAS_PACKAGE_REPO_PATH}/${{ matrix.component }} cd $VELOCITAS_PACKAGE_REPO_PATH - python -m pip install -r ./${{ matrix.component }}/test/requirements.txt - python -m pip install -r ./${{ matrix.component }}/requirements.txt + python3 -m pip install -r ./${{ matrix.component }}/test/requirements.txt + python3 -m pip install -r ./${{ matrix.component }}/requirements.txt pytest -s ./${{ matrix.component }}/test/integration diff --git a/build-system/cpp-cmake-conan/requirements.txt b/build-system/cpp-cmake-conan/requirements.txt index 3616ebfa..136cf097 100644 --- a/build-system/cpp-cmake-conan/requirements.txt +++ b/build-system/cpp-cmake-conan/requirements.txt @@ -1 +1 @@ -velocitas-lib==0.0.11 +velocitas-lib==0.0.12 diff --git a/conan-setup/requirements.txt b/conan-setup/requirements.txt new file mode 100644 index 00000000..136cf097 --- /dev/null +++ b/conan-setup/requirements.txt @@ -0,0 +1 @@ +velocitas-lib==0.0.12 diff --git a/grpc-interface-support/requirements.txt b/grpc-interface-support/requirements.txt index 1569a2c3..dd10552f 100644 --- a/grpc-interface-support/requirements.txt +++ b/grpc-interface-support/requirements.txt @@ -1,2 +1,2 @@ -velocitas-lib==0.0.11 +velocitas-lib==0.0.12 proto-schema-parser==1.3.4 diff --git a/grpc-interface-support/src/python.py b/grpc-interface-support/src/python.py index 84a05683..97f929d7 100644 --- a/grpc-interface-support/src/python.py +++ b/grpc-interface-support/src/python.py @@ -122,7 +122,7 @@ def __init__( def __invoke_code_generator(self) -> None: subprocess.check_call( [ - "python", + "python3", "-m", "grpc_tools.protoc", f"-I{self.__proto_include_path}", @@ -136,7 +136,7 @@ def __invoke_code_generator(self) -> None: for element in imports: path = os.path.join(self.__proto_include_path, element) args = [ - "python", + "python3", "-m", "grpc_tools.protoc", f"-I{self.__proto_include_path}", diff --git a/manifest.json b/manifest.json index 49037f5d..7cd1a4d8 100644 --- a/manifest.json +++ b/manifest.json @@ -63,21 +63,25 @@ "programs": [ { "id": "install-deps", - "executable": "python", + "executable": "python3", "args": [ - "./src/install_deps.py" + "-m", + "pip", + "install", + "-r", + "./requirements.txt" ] }, { "id": "download-vspec", - "executable": "python", + "executable": "python3", "args": [ "./src/download_vspec.py" ] }, { "id": "generate-model", - "executable": "python", + "executable": "python3", "args": [ "./src/generate_model.py" ] @@ -111,6 +115,17 @@ "description": "Sets up the conan client to connect to different remotes with credentials.", "basePath": "./conan-setup", "programs": [ + { + "id": "install-deps", + "executable": "python3", + "args": [ + "-m", + "pip", + "install", + "-r", + "./requirements.txt" + ] + }, { "id": "run", "executable": "python3", @@ -120,6 +135,9 @@ } ], "onPostInit": [ + { + "ref": "install-deps" + }, { "ref": "run" } @@ -139,7 +157,7 @@ "programs": [ { "id": "install-deps", - "executable": "python", + "executable": "python3", "args": [ "-m", "pip", @@ -150,7 +168,7 @@ }, { "id": "run", - "executable": "python", + "executable": "python3", "args": [ "./src/run.py" ] @@ -209,7 +227,7 @@ "programs": [ { "id": "install-deps", - "executable": "python", + "executable": "python3", "args": [ "-m", "pip", @@ -221,7 +239,7 @@ { "id": "generate-sdk", "description": "Generates service client SDKs to be used in business logic.", - "executable": "python", + "executable": "python3", "args": [ "./src/main.py" ] @@ -231,11 +249,27 @@ { "id": "build-system", "basePath": "build-system", + "onPostInit": [ + { + "ref": "install-deps" + } + ], "programs": [ + { + "id": "install-deps", + "executable": "python3", + "args": [ + "-m", + "pip", + "install", + "-r", + "./cpp-cmake-conan/requirements.txt" + ] + }, { "id": "install", "description": "Installs all necessary dependencies / packages for the application", - "executable": "python", + "executable": "python3", "args": [ "./cpp-cmake-conan/src/install_deps.py" ] @@ -243,7 +277,7 @@ { "id": "build", "description": "Builds the application", - "executable": "python", + "executable": "python3", "args": [ "./cpp-cmake-conan/src/build.py" ] diff --git a/sdk-installer/requirements.txt b/sdk-installer/requirements.txt index f01149b2..d6d52390 100644 --- a/sdk-installer/requirements.txt +++ b/sdk-installer/requirements.txt @@ -1,2 +1,2 @@ -velocitas-lib==0.0.11 +velocitas-lib==0.0.12 cloudevents # FIXME: this dep is missing in SDK! diff --git a/sdk-installer/src/run.py b/sdk-installer/src/run.py index f796d3a6..0065de40 100644 --- a/sdk-installer/src/run.py +++ b/sdk-installer/src/run.py @@ -137,7 +137,7 @@ def get_required_package_version(self, package_name: str) -> Optional[str]: def install_local_package(self, path: str) -> None: subprocess.check_call( - ["python", "-m", "pip", "install", "."], + ["python3", "-m", "pip", "install", "."], stdout=subprocess.DEVNULL if not self._verbose_logging else None, cwd=path, ) diff --git a/setup/requirements.txt b/setup/requirements.txt index 3616ebfa..136cf097 100644 --- a/setup/requirements.txt +++ b/setup/requirements.txt @@ -1 +1 @@ -velocitas-lib==0.0.11 +velocitas-lib==0.0.12 diff --git a/setup/src/common/scripts/onCreateCommand.sh b/setup/src/common/scripts/onCreateCommand.sh index 6432e4bb..7bb0cb42 100755 --- a/setup/src/common/scripts/onCreateCommand.sh +++ b/setup/src/common/scripts/onCreateCommand.sh @@ -21,6 +21,8 @@ sudo chown -R $(whoami) $HOME if [[ -z "${VELOCITAS_OFFLINE}" ]]; then .devcontainer/scripts/configure-codespaces.sh .devcontainer/scripts/upgrade-cli.sh +elif [[ -x .devcontainer/scripts/local-setup.sh ]]; then + .devcontainer/scripts/local-setup.sh fi echo "#######################################################" diff --git a/vehicle-model-lifecycle/requirements.txt b/vehicle-model-lifecycle/requirements.txt index 5ea2682e..99edcf7f 100644 --- a/vehicle-model-lifecycle/requirements.txt +++ b/vehicle-model-lifecycle/requirements.txt @@ -1,4 +1,4 @@ -velocitas-lib==0.0.11 +velocitas-lib==0.0.12 velocitas-model-generator==0.7.1 types-requests requests diff --git a/vehicle-model-lifecycle/src/install_deps.py b/vehicle-model-lifecycle/src/install_deps.py deleted file mode 100644 index 8b9a3038..00000000 --- a/vehicle-model-lifecycle/src/install_deps.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2023-2024 Contributors to the Eclipse Foundation -# -# This program and the accompanying materials are made available under the -# terms of the Apache License, Version 2.0 which is available at -# https://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. -# -# SPDX-License-Identifier: Apache-2.0 - -"""Provides methods and functions to download and install dependencies.""" - -import os -import subprocess -import sys - - -def require_env(name: str) -> str: - """Require and return an environment variable. - - Args: - name (str): The name of the variable. - - Raises: - ValueError: In case the environment variable is not set. - - Returns: - str: The value of the variable. - """ - var = os.getenv(name) - if not var: - raise ValueError(f"environment variable {var!r} not set!") - return var - - -def get_script_path() -> str: - """Return the absolute path to the directory the invoked Python script - is located in.""" - return os.path.dirname(os.path.realpath(sys.argv[0])) - - -def pip(args: list[str]) -> None: - """Invoke the pip process with the given arguments.""" - subprocess.check_call([sys.executable, "-m", "pip", *args]) - - -def should_install_model_generator() -> bool: - """Return whether to install the model generator or not.""" - env = os.getenv("installModelGenerator") - - if env is not None and env: - return True - - return False - - -def install_packages() -> None: - """Install all required Python packages for the model generator and - VSpec download.""" - script_path = get_script_path() - - pip(["install", "-r", f"{script_path}/../requirements.txt"]) - - -if __name__ == "__main__": - install_packages()