From 249e445fdabe1d5a676a47aa6be7d008fb3a3398 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Sep 2023 16:59:19 +0200 Subject: [PATCH] lets see how well this works --- .flake8 | 17 ----------------- .github/workflows/package.yml | 9 +++------ docs/conf.py | 4 ---- pyproject.toml | 5 +++++ spacepackets/ccsds/spacepacket.py | 16 ++++++++-------- spacepackets/cfdp/lv.py | 5 ++++- spacepackets/cfdp/pdu/eof.py | 3 ++- spacepackets/cfdp/pdu/file_data.py | 3 ++- spacepackets/cfdp/pdu/metadata.py | 4 ++-- spacepackets/cfdp/pdu/nak.py | 5 +++-- spacepackets/cfdp/tlv.py | 19 ++++++++++++------- spacepackets/ecss/tc.py | 15 ++++++++------- spacepackets/ecss/tm.py | 29 +++++++++++++++++++---------- spacepackets/util.py | 7 +++---- tests/ccsds/test_space_packet.py | 12 +++++------- 15 files changed, 76 insertions(+), 77 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 9dca1e5..0000000 --- a/.flake8 +++ /dev/null @@ -1,17 +0,0 @@ -[flake8] -max-line-length = 100 -ignore = D203, W503 -per-file-ignores = - */__init__.py: F401 -exclude = - .git, - __pycache__, - docs/conf.py, - old, - build, - dist, - venv -max-complexity = 10 -extend-ignore = - # See https://github.com/PyCQA/pycodestyle/issues/373 - E203, diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 0ab85bc..04f96b3 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -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 . @@ -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: | diff --git a/docs/conf.py b/docs/conf.py index 1826c84..c2532eb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 ----------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 22f0ba9..0d0402f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,3 +38,8 @@ dependencies = [ [tool.setuptools.packages] find = {} + +[tool.ruff] +ignore = ["E501"] +[tool.ruff.extend-per-file-ignores] +"__init__.py" = ["F401"] diff --git a/spacepackets/ccsds/spacepacket.py b/spacepackets/ccsds/spacepacket.py index bd416ca..e3e9c25 100644 --- a/spacepackets/ccsds/spacepacket.py +++ b/spacepackets/ccsds/spacepacket.py @@ -2,7 +2,6 @@ of all CCSDS packets.""" from __future__ import annotations -import logging from abc import abstractmethod, ABC import enum import struct @@ -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: @@ -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( @@ -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): diff --git a/spacepackets/cfdp/lv.py b/spacepackets/cfdp/lv.py index 7311003..4c6d7d5 100644 --- a/spacepackets/cfdp/lv.py +++ b/spacepackets/cfdp/lv.py @@ -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 diff --git a/spacepackets/cfdp/pdu/eof.py b/spacepackets/cfdp/pdu/eof.py index bfab926..143cc5c 100644 --- a/spacepackets/cfdp/pdu/eof.py +++ b/spacepackets/cfdp/pdu/eof.py @@ -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})" ) diff --git a/spacepackets/cfdp/pdu/file_data.py b/spacepackets/cfdp/pdu/file_data.py index 0d2b79f..509edaf 100644 --- a/spacepackets/cfdp/pdu/file_data.py +++ b/spacepackets/cfdp/pdu/file_data.py @@ -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: diff --git a/spacepackets/cfdp/pdu/metadata.py b/spacepackets/cfdp/pdu/metadata.py index f5a3e74..9f03629 100644 --- a/spacepackets/cfdp/pdu/metadata.py +++ b/spacepackets/cfdp/pdu/metadata.py @@ -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): diff --git a/spacepackets/cfdp/pdu/nak.py b/spacepackets/cfdp/pdu/nak.py index b10fa25..a61609d 100644 --- a/spacepackets/cfdp/pdu/nak.py +++ b/spacepackets/cfdp/pdu/nak.py @@ -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 = [] @@ -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})" ) diff --git a/spacepackets/cfdp/tlv.py b/spacepackets/cfdp/tlv.py index 9a09250..3a28560 100644 --- a/spacepackets/cfdp/tlv.py +++ b/spacepackets/cfdp/tlv.py @@ -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() @@ -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)}" ) @@ -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 @@ -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: diff --git a/spacepackets/ecss/tc.py b/spacepackets/ecss/tc.py index abc2ad9..601805a 100644 --- a/spacepackets/ecss/tc.py +++ b/spacepackets/ecss/tc.py @@ -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): @@ -216,8 +216,8 @@ 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): @@ -225,9 +225,10 @@ def __str__(self): 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): diff --git a/spacepackets/ecss/tm.py b/spacepackets/ecss/tm.py index 1c98a9c..3a9510d 100644 --- a/spacepackets/ecss/tm.py +++ b/spacepackets/ecss/tm.py @@ -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): @@ -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): @@ -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 @@ -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.""" @@ -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""" diff --git a/spacepackets/util.py b/spacepackets/util.py index 42eceed..6da350e 100644 --- a/spacepackets/util.py +++ b/spacepackets/util.py @@ -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): @@ -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): diff --git a/tests/ccsds/test_space_packet.py b/tests/ccsds/test_space_packet.py index 2682a4b..b6caa0b 100644 --- a/tests/ccsds/test_space_packet.py +++ b/tests/ccsds/test_space_packet.py @@ -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):