Skip to content

Commit

Permalink
Merge pull request #24 from ubuntu-robotics/dev/my_py_refactor
Browse files Browse the repository at this point in the history
Dev/my py refactor
  • Loading branch information
Guillaumebeuzeboc committed Mar 20, 2024
2 parents 4a6bd17 + 1c07511 commit a2be79f
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 144 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/rock-release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# does not allow setting a GHCR repo where to publish at the moment.
# We thus copy it below and adapt it.

name: Build ROCK and release dev tag to GHCR
name: Build ROCK and release dev or branch tag to GHCR

on:
workflow_dispatch:
Expand Down Expand Up @@ -41,7 +41,14 @@ jobs:

- name: Upload ROCK to ghcr.io
run: |
sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/cos-registration-server:dev --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"
if [[ ${{ github.ref }} == 'refs/heads/main' ]]
then
TAG=dev
else
TAG=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
TAG=$(echo $TAG | sed "s|\/|\_|")
fi
sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/cos-registration-server:$TAG --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"
- name: Generate digest
run: |
digest=$(skopeo inspect oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) --format '{{.Digest}}')
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/rock-release-pr.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fmt: ## Format code using black & isort.
lint: ## Run pep8, black, mypy linters.
$(ENV_PREFIX)flake8 cos_registration_server/ --exclude migrations,tests.py
$(ENV_PREFIX)black -l 79 --check cos_registration_server/
$(ENV_PREFIX)mypy --ignore-missing-imports cos_registration_server/
$(ENV_PREFIX)mypy --strict cos_registration_server

.PHONY: test
test: lint ## Run tests and generate coverage report.
Expand Down
21 changes: 14 additions & 7 deletions cos_registration_server/api/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""API app serializer."""

import json
from typing import Any, Dict, Union

from applications.models import Dashboard, GrafanaDashboard
from devices.models import Device
Expand All @@ -16,7 +17,9 @@ class Meta:
model = Dashboard
fields = ["uid", "dashboard"]

def update(self, instance, validated_data):
def update(
self, instance: Dashboard, validated_data: Dict[str, Any]
) -> Dashboard:
"""Update a Dashboard from data.
instance: Device instance.
Expand All @@ -27,7 +30,9 @@ def update(self, instance, validated_data):
instance.save()
return instance

def validate_dashboard(self, value):
def validate_dashboard(
self, value: Union[str, Dict[str, Any]]
) -> Dict[str, Any]:
"""Validate dashboards data.
value: dashboard provided data.
Expand All @@ -53,7 +58,7 @@ def validate_dashboard(self, value):


class GrafanaDashboardSerializer(
DashboardSerializer, serializers.ModelSerializer
DashboardSerializer, serializers.ModelSerializer # type: ignore[type-arg]
):
"""Grafana Dashboard Serializer class."""

Expand All @@ -62,15 +67,15 @@ class Meta(DashboardSerializer.Meta):

model = GrafanaDashboard

def create(self, validated_data):
def create(self, validated_data: Dict[str, Any]) -> GrafanaDashboard:
"""Create Grafana Dashboard object from data.
validated_data: Dict of complete and validated data.
"""
return GrafanaDashboard.objects.create(**validated_data)


class DeviceSerializer(serializers.ModelSerializer):
class DeviceSerializer(serializers.ModelSerializer): # type: ignore[type-arg]
"""Device Serializer class."""

grafana_dashboards = serializers.SlugRelatedField(
Expand All @@ -86,7 +91,7 @@ class Meta:
model = Device
fields = ("uid", "creation_date", "address", "grafana_dashboards")

def create(self, validated_data):
def create(self, validated_data: Dict[str, Any]) -> Device:
"""Create Device object from data.
validated_data: Dict of complete and validated data.
Expand All @@ -105,7 +110,9 @@ def create(self, validated_data):
)
return device

def update(self, instance, validated_data):
def update(
self, instance: Device, validated_data: Dict[str, Any]
) -> Device:
"""Update a Device from data.
instance: Device instance.
Expand Down
Loading

0 comments on commit a2be79f

Please sign in to comment.