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

add ruff and mypy #57

Merged
merged 3 commits into from
Jan 22, 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
25 changes: 12 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
// Set *default* container specific settings.json values on container create.
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.testing.pytestArgs": [
"--ignore=desired_state_generator/test/integration",
Expand All @@ -28,14 +33,11 @@
"python.testing.pytestEnabled": true,
"python.pythonPath": "/usr/bin/python3",
"python.defaultInterpreterPath": "/usr/bin/python3",
// Only Flake8 is used as linter and static code analyzer, as faster tool
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
// Style Formatter
"python.formatting.provider": "black",
// Security Linter
"python.linting.banditEnabled": true,
"python.disableInstallationCheck": true,
"python.analysis.typeCheckingMode": "basic",
// Strong Type Checker
"mypy.enabled": true,
"mypy.runUsingActiveInterpreter": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
Expand All @@ -48,14 +50,11 @@
"ms-azuretools.vscode-dapr",
"ms-azuretools.vscode-docker",
"ms-python.python",
"cschleiden.vscode-github-actions",
"rpdswtk.vsmqtt",
"dotjoshjohnson.xml",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"matangover.mypy",
"augustocdias.tasks-shell-input",
"ms-python.isort",
"ms-python.flake8"
"ms-python.mypy-type-checker",
"charliermarsh.ruff"
]
}
},
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install required packages
run: |
pip install mypy

- name: Run Linters
uses: ./.github/actions/pre-commit-action

Expand Down
67 changes: 20 additions & 47 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -25,45 +25,28 @@ repos:
exclude: ^runtime_k3d/src/runtime/deployment/config/helm/templates/|^runtime_k3d/src/app_deployment/config/helm/templates/|^config/feedercan/
- id: check-added-large-files

- 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
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-unused-arguments
args: ["--ignore=E203"]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
types: [python]
args: ["--ini", "setup.cfg"]

# Commented out because of mypy bug failing for "match case" syntax
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.2.0"
# hooks:
# - id: mypy
# args: [runtime_k3d, runtime_local]
# language: system
# pass_filenames: false

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
- id: mypy
args:
[
"--config-file",
"setup.cfg",
runtime_k3d,
runtime_local,
runtime_kanto,
desired_state_generator,
]
language: system
pass_filenames: false

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
Expand All @@ -80,16 +63,6 @@ repos:
- --use-current-year
- --allow-past-years
- --skip-license-insertion-comment=This file is maintained by velocitas CLI, do not modify manually.
- id: insert-license
files: '.*\.(cpp|c|cc|h)$'
args:
- --license-filepath
- license_header.txt
- --comment-style
- /**| *| */
- --use-current-year
- --allow-past-years
- --skip-license-insertion-comment=This file is maintained by velocitas CLI, do not modify manually.
- id: insert-license
files: "Dockerfile.*"
args:
Expand Down
10 changes: 3 additions & 7 deletions runtime_k3d/src/app_deployment/deploy_vehicleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
from yaspin import yaspin


def is_vehicleapp_installed(
log_output: TextIOWrapper | int = subprocess.DEVNULL,
) -> bool:
def is_vehicleapp_installed(log_output: TextIOWrapper) -> bool:
"""Return whether the runtime is installed or not.

Args:
Expand All @@ -47,7 +45,7 @@ def is_vehicleapp_installed(
)


def uninstall_vehicleapp(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def uninstall_vehicleapp(log_output: TextIOWrapper):
"""Uninstall VehicleApp helm chart

Args:
Expand All @@ -60,9 +58,7 @@ def uninstall_vehicleapp(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def install_vehicleapp(
app_name: str, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def install_vehicleapp(app_name: str, log_output: TextIOWrapper):
"""Install VehicleApp helm chart

Args:
Expand Down
38 changes: 12 additions & 26 deletions runtime_k3d/src/runtime/controlplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from yaspin.core import Yaspin


def registry_exists(log_output: TextIOWrapper | int = subprocess.DEVNULL) -> bool:
def registry_exists(log_output: TextIOWrapper) -> bool:
"""Check if the K3D registry exists.

Args:
Expand All @@ -42,7 +42,7 @@ def registry_exists(log_output: TextIOWrapper | int = subprocess.DEVNULL) -> boo
)


def create_registry(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def create_registry(log_output: TextIOWrapper):
"""Create the K3D registry.

Args:
Expand All @@ -55,7 +55,7 @@ def create_registry(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def delete_registry(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def delete_registry(log_output: TextIOWrapper):
"""Delete the K3D registry.

Args:
Expand All @@ -68,7 +68,7 @@ def delete_registry(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def cluster_exists(log_output: TextIOWrapper | int = subprocess.DEVNULL) -> bool:
def cluster_exists(log_output: TextIOWrapper) -> bool:
"""Check if the K3D cluster exists.

Args:
Expand Down Expand Up @@ -100,11 +100,7 @@ def append_proxy_var_if_set(proxy_args: List[str], var_name: str): # noqa: U100
proxy_args += ["-e", f"{var_name}={var_content}@server:0"]


def create_cluster(
spinner: Yaspin,
config_dir_path: str,
log_output: TextIOWrapper | int = subprocess.DEVNULL,
):
def create_cluster(spinner: Yaspin, config_dir_path: str, log_output: TextIOWrapper):
"""Create the cluster with the given config dir.

Args:
Expand Down Expand Up @@ -154,7 +150,7 @@ def generate_ports_to_expose() -> List[str]:
return exposed_services


def delete_cluster(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def delete_cluster(log_output: TextIOWrapper):
"""Delete the K3D cluster.

Args:
Expand All @@ -167,9 +163,7 @@ def delete_cluster(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def deployment_exists(
deployment_name: str, log_output: TextIOWrapper | int = subprocess.DEVNULL
) -> bool:
def deployment_exists(deployment_name: str, log_output: TextIOWrapper) -> bool:
"""Check if the deployment of a given name exists.

Args:
Expand All @@ -189,7 +183,7 @@ def deployment_exists(
)


def deploy_zipkin(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def deploy_zipkin(log_output: TextIOWrapper):
"""Deploy zipkin to the cluster.

Args:
Expand Down Expand Up @@ -218,9 +212,7 @@ def deploy_zipkin(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def dapr_is_initialized_with_k3d(
log_output: TextIOWrapper | int = subprocess.DEVNULL,
) -> bool:
def dapr_is_initialized_with_k3d(log_output: TextIOWrapper) -> bool:
"""Check if dapr is initialized with k3d.

Args:
Expand All @@ -237,9 +229,7 @@ def dapr_is_initialized_with_k3d(


def initialize_dapr_with_k3d(
dapr_runtime_version: str,
dapr_config_dir_path: str,
log_output: TextIOWrapper | int = subprocess.DEVNULL,
dapr_runtime_version: str, dapr_config_dir_path: str, log_output: TextIOWrapper
):
"""Initialize dapr with K3D.

Expand Down Expand Up @@ -270,9 +260,7 @@ def initialize_dapr_with_k3d(
)


def configure_controlplane(
spinner: Yaspin, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def configure_controlplane(spinner: Yaspin, log_output: TextIOWrapper):
"""Configure the K3D control plane and display the progress
using the given spinner.

Expand Down Expand Up @@ -325,9 +313,7 @@ def configure_controlplane(
spinner.write(status)


def reset_controlplane(
spinner: Yaspin, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def reset_controlplane(spinner: Yaspin, log_output: TextIOWrapper):
"""Reset the K3D control plane and display the progress
using the given spinner.

Expand Down
2 changes: 1 addition & 1 deletion runtime_k3d/src/runtime/deployment/gen_podspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def generate_nodeport_service(service_id: str, port: str) -> dict[str, Any]:
service_config: The parsed configuration from the runtime.json
port: The port to be published
"""
nodeport_spec = {
nodeport_spec: dict[str, Any] = {
"apiVersion": "v1",
"kind": "Service",
"metadata": {"name": f"{service_id}-nodeport{port}"},
Expand Down
24 changes: 8 additions & 16 deletions runtime_k3d/src/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from deployment.gen_helm import gen_helm # noqa: E402


def is_runtime_installed(log_output: TextIOWrapper | int = subprocess.DEVNULL) -> bool:
def is_runtime_installed(log_output: TextIOWrapper) -> bool:
"""Return whether the runtime is installed or not.

Args:
Expand All @@ -48,9 +48,7 @@ def is_runtime_installed(log_output: TextIOWrapper | int = subprocess.DEVNULL) -
return False


def retag_docker_image(
image_name: str, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def retag_docker_image(image_name: str, log_output: TextIOWrapper):
"""Retag the given docker image to be available in K8S.

Args:
Expand All @@ -74,7 +72,7 @@ def retag_docker_image(
)


def retag_docker_images(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def retag_docker_images(log_output: TextIOWrapper):
"""Retag docker images of all defined services from runtime.json

Args:
Expand All @@ -85,7 +83,7 @@ def retag_docker_images(log_output: TextIOWrapper | int = subprocess.DEVNULL):
retag_docker_image(service.config.image, log_output)


def create_config_maps(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def create_config_maps(log_output: TextIOWrapper):
"""Create config maps for all services.

Args:
Expand Down Expand Up @@ -121,9 +119,7 @@ def create_config_maps(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def install_runtime(
helm_chart_path: str, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def install_runtime(helm_chart_path: str, log_output: TextIOWrapper):
"""Install the runtime from the given helm chart.

Args:
Expand All @@ -149,7 +145,7 @@ def install_runtime(
)


def uninstall_runtime(log_output: TextIOWrapper | int = subprocess.DEVNULL):
def uninstall_runtime(log_output: TextIOWrapper):
"""Uninstall the runtime.

Args:
Expand All @@ -162,9 +158,7 @@ def uninstall_runtime(log_output: TextIOWrapper | int = subprocess.DEVNULL):
)


def deploy_runtime(
spinner: Yaspin, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def deploy_runtime(spinner: Yaspin, log_output: TextIOWrapper):
"""Deploy the runtime and display the progress using the given spinner.

Args:
Expand All @@ -183,9 +177,7 @@ def deploy_runtime(
spinner.write(status)


def undeploy_runtime(
spinner: Yaspin, log_output: TextIOWrapper | int = subprocess.DEVNULL
):
def undeploy_runtime(spinner: Yaspin, log_output: TextIOWrapper):
"""Undeploy/remove the runtime and display the progress
using the given spinner.

Expand Down
Loading
Loading