con un clic
python
// Python coding standards for SceneScape — imports, indentation, patterns, and conventions.
// Python coding standards for SceneScape — imports, indentation, patterns, and conventions.
Runtime test verification gate for SceneScape — image freshness checks, rebuild-before-test requirements, and retry policy.
Guide for creating SceneScape test cases — unit, functional, integration, UI, and smoke tests with positive and negative cases.
Procedures for updating SceneScape documentation — where to make changes and what to update for each type of modification.
JavaScript coding standards for SceneScape — code style, conventions, and frontend patterns.
Makefile standards for SceneScape — build targets, conventions, and patterns.
On-demand security review skill for SceneScape — code and configuration security guidance.
| name | python |
| description | Python coding standards for SceneScape — imports, indentation, patterns, and conventions. |
Organize imports in this order:
# Standard library
import json
import os
from pathlib import Path
# Third-party
import numpy as np
from django.http import HttpResponse
# Local
from scene_common import log
from scene_common.geometry import Point
from manager.models import Scene
PascalCase (e.g., SceneController, RESTClient)snake_case (e.g., get_scene_data, validate_message)UPPER_SNAKE_CASE (e.g., TOPIC_BASE, CHUNK_SIZE)_ (e.g., _process_data, _internal_state)make lint-python # Run both pylint and flake8
make format-python # Auto-format with autopep8
make indent-checkUse docstrings for classes and public methods:
def process_detection(self, detection_data):
"""Process detection data from sensor.
Args:
detection_data: Dictionary containing detection information
Returns:
Processed detection object or None on failure
"""
scene_common for shared geometry/camera classesListField (from manager.fields) for list/array storage - provides database portability (PostgreSQL and non-PostgreSQL) and robust handling of edge cases__str__ for admin interface readabilityfrom django.db import models
from scene_common.geometry import Region as ScenescapeRegion
from manager.fields import ListField
class Scene(models.Model):
name = models.CharField(max_length=255)
map = models.FileField(upload_to='maps/')
coordinates = ListField(default=list) # Works with PostgreSQL and SQLite
def __str__(self):
return self.name
CreateView, UpdateView, DeleteView)@login_required decorator for protected viewsJsonResponse for AJAX endpointsmanager.serializersIsAdminOrReadOnly)from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
class SceneAPI(APIView):
def get(self, request, scene_id):
# Implementation
return Response(data, status=status.HTTP_200_OK)
from scene_common.mqtt import PubSub
pubsub = PubSub(mqtt_auth, client_cert, root_cert, mqtt_broker, keepalive=60)
pubsub.onMessage = self.handle_message
pubsub.connect()
from scene_common.schema import SchemaValidation
schema_val = SchemaValidation(schema_file)
if not schema_val.validateMessage("detector", message_data):
log.error("Validation failed")
from scene_common.rest_client import RESTClient
client = RESTClient(rest_url, rest_auth, root_cert)
result = client.getScene(scene_id)
%s, %d) in log statements.from scene_common import log
log.info("Processing started")
log.error(f"Failed to process scene {scene_id}")
log.debug(f"Debug information: {debug_payload}")
Use type hints for function signatures:
from typing import Optional, List, Dict, Union
from pathlib import Path
def process_images(
image_paths: List[Path],
config: Optional[Dict] = None
) -> Union[np.ndarray, None]:
pass
Use specific exceptions and log appropriately:
try:
result = dangerous_operation()
except FileNotFoundError as e:
log.error(f"File not found: {e}")
return None
except Exception as e:
log.error(f"Unexpected error: {e}")
raise
# Good - shallow copy
data = original_data.copy()
# Use only when needed
data = copy.deepcopy(original_data)
# Preferred
results = [process(item) for item in items if item.valid]
# Over
results = []
for item in items:
if item.valid:
results.append(process(item))
❌ Don't use mutable default arguments:
# Bad
def process(data, cache={}):
pass
# Good
def process(data, cache=None):
if cache is None:
cache = {}
❌ Don't catch bare exceptions unless re-raising:
# Bad
try:
risky_operation()
except:
pass
# Good
try:
risky_operation()
except SpecificException as e:
log.error(f"Failed: {e}")
❌ Don't use from module import *:
# Bad
from scene_common.geometry import *
# Good
from scene_common.geometry import Point, Region
Development uses .venv in project root:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements-runtime.txt
VS Code configuration should point to .venv/bin/python.
requirements-runtime.txt for runtime dependenciesrequirements-build.txt for build-time dependencies