Skip to content

Commit

Permalink
Rename Consts -> Mission, Mission -> MissionConsts
Browse files Browse the repository at this point in the history
Consts by itself was found to be a bit too generic. While I had
initially proposed Consts->MissionConsts I think it works out a bit
better to do it the way in the title. Mission.default() or
Mission.ORESAT0 reads a bit better and the dataclass is where the actual
consts are.

This will break all the other projects using oresat-configs but I don't
really want to go through a backwards compatible release process to
smoothly fix up everything. I'll try to patch what we have and hopefully
anything I miss will yell loudly.
  • Loading branch information
ThirteenFish committed Nov 9, 2024
1 parent e404f74 commit 725d192
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 59 deletions.
6 changes: 3 additions & 3 deletions docs/scripts/gen_beacon_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import bitstring
import canopen

from oresat_configs import Consts, OreSatConfig
from oresat_configs import Mission, OreSatConfig

OD_DATA_TYPES = {
canopen.objectdictionary.BOOLEAN: "bool",
Expand Down Expand Up @@ -170,7 +170,7 @@ def gen_beacon_rst(config: OreSatConfig, file_path: str, url: str) -> None:
if obj.name in ["start_chars", "revision"]:
desc += f": {obj.value}\n"
if obj.name == "satellite_id":
sat = Consts.from_id(obj.value)
sat = Mission.from_id(obj.value)
desc += f": {sat.id}\n"
if obj.value_descriptions:
desc += "\n\nValue Descriptions:\n"
Expand Down Expand Up @@ -206,7 +206,7 @@ def gen_beacon_rst_files() -> None:
"""Generate all beacon rst files."""

parent_dir = os.path.dirname(os.path.abspath(__file__ + "/.."))
for mission in Consts:
for mission in Mission:
mission_name = mission.name.lower()
url = (
f"https://github.com/oresat/oresat-configs/blob/master/oresat_configs/{mission_name}"
Expand Down
14 changes: 7 additions & 7 deletions oresat_configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@
from .base import FW_COMMON_CONFIG_PATH
from .beacon_config import BeaconConfig
from .card_info import Card, cards_from_csv
from .constants import Consts, __version__
from .constants import Mission, __version__

__all__ = ["Card", "Consts", "__version__"]
__all__ = ["Card", "Mission", "__version__"]


class OreSatConfig:
"""All the configs for an OreSat mission."""

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

self.mission = mission
Expand Down
8 changes: 4 additions & 4 deletions oresat_configs/_yaml_to_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .beacon_config import BeaconConfig
from .card_config import CardConfig, ConfigObject, IndexObject, SubindexObject
from .card_info import Card
from .constants import Consts, __version__
from .constants import Mission, __version__

STD_OBJS_FILE_NAME = f"{os.path.dirname(os.path.abspath(__file__))}/standard_objects.yaml"

Expand Down Expand Up @@ -592,7 +592,7 @@ def _load_configs(config_paths: ConfigPaths) -> dict[str, CardConfig]:


def _gen_od_db(
mission: Consts,
mission: Mission,
cards: dict[str, Card],
beacon_def: BeaconConfig,
configs: dict[str, CardConfig],
Expand Down Expand Up @@ -639,7 +639,7 @@ def _gen_od_db(
# set specific obj defaults
od["versions"]["configs_version"].default = __version__
od["satellite_id"].default = mission.id
for sat in Consts:
for sat in Mission:
od["satellite_id"].value_descriptions[sat.id] = sat.name.lower()
if name == "c3":
od["beacon"]["revision"].default = beacon_def.revision
Expand Down Expand Up @@ -708,7 +708,7 @@ def _gen_c3_beacon_defs(c3_od: ObjectDictionary, beacon_def: BeaconConfig) -> li
return beacon_objs


def _gen_fw_base_od(mission: Consts, config_path: str) -> canopen.ObjectDictionary:
def _gen_fw_base_od(mission: Mission, config_path: str) -> canopen.ObjectDictionary:
"""Generate all ODs for a OreSat mission."""

od = canopen.ObjectDictionary()
Expand Down
4 changes: 2 additions & 2 deletions oresat_configs/card_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from dataclasses import dataclass, fields

from .constants import Consts
from .constants import Mission


@dataclass
Expand All @@ -25,7 +25,7 @@ class Card:
"""Optional child node name. Useful for CFC cards."""


def cards_from_csv(mission: Consts) -> dict[str, Card]:
def cards_from_csv(mission: Mission) -> dict[str, Card]:
"""Turns cards.csv into a dict of names->Cards, filtered by the current mission"""

file_path = f"{os.path.dirname(os.path.abspath(__file__))}/cards.csv"
Expand Down
14 changes: 7 additions & 7 deletions oresat_configs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

__all__ = [
"__version__",
"MissionConsts",
"Mission",
"Consts",
]

try:
Expand All @@ -25,7 +25,7 @@


@dataclass
class Mission:
class MissionConsts:
"""A specific set of constants associated with an OreSat Mission"""

id: int
Expand All @@ -35,8 +35,8 @@ class Mission:


@unique
class Consts(Mission, Enum):
"""Constants associated with each OreSat Mission"""
class Mission(MissionConsts, Enum):
"""Each OreSat Mission and constant configuration data associated with them"""

ORESAT0 = 1, "0", oresat0.BEACON_CONFIG_PATH, oresat0.CARD_CONFIGS_PATH
ORESAT0_5 = 2, "0.5", oresat0_5.BEACON_CONFIG_PATH, oresat0_5.CARD_CONFIGS_PATH
Expand All @@ -53,12 +53,12 @@ def filename(self) -> str:
return str(self).lower().replace(".", "_")

@classmethod
def default(cls) -> Consts:
def default(cls) -> Mission:
"""Returns the currently active mission"""
return cls.ORESAT0_5

@classmethod
def from_string(cls, val: str) -> Consts:
def from_string(cls, val: str) -> Mission:
"""Fetches the Mission associated with an appropriate string
Appropriate strings are the arg (0, 0.5, ...), optionally prefixed with
Expand All @@ -71,7 +71,7 @@ def from_string(cls, val: str) -> Consts:
raise ValueError(f"invalid oresat mission: {val}")

@classmethod
def from_id(cls, val: int) -> Consts:
def from_id(cls, val: int) -> Mission:
"""Fetches the Mission associated with an appropriate ID
Appropriate IDs are integers 1, 2, ... that corespond to the specific
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/gen_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from canopen.objectdictionary import REAL32, REAL64, UNSIGNED_TYPES, Variable

from .. import Consts, OreSatConfig, __version__
from .. import Mission, OreSatConfig, __version__

GEN_DBC = "generate dbc file for SavvyCAN"

Expand Down Expand Up @@ -122,8 +122,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = GEN_DBC
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/gen_dcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import canopen
from canopen.objectdictionary import Variable

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

GEN_DCF = "generate DCF file for OreSat node(s)"

Expand All @@ -20,8 +20,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = GEN_DCF
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/gen_fw_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import canopen

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

GEN_FW_FILES = "generate CANopenNode OD.[c/h] files for a OreSat firmware card"

Expand All @@ -21,8 +21,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = GEN_FW_FILES
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/gen_kaitai.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from canopen.objectdictionary import Array, Record
from yaml import dump

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

GEN_KAITAI = "generate beacon kaitai configuration"

Expand All @@ -20,8 +20,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = GEN_KAITAI
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/gen_xtce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import canopen

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

GEN_XTCE = "generate beacon xtce file"

Expand All @@ -20,8 +20,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = GEN_XTCE
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
8 changes: 4 additions & 4 deletions oresat_configs/scripts/list_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tabulate import tabulate

from ..card_info import Card, cards_from_csv
from ..constants import Consts
from ..constants import Mission

LIST_CARDS = "list oresat cards, suitable as arguments to other commands"

Expand All @@ -22,8 +22,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.formatter_class = RawDescriptionHelpFormatter
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down Expand Up @@ -65,7 +65,7 @@ def list_cards(args: Optional[Namespace] = None) -> None:
if args is None:
args = build_parser(ArgumentParser()).parse_args()

cards = cards_from_csv(Consts.from_string(args.oresat))
cards = cards_from_csv(Mission.from_string(args.oresat))
data: dict[str, list[str]] = defaultdict(list)
data["name"] = list(cards)
for card in cards.values():
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/pdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import canopen

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

PDO = "list or receive PDOs from the specified card"

Expand All @@ -19,8 +19,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = PDO
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/print_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import canopen

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig
from .._yaml_to_od import STR_2_OD_DATA_TYPE

PRINT_OD = "print the object dictionary out to stdout"
Expand All @@ -19,8 +19,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
parser.description = PRINT_OD
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
6 changes: 3 additions & 3 deletions oresat_configs/scripts/sdo_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import canopen

from .. import Consts, OreSatConfig
from .. import Mission, OreSatConfig

SDO_TRANSFER = "read or write value to a node's object dictionary via SDO transfers"

Expand All @@ -38,8 +38,8 @@ def build_parser(parser: ArgumentParser) -> ArgumentParser:
)
parser.add_argument(
"--oresat",
default=Consts.default().arg,
choices=[m.arg for m in Consts],
default=Mission.default().arg,
choices=[m.arg for m in Mission],
type=lambda x: x.lower().removeprefix("oresat"),
help="Oresat Mission. (Default: %(default)s)",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import canopen

from oresat_configs import Consts, OreSatConfig
from oresat_configs import Mission, OreSatConfig
from oresat_configs._yaml_to_od import OD_DATA_TYPES, TPDO_COMM_START, TPDO_PARA_START

INT_MIN_MAX = {
Expand All @@ -24,7 +24,7 @@ class TestConfig(unittest.TestCase):
"""Base class to test a OreSat OD databases."""

def setUp(self) -> None:
self.oresatid = Consts.ORESAT0
self.oresatid = Mission.ORESAT0
self.config = OreSatConfig(self.oresatid)

def test_tpdo_sizes(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_oresat0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for OreSat0 OD database."""

from oresat_configs import Consts, OreSatConfig
from oresat_configs import Mission, OreSatConfig

from . import TestConfig

Expand All @@ -9,5 +9,5 @@ class TestOreSat0(TestConfig):
"""Test the OreSat0 OD database."""

def setUp(self) -> None:
self.oresatid = Consts.ORESAT0
self.oresatid = Mission.ORESAT0
self.config = OreSatConfig(self.oresatid)
Loading

0 comments on commit 725d192

Please sign in to comment.