diff --git a/.github/workflows/clang-formatter.yaml b/.github/workflows/clang-formatter.yaml deleted file mode 100644 index 5a3b02b2..00000000 --- a/.github/workflows/clang-formatter.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: Run clang-format Linter - -on: [pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: DoozyX/clang-format-lint-action@v0.18.1 - with: - source: "." - exclude: "./lib" - extensions: "h,cpp,c" - clangFormatVersion: 18 - inplace: True - - uses: EndBug/add-and-commit@v9 - with: - author_name: Clang Robot - author_email: robot@example.com - message: "Committing clang-format changes" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/codespell.yaml b/.github/workflows/codespell.yaml deleted file mode 100644 index 64f64e6b..00000000 --- a/.github/workflows/codespell.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: codespell - -on: [pull_request] - -jobs: - codespell: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Install codespell - run: | - sudo apt-get update - sudo apt-get install -y codespell - - - name: Run codespell to fix spelling mistakes - run: | - codespell -w . - - - name: Commit codespell changes - uses: EndBug/add-and-commit@v9 - with: - author_name: Codespell Robot - author_email: codespell-robot@example.com - message: "Committing codespell fixes" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/mypy.yaml b/.github/workflows/mypy.yaml deleted file mode 100644 index e8c633a3..00000000 --- a/.github/workflows/mypy.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: mypy - -on: [pull_request] - -jobs: - mypy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Install mypy - run: | - sudo apt-get update - sudo apt-get install -y python3-pip - pip3 install mypy - - - name: Run mypy type checking - run: | - mypy . --explicit-package-bases diff --git a/.github/workflows/python-checks.yaml b/.github/workflows/python-checks.yaml new file mode 100644 index 00000000..2047c444 --- /dev/null +++ b/.github/workflows/python-checks.yaml @@ -0,0 +1,99 @@ +name: Python Checks + +on: [pull_request] + +jobs: + black: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install black + run: | + python -m pip install black + + - name: Run black + run: | + black --check . + + isort: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install isort + run: | + python -m pip install isort + + - name: Run isort + run: | + isort --check . + + bandit: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install bandit + run: | + python -m pip install bandit[toml] + + - name: Run bandit scan + run: | + bandit -c pyproject.toml -r . --severity-level medium + + mypy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install mypy + run: | + python -m pip install mypy + + - name: Run mypy + run: | + mypy . --explicit-package-bases + + pylint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install pylint + run: | + python -m pip install pylint + + - name: Run pylint + run: | + pylint . diff --git a/.github/workflows/python-format-lint.yaml b/.github/workflows/python-format-lint.yaml deleted file mode 100644 index 3c7283fd..00000000 --- a/.github/workflows/python-format-lint.yaml +++ /dev/null @@ -1,68 +0,0 @@ -name: Python Format and Lint (isort, black, pylint) - -on: [pull_request] - -jobs: - isort: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Run isort to sort imports - uses: isort/isort-action@v1 - - - name: Commit isort changes - uses: EndBug/add-and-commit@v9 - with: - author_name: Isort Robot - author_email: isort-robot@example.com - message: "Committing isort changes" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - black: - runs-on: ubuntu-latest - needs: isort - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Check files using the black formatter - uses: rickstaa/action-black@v1 - id: action_black - with: - black_args: "." - - - name: Commit black-format changes - uses: EndBug/add-and-commit@v9 - with: - author_name: Black Robot - author_email: black-robot@example.com - message: "Committing black-format changes" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - pylint: - runs-on: ubuntu-latest - needs: black - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint - run: | - pylint $(git ls-files '*.py') diff --git a/.github/workflows/yaml-format.yaml b/.github/workflows/yaml-format.yaml deleted file mode 100644 index a0a5745f..00000000 --- a/.github/workflows/yaml-format.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Yaml Format (prettier) - -on: [pull_request] - -jobs: - prettier: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Install Prettier - run: | - sudo npm install -g prettier - - # Run Prettier to format all YAML files - - name: Run Prettier to format YAML files - run: | - prettier --write "**/*.yaml" "**/*.yml" - - # Commit Prettier changes - - name: Commit Prettier changes - uses: EndBug/add-and-commit@v9 - with: - author_name: Prettier Robot - author_email: prettier-robot@example.com - message: "Committing Prettier formatting fixes" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/mission/LCD/sources/ip_lib.py b/mission/LCD/sources/ip_lib.py index 5719249e..6828b651 100644 --- a/mission/LCD/sources/ip_lib.py +++ b/mission/LCD/sources/ip_lib.py @@ -5,7 +5,8 @@ class IPDriver: def __init__(self) -> None: - self.cmd = "hostname -I | cut -d' ' -f1" + # Store command as a list of arguments + self.cmd = ["hostname", "-I"] def get_ip(self) -> str: """ @@ -14,7 +15,15 @@ def get_ip(self) -> str: Returns: str: The IP address as a string. """ - ip_bytes = subprocess.check_output(self.cmd, shell=True) - ip_str = ip_bytes.decode("utf-8") + try: + # Run the command without shell=True + ip_bytes = subprocess.check_output(self.cmd, stderr=subprocess.STDOUT) + ip_str = ip_bytes.decode("utf-8").strip() - return ip_str + # Split by space and get the first IP + return ip_str.split()[0] + + except subprocess.CalledProcessError as e: + # Handle the error appropriately (e.g., log it or raise an exception) + print(f"Failed to retrieve IP address: {e}") + return ""