Skip to content

Commit

Permalink
Issue #89: Check Basilisk version on import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Dec 5, 2023
1 parent 68758fc commit 311007e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bsk_rl/__init__.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -33,3 +35,6 @@
id="SingleSatelliteTasking-v1",
entry_point="bsk_rl.envs.general_satellite_tasking.gym_env:SingleSatelliteTasking",
)


check_bsk_version()
1 change: 1 addition & 0 deletions src/bsk_rl/bsk_version_req.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.1b0
35 changes: 35 additions & 0 deletions src/bsk_rl/check_bsk_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from warnings import warn

from pkg_resources import (
DistributionNotFound,
VersionConflict,
get_distribution,
require,
)


def check_bsk_version():
f = open(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"bsk_version_req.txt",
),
"r",
)
BSK_VERSION = f.read().strip()
try:
require(f"Basilisk>={BSK_VERSION}")
except VersionConflict:
warn(
f"Basilisk>={BSK_VERSION} is required for full functionality. "
f"Currently installed: {get_distribution('Basilisk').version}",
# ImportWarning,
)
except DistributionNotFound as e:
e._template = (
"The '{self.req}' distribution was not found "
"and is required by {self.requirers_str}. Install from "
"http://hanspeterschaub.info/basilisk/."
)
raise e
4 changes: 4 additions & 0 deletions src/bsk_rl/finish_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import requests

from bsk_rl.check_bsk_version import check_bsk_version


def pck_install():
subprocess.check_call(
Expand All @@ -29,3 +31,5 @@ def pck_install():
/ "scenario"
/ "simplemaps_worldcities"
)

check_bsk_version()

0 comments on commit 311007e

Please sign in to comment.