Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 54e389e

Browse files
authored
make lint now checks for format (#656)
This enables `make lint` to also run black but without persisting the changes. This will hopefully allow developers to more easily detect if their changes are not compliant with the linter settings. This also removes the `make format` call from CI, which didn't actually fail if linter issues were found. Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 9fab905 commit 54e389e

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ jobs:
4747
- name: Run linting
4848
run: make lint
4949

50-
- name: Run formatting
51-
run: make format
52-
5350
- name: Run tests
5451
run: make test
5552

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ format:
1919
poetry run ruff check --fix .
2020

2121
lint:
22+
poetry run black --check .
2223
poetry run ruff check .
2324

2425
test:

src/codegate/api/v1.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ async def create_workspace(request: v1_models.CreateWorkspaceRequest) -> v1_mode
6363
except AlreadyExistsError:
6464
raise HTTPException(status_code=409, detail="Workspace already exists")
6565
except ValidationError:
66-
raise HTTPException(status_code=400,
67-
detail=("Invalid workspace name. "
68-
"Please use only alphanumeric characters and dashes"))
66+
raise HTTPException(
67+
status_code=400,
68+
detail=(
69+
"Invalid workspace name. " "Please use only alphanumeric characters and dashes"
70+
),
71+
)
6972
except Exception:
7073
raise HTTPException(status_code=500, detail="Internal server error")
7174

src/codegate/db/connection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
alert_queue = asyncio.Queue()
3131
fim_cache = FimCache()
3232

33+
3334
class AlreadyExistsError(Exception):
3435
pass
3536

37+
3638
class DbCodeGate:
3739
_instance = None
3840

@@ -266,7 +268,8 @@ async def add_workspace(self, workspace_name: str) -> Optional[Workspace]:
266268

267269
try:
268270
added_workspace = await self._execute_update_pydantic_model(
269-
workspace, sql, should_raise=True)
271+
workspace, sql, should_raise=True
272+
)
270273
except IntegrityError as e:
271274
logger.debug(f"Exception type: {type(e)}")
272275
raise AlreadyExistsError(f"Workspace {workspace_name} already exists.")
@@ -317,8 +320,11 @@ async def _execute_select_pydantic_model(
317320
return None
318321

319322
async def _exec_select_conditions_to_pydantic(
320-
self, model_type: Type[BaseModel], sql_command: TextClause, conditions: dict,
321-
should_raise: bool = False
323+
self,
324+
model_type: Type[BaseModel],
325+
sql_command: TextClause,
326+
conditions: dict,
327+
should_raise: bool = False,
322328
) -> Optional[List[BaseModel]]:
323329
async with self._async_db_engine.begin() as conn:
324330
try:
@@ -397,7 +403,8 @@ async def get_workspace_by_name(self, name: str) -> List[Workspace]:
397403
)
398404
conditions = {"name": name}
399405
workspaces = await self._exec_select_conditions_to_pydantic(
400-
Workspace, sql, conditions, should_raise=True)
406+
Workspace, sql, conditions, should_raise=True
407+
)
401408
return workspaces[0] if workspaces else None
402409

403410
async def get_sessions(self) -> List[Session]:

src/codegate/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ def generate_openapi():
112112

113113
# Convert the schema to JSON string for easier handling or storage
114114
openapi_json = json.dumps(openapi_schema, indent=2)
115-
print(openapi_json)
115+
print(openapi_json)

src/codegate/workspaces/crud.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
class WorkspaceCrudError(Exception):
99
pass
1010

11+
1112
class WorkspaceDoesNotExistError(WorkspaceCrudError):
1213
pass
1314

15+
1416
class WorkspaceAlreadyActiveError(WorkspaceCrudError):
1517
pass
1618

19+
1720
class WorkspaceCrud:
1821

1922
def __init__(self):
@@ -30,7 +33,7 @@ async def add_workspace(self, new_workspace_name: str) -> Workspace:
3033
workspace_created = await db_recorder.add_workspace(new_workspace_name)
3134
return workspace_created
3235

33-
async def get_workspaces(self)-> List[WorkspaceActive]:
36+
async def get_workspaces(self) -> List[WorkspaceActive]:
3437
"""
3538
Get all workspaces
3639
"""
@@ -60,8 +63,7 @@ async def _is_workspace_active(
6063
raise RuntimeError("Something went wrong. No active session found.")
6164

6265
session = sessions[0]
63-
return (session.active_workspace_id == selected_workspace.id,
64-
session, selected_workspace)
66+
return (session.active_workspace_id == selected_workspace.id, session, selected_workspace)
6567

6668
async def activate_workspace(self, workspace_name: str):
6769
"""

tests/pipeline/workspace/test_workspace.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ async def test_add_workspaces(args, existing_workspaces, expected_message):
7777
workspace_commands._db_reader = mock_db_reader
7878

7979
# We'll also patch DbRecorder to ensure no real DB operations happen
80-
with patch(
81-
"codegate.workspaces.crud.WorkspaceCrud", autospec=True
82-
) as mock_recorder_cls:
80+
with patch("codegate.workspaces.crud.WorkspaceCrud", autospec=True) as mock_recorder_cls:
8381
mock_recorder = mock_recorder_cls.return_value
8482
workspace_commands.workspace_crud = mock_recorder
8583
mock_recorder.add_workspace = AsyncMock()
@@ -115,9 +113,7 @@ async def test_parse_execute_cmd(
115113
"""
116114
workspace_commands = Workspace()
117115

118-
with patch.object(
119-
workspace_commands, "run", return_value=mocked_execute_response
120-
) as mock_run:
116+
with patch.object(workspace_commands, "run", return_value=mocked_execute_response) as mock_run:
121117
result = await workspace_commands.exec(user_message)
122118
assert result == mocked_execute_response
123119

tests/test_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_health_check(test_client: TestClient) -> None:
8181
assert response.status_code == 200
8282
assert response.json() == {"status": "healthy"}
8383

84+
8485
@patch("codegate.api.dashboard.dashboard.fetch_latest_version", return_value="foo")
8586
def test_version_endpoint(mock_fetch_latest_version, test_client: TestClient) -> None:
8687
"""Test the version endpoint."""
@@ -89,11 +90,12 @@ def test_version_endpoint(mock_fetch_latest_version, test_client: TestClient) ->
8990

9091
response_data = response.json()
9192

92-
assert response_data["current_version"] == __version__.lstrip('v')
93+
assert response_data["current_version"] == __version__.lstrip("v")
9394
assert response_data["latest_version"] == "foo"
9495
assert isinstance(response_data["is_latest"], bool)
9596
assert response_data["is_latest"] is False
9697

98+
9799
@patch("codegate.pipeline.secrets.manager.SecretsManager")
98100
@patch("codegate.server.ProviderRegistry")
99101
def test_provider_registration(mock_registry, mock_secrets_mgr, mock_pipeline_factory) -> None:

0 commit comments

Comments
 (0)