Skip to content

[tooling] Switch to ruff #1096

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

Merged
merged 12 commits into from
Aug 18, 2025
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
22 changes: 8 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@ USER_GROUP := $(shell id -u):$(shell id -g)
UPSTREAM_OWNER := $(shell scripts/git/upstream_owner.sh)
COMMIT := $(shell scripts/git/commit.sh)

BLACK_EXCLUDES := "/interfaces|/venv|/.venv"
ISORT_EXCLUDES := "--extend-skip=/interfaces --extend-skip=/venv --extends-skip=/.venv/"

ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell uname -s)
endif

.PHONY: isort-image
isort-image:
cd test/isort && docker image build . -t interuss/isort

.PHONY: format
format: isort-image
docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/code" -w /code pyfound/black:25.1.0 black --exclude=$(BLACK_EXCLUDES) .
docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/code" -w /code interuss/isort --profile black ${ISORT_EXCLUDES} .
format: image
docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/app" -w /app interuss/monitoring uv run ruff format
docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/app" -w /app interuss/monitoring uv run ruff check --fix
cd monitoring && make format
cd schemas && make format

Expand All @@ -29,13 +22,14 @@ lint: shell-lint python-lint
cd schemas && make lint

.PHONY: check-hygiene
check-hygiene: lint validate-uss-qualifier-docs
check-hygiene: image lint validate-uss-qualifier-docs
test/repo_hygiene/repo_hygiene.sh

.PHONY: python-lint
python-lint: isort-image
docker run --rm -v "$(CURDIR):/code" -w /code pyfound/black:25.1.0 black --check --exclude=$(BLACK_EXCLUDES) . || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)
docker run --rm -v "$(CURDIR):/code" -w /code interuss/isort --check-only --profile black ${ISORT_EXCLUDES} . || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)
python-lint: image

docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/app" -w /app interuss/monitoring uv run ruff format --check || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)
docker run --rm -u ${USER_GROUP} -v "$(CURDIR):/app" -w /app interuss/monitoring uv run ruff check || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)

.PHONY: validate-uss-qualifier-docs
validate-uss-qualifier-docs:
Expand Down
1 change: 0 additions & 1 deletion build/dev/extract_json_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import sys


with open(sys.argv[2], "r") as f:
try:
obj = json.load(f)
Expand Down
4 changes: 2 additions & 2 deletions introduction_to_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You may use [uv features to manage them](https://docs.astral.sh/uv/concepts/proj
* Update the requiered version in the [pyproject.toml](pyproject.toml) file
* Run `uv lock` to update the lock file.

This procedure also work for the small mini-projects for [isort](test/isort) and [repo_hygiene](test/repo_hygiene).
This procedure also work for the [repo_hygiene](test/repo_hygiene) mini project.

### Upgrade dependencies

Expand All @@ -67,4 +67,4 @@ You may also upgrade all packages with

* `uv lock --upgrade`

This procedure also work for the small mini-projects for [isort](test/isort) and [repo_hygiene](test/repo_hygiene).
This procedure also work for the [repo_hygiene](test/repo_hygiene) mini project.
1 change: 0 additions & 1 deletion monitoring/deployment_manager/actions/dss/v1/crdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import base64
import os

import cryptography.exceptions
import cryptography.hazmat.backends
Expand Down
2 changes: 0 additions & 2 deletions monitoring/deployment_manager/actions/k8s.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from kubernetes.client import V1IngressClass

from monitoring.deployment_manager.infrastructure import Context, deployment_action


Expand Down
18 changes: 6 additions & 12 deletions monitoring/deployment_manager/actions/test/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import monitoring.deployment_manager.deploylib.namespaces
import monitoring.deployment_manager.deploylib.systems
from monitoring.deployment_manager import deploylib
from monitoring.deployment_manager.deploylib import namespaces, systems
from monitoring.deployment_manager.infrastructure import Context, deployment_action
from monitoring.deployment_manager.systems.test import hello_world
from monitoring.monitorlib.delay import sleep
Expand All @@ -12,12 +10,8 @@ def deploy(context: Context) -> None:
namespace = hello_world.define_namespace(context.spec.test.v1.namespace)
resources = hello_world.define_resources()

active_namespace = deploylib.namespaces.upsert(
context.clients.core, context.log, namespace
)
deploylib.systems.upsert_resources(
resources, active_namespace, context.clients, context.log
)
active_namespace = namespaces.upsert(context.clients.core, context.log, namespace)
systems.upsert_resources(resources, active_namespace, context.clients, context.log)

context.log.msg(
"hello_world system deployment complete. Run `minikube tunnel` and then navigate to http://localhost in a browser to see the web content."
Expand All @@ -27,7 +21,7 @@ def deploy(context: Context) -> None:
@deployment_action("test/hello_world/destroy")
def destroy(context: Context) -> None:
"""Tear down the hello_world system"""
namespace = deploylib.namespaces.get(
namespace = namespaces.get(
context.clients.core,
context.log,
hello_world.define_namespace(context.spec.test.v1.namespace),
Expand All @@ -42,7 +36,7 @@ def destroy(context: Context) -> None:

resources = hello_world.define_resources()
resources.reverse()
existing_resources = deploylib.systems.get_resources(
existing_resources = systems.get_resources(
resources, namespace, context.clients, context.log, context.spec.cluster.name
)

Expand All @@ -53,7 +47,7 @@ def destroy(context: Context) -> None:
)
sleep(15, "destruction of hello_world system may take a few seconds")

deploylib.systems.delete_resources(
systems.delete_resources(
existing_resources, namespace, context.clients, context.log
)

Expand Down
2 changes: 1 addition & 1 deletion monitoring/deployment_manager/deploylib/crdb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_monitoring_user(
username = prefix + suffix

# Create a new password
r = random.Random()
random.Random()
password = "".join(
random.choice(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_+[]\\{}|;:",./<>?'
Expand Down
9 changes: 4 additions & 5 deletions monitoring/deployment_manager/deploylib/port_forwarding.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from http.client import HTTPConnection

import urllib3
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool, PoolManager

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from typing import Tuple

import kubernetes.stream
import requests
import urllib3
import urllib3.connection
from kubernetes.client import CoreV1Api
from requests.adapters import HTTPAdapter
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool, PoolManager

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


def _get_session_for_socket(sock, host: str, port: int) -> requests.Session:
Expand Down
31 changes: 14 additions & 17 deletions monitoring/deployment_manager/deploylib/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from kubernetes.client import V1Deployment, V1Ingress, V1Namespace, V1Service
from structlog import BoundLogger

import monitoring.deployment_manager.deploylib.deployments
import monitoring.deployment_manager.deploylib.ingresses
import monitoring.deployment_manager.deploylib.namespaces
import monitoring.deployment_manager.deploylib.services
from monitoring.deployment_manager import deploylib
from monitoring.deployment_manager.deploylib import (
deployments,
ingresses,
namespaces,
services,
)
from monitoring.deployment_manager.infrastructure import Clients


Expand All @@ -19,15 +20,13 @@ def upsert_resources(
) -> None:
for target_resource in target_resources:
if target_resource.__class__ == V1Deployment:
deploylib.deployments.upsert(clients.apps, log, namespace, target_resource)
deployments.upsert(clients.apps, log, namespace, target_resource)
elif target_resource.__class__ == V1Ingress:
deploylib.ingresses.upsert(
clients.networking, log, namespace, target_resource
)
ingresses.upsert(clients.networking, log, namespace, target_resource)
elif target_resource.__class__ == V1Namespace:
deploylib.namespaces.upsert(clients.core, log, target_resource)
namespaces.upsert(clients.core, log, target_resource)
elif target_resource.__class__ == V1Service:
deploylib.services.upsert(clients.core, log, namespace, target_resource)
services.upsert(clients.core, log, namespace, target_resource)
else:
raise NotImplementedError(
"Upserting {} is not yet supported".format(target_resource.__class__)
Expand All @@ -44,19 +43,17 @@ def get_resources(
existing_resources = []
for target_resource in target_resources:
if target_resource.__class__ == V1Deployment:
existing_resource = deploylib.deployments.get(
existing_resource = deployments.get(
clients.apps, log, namespace, target_resource
)
elif target_resource.__class__ == V1Ingress:
existing_resource = deploylib.ingresses.get(
existing_resource = ingresses.get(
clients.networking, log, namespace, target_resource
)
elif target_resource.__class__ == V1Namespace:
existing_resource = deploylib.namespaces.get(
clients.core, log, target_resource
)
existing_resource = namespaces.get(clients.core, log, target_resource)
elif target_resource.__class__ == V1Service:
existing_resource = deploylib.services.get(
existing_resource = services.get(
clients.core, log, namespace, target_resource
)
else:
Expand Down
2 changes: 1 addition & 1 deletion monitoring/loadtest/locust_files/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from locust import User
from uas_standards.astm.f3411.v19.constants import Scope

from monitoring.monitorlib import auth, infrastructure, rid_v1
from monitoring.monitorlib import auth, infrastructure


class DSSClient(infrastructure.UTMClientSession):
Expand Down
49 changes: 28 additions & 21 deletions monitoring/mock_uss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

monkey.patch_all()

from loguru import logger
from werkzeug.middleware.proxy_fix import ProxyFix
from loguru import logger # noqa E402
from werkzeug.middleware.proxy_fix import ProxyFix # noqa E402

from monitoring.mock_uss.server import MockUSS
from monitoring.mock_uss.server import MockUSS # noqa E402

SERVICE_GEOAWARENESS = "geoawareness"
SERVICE_RIDSP = "ridsp"
Expand Down Expand Up @@ -74,55 +74,62 @@ def require_config_value(config_key: str) -> None:
)


from monitoring.mock_uss import config, logging
from monitoring.mock_uss import routes as basic_routes
from monitoring.mock_uss import config # noqa E402
from monitoring.mock_uss import logging as logging # noqa E402
from monitoring.mock_uss import routes as basic_routes # noqa F401,F402

if SERVICE_GEOAWARENESS in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_GEOAWARENESS)
from monitoring.mock_uss import geoawareness
from monitoring.mock_uss.geoawareness import routes as geoawareness_routes
from monitoring.mock_uss import geoawareness as geoawareness
from monitoring.mock_uss.geoawareness import (
routes as geoawareness_routes, # noqa F401
)

if SERVICE_RIDSP in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_RIDSP)
from monitoring.mock_uss import ridsp
from monitoring.mock_uss.ridsp import routes as ridsp_routes
from monitoring.mock_uss import ridsp as ridsp
from monitoring.mock_uss.ridsp import routes as ridsp_routes # noqa F401

if SERVICE_RIDDP in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_RIDDP)
from monitoring.mock_uss import riddp
from monitoring.mock_uss.riddp import routes as riddp_routes
from monitoring.mock_uss import riddp as riddp
from monitoring.mock_uss.riddp import routes as riddp_routes # noqa F401

if SERVICE_SCDSC in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_SCDSC)
from monitoring.mock_uss.f3548v21 import routes_scd
from monitoring.mock_uss.scd_injection import routes as scd_injection_routes
from monitoring.mock_uss.f3548v21 import routes_scd as routes_scd
from monitoring.mock_uss.scd_injection import (
routes as scd_injection_routes, # noqa F401
)

if SERVICE_MESSAGESIGNING in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_MESSAGESIGNING)
from monitoring.mock_uss import msgsigning
from monitoring.mock_uss.msgsigning import routes as msgsigning_routes
from monitoring.mock_uss import msgsigning as msgsigning # noqa F401
from monitoring.mock_uss.msgsigning import routes as msgsigning_routes # noqa F401

if SERVICE_INTERACTION_LOGGING in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_INTERACTION_LOGGING)
from monitoring.mock_uss.interaction_logging import logger as interactions_logger
from monitoring.mock_uss.interaction_logging import routes_interactions_log
from monitoring.mock_uss.interaction_logging import logger as interactions_logger # noqa F401
from monitoring.mock_uss.interaction_logging import (
routes_interactions_log as routes_interactions_log,
)

logger.info("Interaction logging enabled")
else:
logger.info("Interaction logging disabled")

if SERVICE_TRACER in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_TRACER)
from monitoring.mock_uss import tracer
from monitoring.mock_uss.tracer import routes as tracer_routes
from monitoring.mock_uss import tracer as tracer
from monitoring.mock_uss.tracer import routes as tracer_routes # noqa F401

if SERVICE_VERSIONING in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_VERSIONING)
from monitoring.mock_uss.versioning import routes as versioning_routes
from monitoring.mock_uss.versioning import routes as versioning_routes # noqa F401

if SERVICE_FLIGHT_PLANNING in webapp.config[config.KEY_SERVICES]:
enabled_services.add(SERVICE_FLIGHT_PLANNING)
from monitoring.mock_uss.flight_planning import routes as flight_planning_routes
from monitoring.mock_uss.flight_planning import routes as flight_planning_routes # noqa F401

msg = (
"################################################################################\n"
Expand Down
9 changes: 5 additions & 4 deletions monitoring/mock_uss/f3548v21/flight_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def check_for_disallowed_conflicts(
log: If specified, call this function to report information about conflict evaluation.
"""
if log is None:
log = lambda msg: None

def log(msg):
return None

if new_op_intent.reference.state not in (
scd_api.OperationalIntentState.Accepted,
Expand All @@ -135,9 +137,8 @@ def check_for_disallowed_conflicts(
f"intersection with {op_intent.reference.id} not considered: intersection with lower-priority operational intents"
)
continue
if (
new_priority == old_priority
and locality.allows_same_priority_intersections(old_priority)
if new_priority == old_priority and locality.allows_same_priority_intersections(
old_priority
):
log(
f"intersection with {op_intent.reference.id} not considered: intersection with same-priority operational intents (if allowed)"
Expand Down
1 change: 0 additions & 1 deletion monitoring/mock_uss/f3548v21/routes_scd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
ErrorReport,
ErrorResponse,
GetOperationalIntentDetailsResponse,
GetOperationalIntentTelemetryResponse,
OperationalIntentState,
)

Expand Down
1 change: 0 additions & 1 deletion monitoring/mock_uss/flight_planning/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from loguru import logger
from uas_standards.interuss.automated_testing.flight_planning.v1 import api
from uas_standards.interuss.automated_testing.flight_planning.v1.constants import Scope
from uas_standards.interuss.automated_testing.scd.v1 import api as scd_api

from monitoring.mock_uss import require_config_value, webapp
from monitoring.mock_uss.auth import requires_scope
Expand Down
1 change: 0 additions & 1 deletion monitoring/mock_uss/flights/planning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from datetime import UTC, datetime
from typing import Callable, Optional

Expand Down
6 changes: 3 additions & 3 deletions monitoring/mock_uss/geoawareness/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ def check_geozones(req: GeozonesCheckRequest) -> List[GeozonesCheckResultGeozone
for j, (source_id, source) in enumerate(sources.items()):
if source.state != GeozoneSourceResponseResult.Ready:
logger.debug(
f" {j+1}. Source {source_id} is not ready ({source.state}). Skip."
f" {j + 1}. Source {source_id} is not ready ({source.state}). Skip."
)
continue

fmt = source.definition.https_source.format
if fmt == GeozoneHttpsSourceFormat.ED_269:
logger.debug(f" {j+1}. ED269 source {source_id} ready.")
logger.debug(f" {j + 1}. ED269 source {source_id} ready.")
result = combine_results(
result, evaluate_source(source, check.filterSets)
)
else:
logger.debug(
f" {j+1}. Source {source_id} not in supported format {fmt}. Skip."
f" {j + 1}. Source {source_id} not in supported format {fmt}. Skip."
)

results[i] = result
Expand Down
Loading
Loading