Skip to content

Commit

Permalink
OreSatConfig can be called with None/no argument
Browse files Browse the repository at this point in the history
Most invocations of OreSatConfigs at this point are with
Mission.default() as the argument so we might as well be nice and do it
here instead of asking each user.

mypy got a little picky about types so this change ended up being bigger
than I expected but most of it is just mission -> self.mission.
  • Loading branch information
ThirteenFish committed Nov 16, 2024
1 parent 8bf0bd6 commit 2e80e0e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions oresat_configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@
class OreSatConfig:
"""All the configs for an OreSat mission."""

def __init__(self, mission: Union[Mission, str]):
def __init__(self, mission: Union[Mission, str, None] = None):
"""The parameter mission may be:
- a string, either short or long mission name ('0', 'OreSat0.5', ...)
- a Mission (ORESAT0, ...)
- Omitted or None, in which case Mission.default() is chosen
It will be used to derive the appropriate Mission, the collection of
constants associated with a specific oresat mission.
"""
if isinstance(mission, str):
mission = Mission.from_string(mission)
elif not isinstance(mission, Mission):
if mission is None:
self.mission = Mission.default()
elif isinstance(mission, str):
self.mission = Mission.from_string(mission)
elif isinstance(mission, Mission):
self.mission = mission
else:
raise TypeError(f"Unsupported mission type: '{type(mission)}'")

self.mission = mission
with as_file(mission.beacon) as path:
with as_file(self.mission.beacon) as path:
beacon_config = BeaconConfig.from_yaml(path)
with as_file(mission.cards) as path:
with as_file(self.mission.cards) as path:
self.cards = cards_from_csv(path)
self.configs = _load_configs(self.cards, mission.overlays)
self.od_db = _gen_od_db(mission, self.cards, beacon_config, self.configs)
self.configs = _load_configs(self.cards, self.mission.overlays)
self.od_db = _gen_od_db(self.mission, self.cards, beacon_config, self.configs)
c3_od = self.od_db["c3"]
self.beacon_def = _gen_c3_beacon_defs(c3_od, beacon_config)
self.fram_def = _gen_c3_fram_defs(c3_od, self.configs["c3"])
self.fw_base_od = _gen_fw_base_od(mission)
self.fw_base_od = _gen_fw_base_od(self.mission)

0 comments on commit 2e80e0e

Please sign in to comment.