diff --git a/.github/workflows/run-pycodestyle.yml b/.github/workflows/run-pycodestyle.yml new file mode 100644 index 0000000..8840659 --- /dev/null +++ b/.github/workflows/run-pycodestyle.yml @@ -0,0 +1,12 @@ +name: Run PyCodeStyle +on: pull_request +jobs: + pylint: + runs-on: ubuntu-latest + steps: + - name: Check out repo + uses: actions/checkout@v4 + - name: Build Docker image + run: docker build . --file Dockerfile --target style --tag space-packet-parser-style:latest + - name: Run PyCodeStyle in Docker + run: docker run -i space-packet-parser-style:latest diff --git a/.gitignore b/.gitignore index e49e8cd..3aa1c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ Thumbs.db ####################### .idea .project +.run # Virtual environment # ####################### diff --git a/Dockerfile b/Dockerfile index 85be557..70d415f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Python version with which to test (must be supported and available on dockerhub) ARG BASE_IMAGE_PYTHON_VERSION -FROM python:${BASE_IMAGE_PYTHON_VERSION:-3.11}-slim AS test +FROM python:${BASE_IMAGE_PYTHON_VERSION:-3.12}-slim AS test USER root @@ -26,7 +26,6 @@ ENV PATH="$PATH:/root/.local/bin" COPY space_packet_parser $INSTALL_LOCATION/space_packet_parser COPY tests $INSTALL_LOCATION/tests -COPY pylintrc $INSTALL_LOCATION COPY pyproject.toml $INSTALL_LOCATION # LICENSE.txt is referenced by pyproject.toml COPY LICENSE.txt $INSTALL_LOCATION @@ -50,4 +49,12 @@ ENTRYPOINT pytest --cov-report=xml:coverage.xml \ FROM test AS lint -ENTRYPOINT pylint space_packet_parser \ No newline at end of file +COPY pylintrc $INSTALL_LOCATION + +ENTRYPOINT pylint space_packet_parser + +FROM test AS style + +COPY pycodestyle.ini $INSTALL_LOCATION + +ENTRYPOINT pycodestyle --config=pycodestyle.ini space_packet_parser diff --git a/docker-compose.yml b/docker-compose.yml index 752abbb..15381c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,14 @@ -version: '3.8' - services: lint: image: space-packets-linting:latest build: target: lint + style: + image: space-packets-style:latest + build: + target: style + 3.8-tests: image: space-packets-3.8-test:latest build: diff --git a/pycodestyle.ini b/pycodestyle.ini new file mode 100644 index 0000000..b3a9cdb --- /dev/null +++ b/pycodestyle.ini @@ -0,0 +1,4 @@ +[pycodestyle] +ignore = E121, E123, E126, E133, E226, E241, E242, E704, W503, W504, W505 +max-line-length = 120 +statistics = True diff --git a/pyproject.toml b/pyproject.toml index d861523..a4f224a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ keywords = [ python = ">=3.8" [tool.poetry.group.dev.dependencies] +pycodestyle = "*" pylint = "*" pytest = "*" pytest-randomly = "*" diff --git a/space_packet_parser/csvdef.py b/space_packet_parser/csvdef.py index 2eb92f7..be1878d 100644 --- a/space_packet_parser/csvdef.py +++ b/space_packet_parser/csvdef.py @@ -5,8 +5,16 @@ from collections import namedtuple from pathlib import Path # Local -from space_packet_parser.xtcedef import Comparison, Parameter, IntegerDataEncoding, FloatDataEncoding, StringDataEncoding, \ - IntegerParameterType, FloatParameterType, StringParameterType +from space_packet_parser.xtcedef import ( + Comparison, + Parameter, + IntegerDataEncoding, + FloatDataEncoding, + StringDataEncoding, + IntegerParameterType, + FloatParameterType, + StringParameterType +) FlattenedContainer = namedtuple('FlattenedContainer', ['entry_list', 'restrictions']) diff --git a/space_packet_parser/xtcedef.py b/space_packet_parser/xtcedef.py index 4b17ad8..e7d1109 100644 --- a/space_packet_parser/xtcedef.py +++ b/space_packet_parser/xtcedef.py @@ -2421,8 +2421,10 @@ def parse_sequence_container_contents(self, sequence_container: ElementTree.Elem try: parameter_type_class = self.type_tag_to_object[parameter_type_element.tag] except KeyError as e: - if ("ArrayParameterType" in parameter_type_element.tag or - "AggregateParameterType" in parameter_type_element.tag): + if ( + "ArrayParameterType" in parameter_type_element.tag or + "AggregateParameterType" in parameter_type_element.tag + ): raise NotImplementedError(f"Unsupported parameter type {parameter_type_element.tag}. " "Supporting this parameter type is in the roadmap but has " "not yet been implemented.") from e @@ -2436,10 +2438,10 @@ def parse_sequence_container_contents(self, sequence_container: ElementTree.Elem self._parameter_type_cache[parameter_type_name] = parameter_type_object # Add to cache parameter_short_description = parameter_element.attrib['shortDescription'] if ( - 'shortDescription' in parameter_element.attrib + 'shortDescription' in parameter_element.attrib ) else None parameter_long_description = parameter_element.find('xtce:LongDescription', self.ns).text if ( - parameter_element.find('xtce:LongDescription', self.ns) is not None + parameter_element.find('xtce:LongDescription', self.ns) is not None ) else None parameter_object = Parameter( @@ -2456,10 +2458,10 @@ def parse_sequence_container_contents(self, sequence_container: ElementTree.Elem entry_list.append(self.parse_sequence_container_contents(nested_container)) short_description = sequence_container.attrib['shortDescription'] if ( - 'shortDescription' in sequence_container.attrib + 'shortDescription' in sequence_container.attrib ) else None long_description = sequence_container.find('xtce:LongDescription', self.ns).text if ( - sequence_container.find('xtce:LongDescription', self.ns) is not None + sequence_container.find('xtce:LongDescription', self.ns) is not None ) else None return SequenceContainer(name=sequence_container.attrib['name'], @@ -2686,7 +2688,7 @@ def _get_container_base_container( def _extract_bits(data: bytes, start_bit: int, nbits: int): """Extract nbits from the data starting from the least significant end. - + If data = 00110101 11001010, start_bit = 2, nbits = 9, then the bits extracted are "110101110". Those bits are turned into a Python integer and returned. @@ -2698,7 +2700,7 @@ def _extract_bits(data: bytes, start_bit: int, nbits: int): Starting bit location within the data nbits : int Number of bits to extract - + Returns ------- int