From 638cb982069abc45c1927c573528c7a9f5d62165 Mon Sep 17 00:00:00 2001 From: Diego Ferigo Date: Sat, 2 Oct 2021 12:12:48 +0200 Subject: [PATCH 1/2] Check the installed Ignition version from the command line --- scenario/bindings/__init__.py | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/scenario/bindings/__init__.py b/scenario/bindings/__init__.py index 56ee4744f..da41fc360 100644 --- a/scenario/bindings/__init__.py +++ b/scenario/bindings/__init__.py @@ -7,6 +7,24 @@ from enum import Enum, auto from pathlib import Path +import packaging.specifiers +import packaging.version + + +def supported_versions_specifier_set() -> packaging.specifiers.SpecifierSet: + + # If 6 is the Ignition distribution major version, the following specifier enables + # the compatibility with all the following versions: + # + # 6.Y.Z.devK + # 6.Y.Z.alphaK + # 6.Y.Z.betaK + # 6.Y.Z.rcK + # 6.Y.Z.preK + # 6.Y.Z.postK + # + return packaging.specifiers.SpecifierSet("~=6.0.0.dev") + class InstallMode(Enum): User = auto() @@ -92,6 +110,42 @@ def pre_import_gym() -> None: import gym +def check_gazebo_installation() -> None: + + import subprocess + + try: + command = ["ign", "gazebo", "--versions"] + result = subprocess.run(command, capture_output=True, text=True, check=True) + except FileNotFoundError: + msg = "Failed to find the 'ign' command in your PATH. " + msg += "Make sure that Ignition is installed " + msg += "and your environment is properly configured." + raise RuntimeError(msg) + except subprocess.CalledProcessError: + raise RuntimeError(f"Failed to execute command: {' '.join(command)}") # noqa + + gazebo_version_string = result.stdout.strip() + + # Get the gazebo version from the command line. + # Since the releases could be in the "6.0.0~preK" form, we replace '~' with '.' to + # be compatible with the 'packaging' package. + gazebo_version_string_normalized = gazebo_version_string.replace("~", ".") + + try: + # Parse the gazebo version + gazebo_version_parsed = packaging.version.Version( + gazebo_version_string_normalized + ) + except: + raise RuntimeError(f"Failed to parse the output of: {' '.join(command)}") + + if not gazebo_version_parsed in supported_versions_specifier_set(): + msg = f"Failed to find Ignition Gazebo {supported_versions_specifier_set()} " + msg += f"(found incompatible {gazebo_version_parsed})" + raise RuntimeError(msg) + + def import_gazebo() -> None: # Check the the module was never loaded by someone else @@ -140,6 +194,7 @@ def create_home_dot_folder() -> None: try: import_gazebo() + check_gazebo_installation() create_home_dot_folder() setup_gazebo_environment() from .bindings import gazebo From 9c1ab6cf114d9ece1c1b4ee926e1e4493fbd4aa6 Mon Sep 17 00:00:00 2001 From: Diego Ferigo Date: Sat, 2 Oct 2021 12:39:52 +0200 Subject: [PATCH 2/2] Add the 'packaging' dependency --- scenario/setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scenario/setup.cfg b/scenario/setup.cfg index fa2873164..83dd3bfc8 100644 --- a/scenario/setup.cfg +++ b/scenario/setup.cfg @@ -51,3 +51,5 @@ classifiers = [options] zip_safe = False python_requires = >=3.8 +install_requires = + packaging