diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa071848b..57fe4e0ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: - id: fix-byte-order-marker - id: trailing-whitespace - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.2.0 hooks: - id: black files: '^backend/' @@ -78,7 +78,7 @@ repos: - 'prettier@^3.0.3' - 'prettier-plugin-tailwindcss@^0.5.5' - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.4 + rev: v1.5.5 hooks: - id: insert-license name: Insert license headers (shell-style comments) diff --git a/backend/capellacollab/core/authentication/injectables.py b/backend/capellacollab/core/authentication/injectables.py index 8bee527bc..75705bb05 100644 --- a/backend/capellacollab/core/authentication/injectables.py +++ b/backend/capellacollab/core/authentication/injectables.py @@ -136,8 +136,9 @@ def __init__( self, required_role: projects_users_models.ProjectUserRole, verify: bool = True, - required_permission: projects_users_models.ProjectUserPermission - | None = None, + required_permission: ( + projects_users_models.ProjectUserPermission | None + ) = None, ): self.required_role = required_role self.verify = verify diff --git a/backend/capellacollab/events/models.py b/backend/capellacollab/events/models.py index 23b91da1a..65722572c 100644 --- a/backend/capellacollab/events/models.py +++ b/backend/capellacollab/events/models.py @@ -77,9 +77,9 @@ class DatabaseUserHistoryEvent(database.Base): sa.ForeignKey("projects.id"), init=False, ) - project: orm.Mapped[ - projects_models.DatabaseProject | None - ] = orm.relationship(default=None, foreign_keys=[project_id]) + project: orm.Mapped[projects_models.DatabaseProject | None] = ( + orm.relationship(default=None, foreign_keys=[project_id]) + ) execution_time: orm.Mapped[datetime.datetime] = orm.mapped_column( default=datetime.datetime.now(datetime.UTC) diff --git a/backend/capellacollab/projects/toolmodels/backups/models.py b/backend/capellacollab/projects/toolmodels/backups/models.py index 4de74fbad..a0375ce43 100644 --- a/backend/capellacollab/projects/toolmodels/backups/models.py +++ b/backend/capellacollab/projects/toolmodels/backups/models.py @@ -78,11 +78,11 @@ class DatabaseBackup(database.Base): ) model: orm.Mapped["DatabaseToolModel"] = orm.relationship() - runs: orm.Mapped[ - list["runs_models.DatabasePipelineRun"] - ] = orm.relationship( - "DatabasePipelineRun", - back_populates="pipeline", - cascade="all, delete-orphan", - default_factory=list, + runs: orm.Mapped[list["runs_models.DatabasePipelineRun"]] = ( + orm.relationship( + "DatabasePipelineRun", + back_populates="pipeline", + cascade="all, delete-orphan", + default_factory=list, + ) ) diff --git a/backend/capellacollab/projects/toolmodels/backups/runs/models.py b/backend/capellacollab/projects/toolmodels/backups/runs/models.py index 0c9aad091..9c4ede3cf 100644 --- a/backend/capellacollab/projects/toolmodels/backups/runs/models.py +++ b/backend/capellacollab/projects/toolmodels/backups/runs/models.py @@ -55,9 +55,9 @@ class DatabasePipelineRun(Base): end_time: orm.Mapped[datetime.datetime | None] = orm.mapped_column( default=None ) - logs_last_fetched_timestamp: orm.Mapped[ - datetime.datetime | None - ] = orm.mapped_column(default=None) + logs_last_fetched_timestamp: orm.Mapped[datetime.datetime | None] = ( + orm.mapped_column(default=None) + ) class PipelineRun(pydantic.BaseModel): diff --git a/backend/capellacollab/projects/toolmodels/models.py b/backend/capellacollab/projects/toolmodels/models.py index 247734839..f5f27ad16 100644 --- a/backend/capellacollab/projects/toolmodels/models.py +++ b/backend/capellacollab/projects/toolmodels/models.py @@ -112,13 +112,13 @@ class DatabaseToolModel(database.Base): default_factory=list, back_populates="model" ) - restrictions: orm.Mapped[ - DatabaseToolModelRestrictions | None - ] = orm.relationship( - back_populates="model", - uselist=False, - cascade="delete", - default=None, + restrictions: orm.Mapped[DatabaseToolModelRestrictions | None] = ( + orm.relationship( + back_populates="model", + uselist=False, + cascade="delete", + default=None, + ) ) diff --git a/backend/capellacollab/projects/toolmodels/modelsources/git/github/handler.py b/backend/capellacollab/projects/toolmodels/modelsources/git/github/handler.py index 0688fa544..898940bd3 100644 --- a/backend/capellacollab/projects/toolmodels/modelsources/git/github/handler.py +++ b/backend/capellacollab/projects/toolmodels/modelsources/git/github/handler.py @@ -141,9 +141,11 @@ def get_last_updated_for_file_path( ) -> datetime.datetime | None: response = requests.get( f"{self.git_instance.api_url}/repos/{project_id}/commits?path={file_path}&sha={revision or self.git_model.revision}", - headers=self.__get_headers(self.git_model.password) - if self.git_model.password - else None, + headers=( + self.__get_headers(self.git_model.password) + if self.git_model.password + else None + ), timeout=config["requests"]["timeout"], ) response.raise_for_status() diff --git a/backend/capellacollab/sessions/hooks/t4c.py b/backend/capellacollab/sessions/hooks/t4c.py index 801ab5710..b3d71b37a 100644 --- a/backend/capellacollab/sessions/hooks/t4c.py +++ b/backend/capellacollab/sessions/hooks/t4c.py @@ -61,9 +61,11 @@ def configuration_hook( # type: ignore { "repository": repository.name, "protocol": repository.instance.protocol, - "port": repository.instance.http_port - if repository.instance.protocol == "ws" - else repository.instance.port, + "port": ( + repository.instance.http_port + if repository.instance.protocol == "ws" + else repository.instance.port + ), "host": repository.instance.host, "instance": repository.instance.name, } diff --git a/backend/capellacollab/sessions/models.py b/backend/capellacollab/sessions/models.py index 8d934a3a9..0ed530048 100644 --- a/backend/capellacollab/sessions/models.py +++ b/backend/capellacollab/sessions/models.py @@ -121,9 +121,9 @@ class DatabaseSession(database.Base): project_id: orm.Mapped[str | None] = orm.mapped_column( sa.ForeignKey("projects.id"), init=False ) - project: orm.Mapped[ - projects_models.DatabaseProject | None - ] = orm.relationship() + project: orm.Mapped[projects_models.DatabaseProject | None] = ( + orm.relationship() + ) environment: orm.Mapped[dict[str, str] | None] diff --git a/backend/capellacollab/sessions/operators/k8s.py b/backend/capellacollab/sessions/operators/k8s.py index 1a21e6b9f..20292005c 100644 --- a/backend/capellacollab/sessions/operators/k8s.py +++ b/backend/capellacollab/sessions/operators/k8s.py @@ -273,12 +273,12 @@ def _get_pod_state(self, label_selector: str): log.debug("Received k8s pod: %s", pod_name) log.debug("Fetching k8s events for pod: %s", pod_name) - events: list[ - client.CoreV1Event - ] = self.v1_core.list_namespaced_event( - namespace=namespace, - field_selector=f"involvedObject.name={pod_name}", - ).items + events: list[client.CoreV1Event] = ( + self.v1_core.list_namespaced_event( + namespace=namespace, + field_selector=f"involvedObject.name={pod_name}", + ).items + ) events = list(filter(self._is_non_promtail_event, events)) if events: diff --git a/backend/capellacollab/tools/models.py b/backend/capellacollab/tools/models.py index 65e436211..7e791833a 100644 --- a/backend/capellacollab/tools/models.py +++ b/backend/capellacollab/tools/models.py @@ -31,12 +31,12 @@ class DatabaseTool(database.Base): default=None ) - integrations: orm.Mapped[ - DatabaseToolIntegrations | None - ] = orm.relationship( - default=None, - back_populates="tool", - uselist=False, + integrations: orm.Mapped[DatabaseToolIntegrations | None] = ( + orm.relationship( + default=None, + back_populates="tool", + uselist=False, + ) ) versions: orm.Mapped[list[DatabaseVersion]] = orm.relationship( diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index cba082daf..92652c3e9 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -94,9 +94,9 @@ def fixture_admin( def get_mock_own_user(): return admin - app.dependency_overrides[ - users_injectables.get_own_user - ] = get_mock_own_user + app.dependency_overrides[users_injectables.get_own_user] = ( + get_mock_own_user + ) yield admin del app.dependency_overrides[users_injectables.get_own_user] @@ -110,9 +110,9 @@ def fixture_user( def get_mock_own_user(): return user - app.dependency_overrides[ - users_injectables.get_own_user - ] = get_mock_own_user + app.dependency_overrides[users_injectables.get_own_user] = ( + get_mock_own_user + ) yield user del app.dependency_overrides[users_injectables.get_own_user] diff --git a/backend/tests/projects/test_projects_routes.py b/backend/tests/projects/test_projects_routes.py index 0fd72292c..12148dfc5 100644 --- a/backend/tests/projects/test_projects_routes.py +++ b/backend/tests/projects/test_projects_routes.py @@ -237,9 +237,9 @@ def fixture_override_dependency(mock_project): def override_get_existing_project(): return mock_project - app.dependency_overrides[ - projects_injectables.get_existing_project - ] = override_get_existing_project + app.dependency_overrides[projects_injectables.get_existing_project] = ( + override_get_existing_project + ) yield del app.dependency_overrides[projects_injectables.get_existing_project] @@ -257,13 +257,16 @@ def test_delete_pipeline_called_when_archiving_project( users_crud.create_user(db, executor_name, users_models.Role.ADMIN) mock_project.models = [mock_model] - with mock.patch( - "capellacollab.projects.routes.backups_core.delete_pipeline", - autospec=True, - ) as mock_delete_pipeline, mock.patch( - "capellacollab.projects.routes.backups_crud.get_pipelines_for_tool_model", - autospec=True, - ) as mock_get_pipelines_for_tool_model: + with ( + mock.patch( + "capellacollab.projects.routes.backups_core.delete_pipeline", + autospec=True, + ) as mock_delete_pipeline, + mock.patch( + "capellacollab.projects.routes.backups_crud.get_pipelines_for_tool_model", + autospec=True, + ) as mock_get_pipelines_for_tool_model, + ): mock_get_pipelines_for_tool_model.return_value = [mock_pipeline] response = client.patch( diff --git a/backend/tests/projects/toolmodels/pipelines/pipeline-runs/test_pipeline_runs.py b/backend/tests/projects/toolmodels/pipelines/pipeline-runs/test_pipeline_runs.py index 1d0e84b1a..e630d2267 100644 --- a/backend/tests/projects/toolmodels/pipelines/pipeline-runs/test_pipeline_runs.py +++ b/backend/tests/projects/toolmodels/pipelines/pipeline-runs/test_pipeline_runs.py @@ -177,9 +177,9 @@ def fixture_override_get_existing_pipeline_run_dependency( def get_mock_existing_pipeline_run() -> runs_models.DatabasePipelineRun: return mock_pipeline_run - app.dependency_overrides[ - runs_injectables.get_existing_pipeline_run - ] = get_mock_existing_pipeline_run + app.dependency_overrides[runs_injectables.get_existing_pipeline_run] = ( + get_mock_existing_pipeline_run + ) yield diff --git a/backend/tests/projects/toolmodels/test_toolmodel_routes.py b/backend/tests/projects/toolmodels/test_toolmodel_routes.py index 56fc196f0..b68efd18e 100644 --- a/backend/tests/projects/toolmodels/test_toolmodel_routes.py +++ b/backend/tests/projects/toolmodels/test_toolmodel_routes.py @@ -27,9 +27,9 @@ def fixture_override_dependency(): mock_model.slug = "any-slug" mock_model.tool = mock.Mock(name="tool") - app.dependency_overrides[ - projects_injectables.get_existing_project - ] = lambda: mock_project + app.dependency_overrides[projects_injectables.get_existing_project] = ( + lambda: mock_project + ) app.dependency_overrides[ toolmodels_injectables.get_existing_capella_model ] = lambda: mock_model diff --git a/backend/tests/sessions/test_session_hooks.py b/backend/tests/sessions/test_session_hooks.py index 5cdae6872..eaab7ba12 100644 --- a/backend/tests/sessions/test_session_hooks.py +++ b/backend/tests/sessions/test_session_hooks.py @@ -99,9 +99,9 @@ def fixture_mockoperator() -> t.Generator[MockOperator, None, None]: def get_mock_operator(): return mock - __main__.app.dependency_overrides[ - operators.get_operator - ] = get_mock_operator + __main__.app.dependency_overrides[operators.get_operator] = ( + get_mock_operator + ) yield mock del __main__.app.dependency_overrides[operators.get_operator] diff --git a/backend/tests/sessions/test_sessions_routes.py b/backend/tests/sessions/test_sessions_routes.py index 2ed069f6e..2ec75812d 100644 --- a/backend/tests/sessions/test_sessions_routes.py +++ b/backend/tests/sessions/test_sessions_routes.py @@ -161,9 +161,9 @@ def fixture_user( def get_mock_own_user(): return user - app.dependency_overrides[ - users_injectables.get_own_user - ] = get_mock_own_user + app.dependency_overrides[users_injectables.get_own_user] = ( + get_mock_own_user + ) yield user del app.dependency_overrides[users_injectables.get_own_user] diff --git a/backend/tests/settings/test_alerts.py b/backend/tests/settings/test_alerts.py index 8a88f33c5..eb191b4cf 100644 --- a/backend/tests/settings/test_alerts.py +++ b/backend/tests/settings/test_alerts.py @@ -63,9 +63,9 @@ def test_create_alert2( assert response.status_code == 200 - notices: abc.Sequence[ - notices_models.DatabaseNotice - ] = notices_crud.get_notices(db) + notices: abc.Sequence[notices_models.DatabaseNotice] = ( + notices_crud.get_notices(db) + ) assert len(notices) == 1 assert notices[0].title == "test" assert notices[0].message == "test" diff --git a/backend/tests/settings/test_configuration.py b/backend/tests/settings/test_configuration.py index b5114d326..7bb04767c 100644 --- a/backend/tests/settings/test_configuration.py +++ b/backend/tests/settings/test_configuration.py @@ -110,9 +110,9 @@ def test_metadata_is_updated( def get_mock_own_user(): return admin - app.dependency_overrides[ - users_injectables.get_own_user - ] = get_mock_own_user + app.dependency_overrides[users_injectables.get_own_user] = ( + get_mock_own_user + ) response = client.put( "/api/v1/settings/configurations/global", diff --git a/backend/tests/test_event_creation.py b/backend/tests/test_event_creation.py index dd6a69299..9934304c7 100644 --- a/backend/tests/test_event_creation.py +++ b/backend/tests/test_event_creation.py @@ -20,9 +20,9 @@ def test_create_admin_user_by_system(db): db, config.config["initial"]["admin"] ) - events: list[ - events_models.DatabaseUserHistoryEvent - ] = get_events_by_user_id(db, user.id) + events: list[events_models.DatabaseUserHistoryEvent] = ( + get_events_by_user_id(db, user.id) + ) assert len(events) == 1 diff --git a/backend/tests/users/conftest.py b/backend/tests/users/conftest.py index 5f65b953e..60e5a8c2e 100644 --- a/backend/tests/users/conftest.py +++ b/backend/tests/users/conftest.py @@ -18,8 +18,8 @@ def fixture_unauthenticated_user(db): def get_mock_own_user(): return user - app.dependency_overrides[ - users_injectables.get_own_user - ] = get_mock_own_user + app.dependency_overrides[users_injectables.get_own_user] = ( + get_mock_own_user + ) yield user del app.dependency_overrides[users_injectables.get_own_user]