Skip to content

Commit

Permalink
Merge pull request #475 from vortexntnu/463-task-set-up-cicd-pipeline…
Browse files Browse the repository at this point in the history
…s-for-linting-and-code-formatting

Combine Python CI/CD pipelines into a single workflow and remove faulty pipelines
  • Loading branch information
kluge7 authored Sep 30, 2024
2 parents 0cd2b87 + 2feb5a1 commit 9005aed
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 179 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/clang-formatter.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/codespell.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/mypy.yaml

This file was deleted.

99 changes: 99 additions & 0 deletions .github/workflows/python-checks.yaml
Original file line number Diff line number Diff line change
@@ -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 .
68 changes: 0 additions & 68 deletions .github/workflows/python-format-lint.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/yaml-format.yaml

This file was deleted.

17 changes: 13 additions & 4 deletions mission/LCD/sources/ip_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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 ""

0 comments on commit 9005aed

Please sign in to comment.