Skip to content

Commit

Permalink
Add pycodestyle as dev dependency (#60)
Browse files Browse the repository at this point in the history
Add pycodestyle.ini custom config file (must be manually referenced with pycodestyle CLI)
Add github workflow to check pycodestyle (in Docker)
Add style target in Dockerfile and style service in docker-compose.yml
Fix the issues caught by pycodestyle
  • Loading branch information
medley56 authored Sep 1, 2024
1 parent 1e8d1cf commit 7e44cb4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/run-pycodestyle.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Thumbs.db
#######################
.idea
.project
.run

# Virtual environment #
#######################
Expand Down
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -50,4 +49,12 @@ ENTRYPOINT pytest --cov-report=xml:coverage.xml \

FROM test AS lint

ENTRYPOINT pylint space_packet_parser
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
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 4 additions & 0 deletions pycodestyle.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pycodestyle]
ignore = E121, E123, E126, E133, E226, E241, E242, E704, W503, W504, W505
max-line-length = 120
statistics = True
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ keywords = [
python = ">=3.8"

[tool.poetry.group.dev.dependencies]
pycodestyle = "*"
pylint = "*"
pytest = "*"
pytest-randomly = "*"
Expand Down
12 changes: 10 additions & 2 deletions space_packet_parser/csvdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down
18 changes: 10 additions & 8 deletions space_packet_parser/xtcedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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'],
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 7e44cb4

Please sign in to comment.