Skip to content

Commit

Permalink
lets see how well this works
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Sep 7, 2023
1 parent 617be4e commit 249e445
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 77 deletions.
17 changes: 0 additions & 17 deletions .flake8

This file was deleted.

9 changes: 3 additions & 6 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
pip install flake8
pip install ruff
pip install -r docs/requirements.txt
pip install .
Expand All @@ -31,12 +31,9 @@ jobs:
sphinx-build -b html docs docs/_build
sphinx-build -b doctest docs docs/_build
- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
ruff .
- name: Run tests and generate coverage data
run: |
Expand Down
4 changes: 0 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys

sys.path.insert(0, os.path.abspath(".."))
from spacepackets.version import get_version

# -- Project information -----------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ dependencies = [

[tool.setuptools.packages]
find = {}

[tool.ruff]
ignore = ["E501"]
[tool.ruff.extend-per-file-ignores]
"__init__.py" = ["F401"]
16 changes: 8 additions & 8 deletions spacepackets/ccsds/spacepacket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
of all CCSDS packets."""
from __future__ import annotations

import logging
from abc import abstractmethod, ABC
import enum
import struct
Expand Down Expand Up @@ -101,8 +100,8 @@ def __repr__(self):
def __str__(self):
pstr = "TM" if self.ptype == PacketType.TM else "TC"
return (
f"Packet ID: [Packet Type: {pstr}, Sec Header Flag: {self.sec_header_flag}, "
f"APID: {self.apid:#05x}]"
f"Packet ID: [Packet Type: {pstr}, Sec Header Flag: {self.sec_header_flag},"
f" APID: {self.apid:#05x}]"
)

def raw(self) -> int:
Expand Down Expand Up @@ -173,7 +172,8 @@ def __init__(
"""
if data_len > pow(2, 16) - 1 or data_len < 0:
raise ValueError(
f"Invalid data length value, exceeds maximum value of {pow(2, 16) - 1} or negative"
"Invalid data length value, exceeds maximum value of"
f" {pow(2, 16) - 1} or negative"
)
self.ccsds_version = ccsds_version
self.packet_id = PacketId(
Expand Down Expand Up @@ -289,10 +289,10 @@ def unpack(cls, data: bytes) -> SpacePacketHeader:

def __repr__(self):
return (
f"{self.__class__.__name__}(packet_version={self.ccsds_version!r}, "
f"packet_type={self.packet_type!r}, apid={self.apid!r}, seq_cnt={self.seq_count!r}, "
f"data_len={self.data_len!r}, sec_header_flag={self.sec_header_flag!r}, "
f"seq_flags={self.seq_flags!r})"
f"{self.__class__.__name__}(packet_version={self.ccsds_version!r},"
f" packet_type={self.packet_type!r}, apid={self.apid!r},"
f" seq_cnt={self.seq_count!r}, data_len={self.data_len!r},"
f" sec_header_flag={self.sec_header_flag!r}, seq_flags={self.seq_flags!r})"
)

def __eq__(self, other: SpacePacketHeader):
Expand Down
5 changes: 4 additions & 1 deletion spacepackets/cfdp/lv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def __repr__(self):
return f"{self.__class__.__name__}(value={self.value!r})"

def __str__(self):
return f"CFDP LV with data 0x[{self.value.hex(sep=',')}] of length {len(self.value)}"
return (
f"CFDP LV with data 0x[{self.value.hex(sep=',')}] of length"
f" {len(self.value)}"
)

def __eq__(self, other):
return self.value == other.value
3 changes: 2 additions & 1 deletion spacepackets/cfdp/pdu/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def __eq__(self, other: EofPdu):
def __repr__(self):
return (
f"{self.__class__.__name__}(file_checksum={self.file_checksum!r},"
f"file_size={self.file_size!r}, pdu_conf={self.pdu_file_directive.pdu_conf},"
f"file_size={self.file_size!r},"
f" pdu_conf={self.pdu_file_directive.pdu_conf},"
f"fault_location={self.fault_location!r},"
f"condition_code={self.condition_code})"
)
3 changes: 2 additions & 1 deletion spacepackets/cfdp/pdu/file_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def pack(self) -> bytearray:
len_metadata = len(self._params.segment_metadata)
if len_metadata > 63:
raise ValueError(
f"Segment metadata length {len_metadata} invalid, larger than 63 bytes"
f"Segment metadata length {len_metadata} invalid, larger than 63"
" bytes"
)
file_data_pdu.append(self._params.record_cont_state << 6 | len_metadata)
if len_metadata > 0:
Expand Down
4 changes: 2 additions & 2 deletions spacepackets/cfdp/pdu/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def _parse_options(self, raw_packet: bytes, start_idx: int):

def __repr__(self):
return (
f"{self.__class__.__name__}(params={self.params!r}, options={self.options!r}, "
f"pdu_conf={self.pdu_file_directive.pdu_conf})"
f"{self.__class__.__name__}(params={self.params!r},"
f" options={self.options!r}, pdu_conf={self.pdu_file_directive.pdu_conf})"
)

def __eq__(self, other: MetadataPdu):
Expand Down
5 changes: 3 additions & 2 deletions spacepackets/cfdp/pdu/nak.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def unpack(cls, data: bytes) -> NakPdu:
packet_size_check = (len(data) - current_idx) % (struct_arg_tuple[1] * 2)
if packet_size_check != 0:
raise ValueError(
f"Invalid size for remaining data, "
"Invalid size for remaining data, "
f"which should be a multiple of {struct_arg_tuple[1] * 2}"
)
segment_requests = []
Expand Down Expand Up @@ -192,6 +192,7 @@ def __eq__(self, other: NakPdu):
def __repr__(self):
return (
f"{self.__class__.__name__}(start_of_scope={self.start_of_scope!r}, "
f"end_of_scope={self.end_of_scope!r}, pdu_conf={self.pdu_file_directive.pdu_conf!r}"
f"end_of_scope={self.end_of_scope!r},"
f" pdu_conf={self.pdu_file_directive.pdu_conf!r}"
f"segment_requests={self.segment_requests!r})"
)
19 changes: 12 additions & 7 deletions spacepackets/cfdp/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def unpack(cls, data: bytes) -> CfdpTlv:
tlv_type = TlvType(data[0])
except ValueError:
raise ValueError(
f"TLV field invalid, found value {data[0]} is not a possible TLV parameter"
f"TLV field invalid, found value {data[0]} is not a possible TLV"
" parameter"
)

value = bytearray()
Expand All @@ -239,12 +240,15 @@ def packet_len(self) -> int:
return self.MINIMAL_LEN + len(self._value)

def __repr__(self):
return f"{self.__class__.__name__}(tlv_type={self.tlv_type!r}, value={self.value!r})"
return (
f"{self.__class__.__name__}(tlv_type={self.tlv_type!r},"
f" value={self.value!r})"
)

def __str__(self):
return (
f"CFDP TLV with type {self.tlv_type} and data 0x[{self._value.hex(sep=',')}] with "
f"length {len(self._value)}"
f"CFDP TLV with type {self.tlv_type} and data"
f" 0x[{self._value.hex(sep=',')}] with length {len(self._value)}"
)


Expand Down Expand Up @@ -517,7 +521,8 @@ def _common_unpacker(
action_code = FilestoreActionCode(action_code_as_int)
except ValueError:
raise ValueError(
f"Invalid action code in file store response with value {action_code_as_int}"
"Invalid action code in file store response with value"
f" {action_code_as_int}"
)
status_code_as_int = raw_bytes[value_idx] & 0x0F
value_idx += 1
Expand Down Expand Up @@ -701,8 +706,8 @@ def _set_fields(cls, instance: FileStoreResponseTlv, data: bytes):
)
except ValueError:
raise ValueError(
f"Invalid status code in file store response with value {status_code} for "
f"action code {action_code}"
"Invalid status code in file store response with value"
f" {status_code} for action code {action_code}"
)
instance.status_code = status_code_named
if second_name is not None:
Expand Down
15 changes: 8 additions & 7 deletions spacepackets/ecss/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def unpack(cls, data: bytes) -> PusTcDataFieldHeader:

def __repr__(self):
return (
f"{self.__class__.__name__}(service={self.service!r}, subservice={self.subservice!r},"
f" ack_flags={self.ack_flags!r} "
f"{self.__class__.__name__}(service={self.service!r},"
f" subservice={self.subservice!r}, ack_flags={self.ack_flags!r} "
)

def __eq__(self, other: PusTcDataFieldHeader):
Expand Down Expand Up @@ -216,18 +216,19 @@ def empty(cls) -> PusTelecommand:
def __repr__(self):
"""Returns the representation of a class instance."""
return (
f"{self.__class__.__name__}.from_composite_fields(sp_header={self.sp_header!r}, "
f"sec_header={self.pus_tc_sec_header!r}, app_data={self.app_data!r})"
f"{self.__class__.__name__}.from_composite_fields(sp_header={self.sp_header!r},"
f" sec_header={self.pus_tc_sec_header!r}, app_data={self.app_data!r})"
)

def __str__(self):
"""Returns string representation of a class instance."""
from .req_id import RequestId

return (
f"PUS TC[{self.pus_tc_sec_header.service}, {self.pus_tc_sec_header.subservice}] with "
f"Request ID {RequestId.from_sp_header(self.sp_header).as_u32():#08x}"
f", APID {self.apid:#05x}, SSC {self.sp_header.seq_count}"
f"PUS TC[{self.pus_tc_sec_header.service},"
f" {self.pus_tc_sec_header.subservice}] with Request ID"
f" {RequestId.from_sp_header(self.sp_header).as_u32():#08x}, APID"
f" {self.apid:#05x}, SSC {self.sp_header.seq_count}"
)

def __eq__(self, other: PusTelecommand):
Expand Down
29 changes: 19 additions & 10 deletions spacepackets/ecss/tm.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ def unpack(

def __repr__(self):
return (
f"{self.__class__.__name__}(service={self.service!r}, subservice={self.subservice!r}, "
f"time={self.time_provider!r}, message_counter={self.message_counter!r}, "
f"dest_id={self.dest_id!r}, spacecraft_time_ref={self.spacecraft_time_ref!r}, "
f"pus_version={self.pus_version!r})"
f"{self.__class__.__name__}(service={self.service!r},"
f" subservice={self.subservice!r}, time={self.time_provider!r},"
f" message_counter={self.message_counter!r}, dest_id={self.dest_id!r},"
f" spacecraft_time_ref={self.spacecraft_time_ref!r},"
f" pus_version={self.pus_version!r})"
)

def __eq__(self, other: PusTmSecondaryHeader):
Expand Down Expand Up @@ -398,9 +399,8 @@ def __str__(self):

def __repr__(self):
return (
f"{self.__class__.__name__}.from_composite_fields({self.__class__.__name__}"
f"(sp_header={self.space_packet_header!r}, sec_header={self.pus_tm_sec_header!r}, "
f"tm_data={self.tm_data!r}"
f"{self.__class__.__name__}.from_composite_fields({self.__class__.__name__}(sp_header={self.space_packet_header!r},"
f" sec_header={self.pus_tm_sec_header!r}, tm_data={self.tm_data!r}"
)

def __eq__(self, other: PusTelemetry):
Expand Down Expand Up @@ -513,7 +513,10 @@ def crc16(self) -> Optional[bytes]:
@deprecation.deprecated(
deprecated_in="0.14.0rc3",
current_version=get_version(),
details="use pack and get_printable_data_string or the hex method on bytearray instead",
details=(
"use pack and get_printable_data_string or the hex method on bytearray"
" instead"
),
)
def get_full_packet_string(
self, print_format: PrintFormats = PrintFormats.HEX
Expand All @@ -524,7 +527,10 @@ def get_full_packet_string(
@deprecation.deprecated(
deprecated_in="0.14.0rc3",
current_version=get_version(),
details="use pack and get_printable_data_string or the hex method on bytearray instead",
details=(
"use pack and get_printable_data_string or the hex method on bytearray"
" instead"
),
)
def print_full_packet_string(self, print_format: PrintFormats = PrintFormats.HEX):
"""Print the full TM packet in a clean format."""
Expand All @@ -533,7 +539,10 @@ def print_full_packet_string(self, print_format: PrintFormats = PrintFormats.HEX
@deprecation.deprecated(
deprecated_in="0.14.0rc3",
current_version=get_version(),
details="use print, the source_data property and the hex method on bytearray instead",
details=(
"use print, the source_data property and the hex method on bytearray"
" instead"
),
)
def print_source_data(self, print_format: PrintFormats = PrintFormats.HEX):
"""Prints the TM source data in a clean format"""
Expand Down
7 changes: 3 additions & 4 deletions spacepackets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def verify_byte_len(byte_len: int):
def _verify_int_value(self, val: int):
if val > pow(2, self.byte_len * 8) - 1 or val < 0:
raise ValueError(
f"Passed value {val} larger than allowed {pow(2, self.byte_len * 8) - 1} or "
f"negative"
f"Passed value {val} larger than allowed"
f" {pow(2, self.byte_len * 8) - 1} or negative"
)

def _verify_bytes_value(self, val: bytes) -> (int, bytes):
Expand Down Expand Up @@ -198,8 +198,7 @@ def hex_str(self):

def __repr__(self):
return (
f"{self.__class__.__name__}(val={self.value!r}, "
f"byte_len={self.byte_len!r})"
f"{self.__class__.__name__}(val={self.value!r}, byte_len={self.byte_len!r})"
)

def __str__(self):
Expand Down
12 changes: 5 additions & 7 deletions tests/ccsds/test_space_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ def test_more_complex_output(self):
def test_repr(self):
self.assertEqual(
f"{self.sp_header!r}",
(
f"SpacePacketHeader(packet_version=0, packet_type={PacketType.TC!r}, "
f"apid={self.sp_header.apid}, seq_cnt={self.sp_header.seq_count}, "
f"data_len={self.sp_header.data_len}, "
f"sec_header_flag={self.sp_header.sec_header_flag}, "
f"seq_flags={self.sp_header.seq_flags!r})"
),
f"SpacePacketHeader(packet_version=0, packet_type={PacketType.TC!r}, "
f"apid={self.sp_header.apid}, seq_cnt={self.sp_header.seq_count}, "
f"data_len={self.sp_header.data_len}, "
f"sec_header_flag={self.sp_header.sec_header_flag}, "
f"seq_flags={self.sp_header.seq_flags!r})",
)

def test_apid_from_raw(self):
Expand Down

0 comments on commit 249e445

Please sign in to comment.