Skip to content

Commit 324fa25

Browse files
authored
Merge pull request #2928 from Agenta-AI/ci/add-check-python
[CI] Add `ruff` checks
2 parents 37feb58 + a2ce3d1 commit 324fa25

File tree

243 files changed

+1419
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+1419
-942
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 02 - check python formatting
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- 'api/**'
10+
- 'sdk/**'
11+
workflow_dispatch:
12+
13+
jobs:
14+
ruff:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install Ruff
25+
run: pip install ruff==0.14.0
26+
27+
- name: Run Ruff formatting check
28+
run: ruff format --check api sdk
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 03 - check python linting
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- 'api/**'
10+
- 'sdk/**'
11+
workflow_dispatch:
12+
13+
jobs:
14+
ruff:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install Ruff
25+
run: pip install ruff==0.14.0
26+
27+
- name: Run Ruff linting check
28+
run: ruff check api sdk

api/ee/databases/postgres/migrations/core/data_migrations/workspaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def create_default_project_for_workspaces(session: Connection):
5656
for workspace in workspaces:
5757
# Create a new default project for each workspace
5858
get_or_create_workspace_default_project(
59-
session=session, workspace=workspace # type: ignore
59+
session=session,
60+
workspace=workspace, # type: ignore
6061
)
6162

6263
# Commit the changes for the current batch

api/ee/databases/postgres/migrations/core/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
7373

7474
async with engine.connect() as connection:
7575
try:
76-
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
76+
result = await connection.execute(
77+
text("SELECT version_num FROM alembic_version")
78+
) # type: ignore
7779
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
7880
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
7981
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
@@ -83,9 +85,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
8385
return "alembic_version"
8486

8587
migration_heads = [row[0] for row in result.fetchall()]
86-
assert (
87-
len(migration_heads) == 1
88-
), "There can only be one migration head stored in the database."
88+
assert len(migration_heads) == 1, (
89+
"There can only be one migration head stored in the database."
90+
)
8991
return migration_heads[0]
9092

9193

api/ee/databases/postgres/migrations/tracing/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
6666

6767
async with engine.connect() as connection:
6868
try:
69-
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
69+
result = await connection.execute(
70+
text("SELECT version_num FROM alembic_version")
71+
) # type: ignore
7072
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
7173
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
7274
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
@@ -76,9 +78,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
7678
return "alembic_version"
7779

7880
migration_heads = [row[0] for row in result.fetchall()]
79-
assert (
80-
len(migration_heads) == 1
81-
), "There can only be one migration head stored in the database."
81+
assert len(migration_heads) == 1, (
82+
"There can only be one migration head stored in the database."
83+
)
8284
return migration_heads[0]
8385

8486

api/ee/src/apis/fastapi/billing/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
stripe.api_key = environ.get("STRIPE_API_KEY")
3737

38-
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xff:02x}" for ele in range(40, -1, -8))
38+
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xFF:02x}" for ele in range(40, -1, -8))
3939
STRIPE_WEBHOOK_SECRET = environ.get("STRIPE_WEBHOOK_SECRET")
4040
STRIPE_TARGET = environ.get("STRIPE_TARGET") or MAC_ADDRESS
4141
AGENTA_PRICING = loads(environ.get("AGENTA_PRICING") or "{}")

api/ee/src/core/subscriptions/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
stripe.api_key = environ.get("STRIPE_SECRET_KEY")
2727

28-
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xff:02x}" for ele in range(40, -1, -8))
28+
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xFF:02x}" for ele in range(40, -1, -8))
2929
STRIPE_TARGET = environ.get("STRIPE_TARGET") or MAC_ADDRESS
3030
AGENTA_PRICING = loads(environ.get("AGENTA_PRICING") or "{}")
3131

api/ee/src/services/db_manager_ee.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,7 @@ async def remove_user_from_workspace(
645645
project = await db_manager.get_project_by_id(project_id=project_id)
646646

647647
async with engine.core_session() as session:
648-
if (
649-
not user
650-
): # User is an invited user who has not yet created an account and therefore does not have a user object
648+
if not user: # User is an invited user who has not yet created an account and therefore does not have a user object
651649
pass
652650
else:
653651
# Ensure that a user can not remove the owner of the workspace

api/ee/src/services/workspace_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ async def accept_workspace_invitation(
317317

318318
invitation = await check_valid_invitation(project_id, user.email, token)
319319
if invitation is not None:
320-
assert (
321-
invitation.role is not None
322-
), "Invitation does not have any workspace role"
320+
assert invitation.role is not None, (
321+
"Invitation does not have any workspace role"
322+
)
323323
await db_manager_ee.add_user_to_workspace_and_org(
324324
organization, workspace, user, project_id, invitation.role
325325
)

api/ee/src/utils/entitlements.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ class EntitlementsException(Exception):
3636
pass
3737

3838

39-
NOT_ENTITLED_RESPONSE: Callable[
40-
[Tracker], JSONResponse
41-
] = lambda tracker=None: JSONResponse(
42-
status_code=403,
43-
content={
44-
"detail": (
45-
"You have reached your monthly quota limit. Please upgrade your plan to continue."
46-
if tracker == Tracker.COUNTERS
47-
else (
48-
"You have reached your quota limit. Please upgrade your plan to continue."
49-
if tracker == Tracker.GAUGES
39+
NOT_ENTITLED_RESPONSE: Callable[[Tracker], JSONResponse] = (
40+
lambda tracker=None: JSONResponse(
41+
status_code=403,
42+
content={
43+
"detail": (
44+
"You have reached your monthly quota limit. Please upgrade your plan to continue."
45+
if tracker == Tracker.COUNTERS
5046
else (
51-
"You do not have access to this feature. Please upgrade your plan to continue."
52-
if tracker == Tracker.FLAGS
53-
else "You do not have access to this feature."
47+
"You have reached your quota limit. Please upgrade your plan to continue."
48+
if tracker == Tracker.GAUGES
49+
else (
50+
"You do not have access to this feature. Please upgrade your plan to continue."
51+
if tracker == Tracker.FLAGS
52+
else "You do not have access to this feature."
53+
)
5454
)
55-
)
56-
),
57-
},
55+
),
56+
},
57+
)
5858
)
5959

6060

@@ -163,7 +163,7 @@ async def check_entitlements(
163163

164164
# TODO: remove this line
165165
log.info(
166-
f"adjusting: {organization_id} | {(('0' if (meter.month != 0 and meter.month < 10) else '') + str(meter.month)) if meter.month != 0 else ' '}.{meter.year if meter.year else ' '} | {'allow' if check else 'deny '} | {meter.key}: {meter.value-meter.synced} [{meter.value}]"
166+
f"adjusting: {organization_id} | {(('0' if (meter.month != 0 and meter.month < 10) else '') + str(meter.month)) if meter.month != 0 else ' '}.{meter.year if meter.year else ' '} | {'allow' if check else 'deny '} | {meter.key}: {meter.value - meter.synced} [{meter.value}]"
167167
)
168168

169169
return check is True, meter, _

0 commit comments

Comments
 (0)