Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Python and project structure, replace static analyzers with ruff #47

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
#
# SPDX-License-Identifier: Apache-2.0

FROM ubuntu:20.04
FROM ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.2

ENV DOCKER_BUILDKIT=1

# Fix for bug in devcontainer features
ADD https://raw.githubusercontent.com/devcontainers/features/7fa90110d762797cc0b1c2fe8fcc028c9b813d56/src/common-utils/install.sh /tmp/scripts/install-common.sh
RUN UID="4000" bash /tmp/scripts/install-common.sh

COPY scripts/*.sh /tmp/scripts/
RUN find /tmp/scripts/ -type f -iname "*.sh" -exec chmod +x {} \;
RUN /bin/bash /tmp/scripts/configure-proxies.sh
76 changes: 41 additions & 35 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.3/containers/dapr-javascript-node
{
"name": "Vehicle Model Generator",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": [
"--init",
"--privileged"
],
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.defaultInterpreterPath": "/usr/bin/python3",
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.linting.banditEnabled": true,
"python.linting.flake8Enabled": true,
"python.disableInstallationCheck": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"dotjoshjohnson.xml",
"matangover.mypy",
"ms-python.isort"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"onCreateCommand": "bash .devcontainer/scripts/postCreateCommand.sh",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
"name": "Vehicle Model Generator",
"dockerFile": "Dockerfile",
MP91 marked this conversation as resolved.
Show resolved Hide resolved
"customizations": {
"vscode": {
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.defaultInterpreterPath": "/usr/bin/python3",
"python.formatting.provider": "ruff",
"python.disableInstallationCheck": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"[python]": {
// Style Formatter
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"njpwerner.autodocstring",
"donjayamanne.python-extension-pack",
"tamasfe.even-better-toml",
"ms-python.mypy-type-checker"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"onCreateCommand": "bash .devcontainer/scripts/postCreateCommand.sh",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
32 changes: 0 additions & 32 deletions .devcontainer/scripts/add-python.sh

This file was deleted.

11 changes: 2 additions & 9 deletions .devcontainer/scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@
#
# SPDX-License-Identifier: Apache-2.0

sudo chmod +x .devcontainer/scripts/*.sh
sudo chown -R $(whoami) $HOME

echo "#######################################################"
echo "### Executing add-python.sh ###"
echo "#######################################################"
.devcontainer/scripts/add-python.sh 2>&1 | tee -a $HOME/add-python.log

pip3 install -r ./requirements-dev.txt
pip3 install -r ./requirements.txt
pip3 install -r ./requirements-vss.txt
pip3 install -e .

# add repo to git safe.directory
REPO=$(pwd)
Expand Down
62 changes: 61 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,67 @@ jobs:

- name: Install required packages
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Run Linters
uses: pre-commit/[email protected]

install-job:
name: "Install package"
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install model generator package
run: |
pip install .

run-tests:
name: "Run tests"
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install required packages
run: |
pip install -r requirements-dev.txt
pip install -r requirements.txt
pip install -e .

- name: unit test
shell: bash
run: |
pytest \
--junit-xml=./results/UnitTest/junit.xml \
--cov-report=xml:results/CodeCoverage/cobertura-coverage.xml \
--cov \
--cov-branch

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: ./results/UnitTest/junit.xml
summary: true
update_check: true
annotate_only: true

- uses: irongut/[email protected]
with:
filename: results/CodeCoverage/cobertura-coverage.xml
badge: true
format: markdown
hide_complexity: true
indicators: true
output: both
MP91 marked this conversation as resolved.
Show resolved Hide resolved

- run: |
cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache/

# Translations
*.mo
Expand Down Expand Up @@ -130,10 +131,14 @@ dmypy.json

# Generated vehicle model
output/
sdv_model/
velocitas_model/
out/

# VSS Submodule
vehicle_signal_specification/

# test reports
results/

# macOS specific
.DS_Store
2 changes: 2 additions & 0 deletions .licensechecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
whitelist-file-path: ./whitelisted-licenses.txt
scan-dirs:
- path: ./
python-pip-included-requirement-files:
- requirements-dev.txt
python-version: 3
50 changes: 8 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -30,55 +30,21 @@ repos:
)$
- id: check-merge-conflict

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2.pyi|
.*_pb2_grpc.py
)$
additional_dependencies:
- flake8-bugbear
- flake8-unused-arguments

- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args: ["--skip=B101"]
types_or: [python]
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.991"
rev: "v1.8.0"
hooks:
- id: mypy
args: ["sdv"]
args: ["src/velocitas"]
language: system
pass_filenames: false

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle

- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.18
hooks:
- id: helmlint

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
Expand Down
11 changes: 0 additions & 11 deletions .vscode/extensions.json

This file was deleted.

20 changes: 15 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@
"type": "python",
"request": "launch",
"name": "gen-vehicle-model",
"program": "${workspaceFolder}/gen_vehicle_model.py",
"program": "${workspaceFolder}/src/velocitas/model_generator/cli.py",
"console": "internalConsole",
"args": [
"-T", "sdv_model",
"-N", "sdv_model",
"-T", "velocitas_model",
"-N", "velocitas_model",
"-l", "${input:languageId}",
"-I", "./vehicle_signal_specification/spec",
"./vehicle_signal_specification/spec/VehicleSignalSpecification.vspec"
"-I", "${input:includeDir}",
"${input:inputFilePath}"
]
}
],
"inputs": [
{
"type":"promptString",
"id": "inputFilePath",
"description": "Path to the main input file. Either .vspec or .json."
},
{
"type": "promptString",
"id": "includeDir",
"description": "Included directories for a vspec tree."
},
{
"type": "pickString",
"id": "languageId",
Expand Down
26 changes: 0 additions & 26 deletions .vscode/settings.json

This file was deleted.

Loading