From 372ed2e44a29343722cf2cec9a557f1ed75469b8 Mon Sep 17 00:00:00 2001 From: Mark Stephenson Date: Tue, 5 Dec 2023 16:30:30 -0700 Subject: [PATCH] Issue #89: Check Basilisk version on import --- src/bsk_rl/__init__.py | 5 +++++ src/bsk_rl/bsk_version_req.txt | 1 + src/bsk_rl/check_bsk_version.py | 28 ++++++++++++++++++++++++++++ src/bsk_rl/finish_install.py | 4 ++++ 4 files changed, 38 insertions(+) create mode 100644 src/bsk_rl/bsk_version_req.txt create mode 100644 src/bsk_rl/check_bsk_version.py diff --git a/src/bsk_rl/__init__.py b/src/bsk_rl/__init__.py index ccb89ef8..cd711e48 100644 --- a/src/bsk_rl/__init__.py +++ b/src/bsk_rl/__init__.py @@ -1,5 +1,7 @@ from gymnasium.envs.registration import register +from bsk_rl.check_bsk_version import check_bsk_version + register(id="SimpleEOS-v0", entry_point="bsk_rl.envs.simple_eos.gym_env:SimpleEOS") register( @@ -33,3 +35,6 @@ id="SingleSatelliteTasking-v1", entry_point="bsk_rl.envs.general_satellite_tasking.gym_env:SingleSatelliteTasking", ) + + +check_bsk_version() diff --git a/src/bsk_rl/bsk_version_req.txt b/src/bsk_rl/bsk_version_req.txt new file mode 100644 index 00000000..cb47f847 --- /dev/null +++ b/src/bsk_rl/bsk_version_req.txt @@ -0,0 +1 @@ +2.2.1b0 \ No newline at end of file diff --git a/src/bsk_rl/check_bsk_version.py b/src/bsk_rl/check_bsk_version.py new file mode 100644 index 00000000..d28a051c --- /dev/null +++ b/src/bsk_rl/check_bsk_version.py @@ -0,0 +1,28 @@ +import os +from importlib.metadata import PackageNotFoundError, version +from warnings import warn + +from packaging.version import parse as parse_version + + +def check_bsk_version(): + f = open( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "bsk_version_req.txt", + ), + "r", + ) + bsk_req = parse_version(f.read().strip()) + try: + bsk_version = parse_version(version("Basilisk")) + if not bsk_version >= bsk_req: + warn( + f"Basilisk>={bsk_req} is required for full functionality. " + f"Currently installed: {bsk_version}", + ) + except PackageNotFoundError: + raise ImportError( + "The 'Basilisk' distribution was not found. Install from " + "http://hanspeterschaub.info/basilisk/." + ) diff --git a/src/bsk_rl/finish_install.py b/src/bsk_rl/finish_install.py index 41f5e8aa..be45eaec 100644 --- a/src/bsk_rl/finish_install.py +++ b/src/bsk_rl/finish_install.py @@ -6,6 +6,8 @@ import requests +from bsk_rl.check_bsk_version import check_bsk_version + def pck_install(): subprocess.check_call( @@ -29,3 +31,5 @@ def pck_install(): / "scenario" / "simplemaps_worldcities" ) + + check_bsk_version()