Skip to content

Commit fa2ef0f

Browse files
authored
[lint] replaces black formatting with ruff (#14132)
`ruff` is faster than `black` when formatting Python `files`, so this change replaces the formatting checks for our files with calls to `ruff` instead of `black`, and runs `ruff format` on all files that would cause those checks to fail.
1 parent 24525ad commit fa2ef0f

File tree

195 files changed

+2872
-3299
lines changed

Some content is hidden

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

195 files changed

+2872
-3299
lines changed

.pre-commit-config.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ repos:
99
language: system
1010
types: [python]
1111
require_serial: true
12+
- id: ruff-format
13+
name: ruff-format
14+
entry: ruff format
15+
language: system
16+
types: [python]
17+
require_serial: true
1218
- id: pyright
1319
name: pyright
1420
entry: pyright
@@ -23,11 +29,6 @@ repos:
2329
hooks:
2430
- id: end-of-file-fixer
2531
- id: trailing-whitespace
26-
- repo: https://github.com/psf/black
27-
rev: 22.3.0
28-
hooks:
29-
- id: black
30-
language_version: python3
3132
- repo: https://github.com/thibaudcolas/curlylint
3233
rev: v0.13.1
3334
hooks:

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ check-all: check-hail check-services
4141
check-hail-fast:
4242
ruff check hail/python/hail
4343
ruff check hail/python/hailtop
44+
ruff format hail --check
4445
$(PYTHON) -m pyright hail/python/hailtop
45-
$(PYTHON) -m black hail --check --diff
4646

4747
.PHONY: pylint-hailtop
4848
pylint-hailtop:
@@ -62,8 +62,8 @@ pylint-%:
6262
.PHONY: check-%-fast
6363
check-%-fast:
6464
ruff check $*
65+
ruff format $* --check
6566
$(PYTHON) -m pyright $*
66-
$(PYTHON) -m black $* --check --diff
6767
curlylint $*
6868
cd $* && bash ../check-sql.sh
6969

auth/auth/auth.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ async def _insert(tx):
164164
return False
165165

166166
await tx.execute_insertone(
167-
'''
167+
"""
168168
INSERT INTO users (state, username, login_id, is_developer, is_service_account, hail_identity, hail_credentials_secret_name)
169169
VALUES (%s, %s, %s, %s, %s, %s, %s);
170-
''',
170+
""",
171171
(
172172
'creating',
173173
username,
@@ -482,9 +482,11 @@ async def rest_login(request: web.Request) -> web.Response:
482482
flow_data['callback_uri'] = callback_uri
483483

484484
# keeping authorization_url and state for backwards compatibility
485-
return json_response(
486-
{'flow': flow_data, 'authorization_url': flow_data['authorization_url'], 'state': flow_data['state']}
487-
)
485+
return json_response({
486+
'flow': flow_data,
487+
'authorization_url': flow_data['authorization_url'],
488+
'state': flow_data['state'],
489+
})
488490

489491

490492
@routes.get('/api/v1alpha/oauth2-client')
@@ -511,10 +513,10 @@ async def post_create_role(request: web.Request, _) -> NoReturn:
511513
name = str(post['name'])
512514

513515
role_id = await db.execute_insertone(
514-
'''
516+
"""
515517
INSERT INTO `roles` (`name`)
516518
VALUES (%s);
517-
''',
519+
""",
518520
(name),
519521
)
520522

@@ -564,10 +566,10 @@ async def rest_get_users(request: web.Request, userdata: UserData) -> web.Respon
564566
raise web.HTTPUnauthorized()
565567

566568
db = request.app[AppKeys.DB]
567-
_query = '''
569+
_query = """
568570
SELECT id, username, login_id, state, is_developer, is_service_account, hail_identity
569571
FROM users;
570-
'''
572+
"""
571573
users = [x async for x in db.select_and_fetchall(_query)]
572574
return json_response(users)
573575

@@ -579,10 +581,10 @@ async def rest_get_user(request: web.Request, _) -> web.Response:
579581
username = request.match_info['user']
580582

581583
user = await db.select_and_fetchone(
582-
'''
584+
"""
583585
SELECT id, username, login_id, state, is_developer, is_service_account, hail_identity FROM users
584586
WHERE username = %s;
585-
''',
587+
""",
586588
(username,),
587589
)
588590
if user is None:
@@ -599,11 +601,11 @@ async def _delete_user(db: Database, username: str, id: Optional[str]):
599601
where_args.append(id)
600602

601603
n_rows = await db.execute_update(
602-
f'''
604+
f"""
603605
UPDATE users
604606
SET state = 'deleting'
605607
WHERE {' AND '.join(where_conditions)};
606-
''',
608+
""",
607609
where_args,
608610
)
609611

@@ -743,11 +745,11 @@ async def get_userinfo_from_login_id_or_hail_identity_id(
743745
users = [
744746
x
745747
async for x in db.select_and_fetchall(
746-
'''
748+
"""
747749
SELECT users.*
748750
FROM users
749751
WHERE (users.login_id = %s OR users.hail_identity_uid = %s) AND users.state = 'active'
750-
''',
752+
""",
751753
(login_id_or_hail_idenity_uid, login_id_or_hail_idenity_uid),
752754
)
753755
]
@@ -767,12 +769,12 @@ async def get_userinfo_from_hail_session_id(request: web.Request, session_id: st
767769
users = [
768770
x
769771
async for x in db.select_and_fetchall(
770-
'''
772+
"""
771773
SELECT users.*
772774
FROM users
773775
INNER JOIN sessions ON users.id = sessions.user_id
774776
WHERE users.state = 'active' AND sessions.session_id = %s AND (ISNULL(sessions.max_age_secs) OR (NOW() < TIMESTAMPADD(SECOND, sessions.max_age_secs, sessions.created)));
775-
''',
777+
""",
776778
session_id,
777779
'get_userinfo',
778780
)

auth/auth/driver/driver.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ async def delete(self):
9494
return
9595

9696
await self.db.just_execute(
97-
'''
97+
"""
9898
DELETE FROM sessions
9999
WHERE session_id = %s;
100-
''',
100+
""",
101101
(self.session_id,),
102102
)
103103
self.session_id = None
@@ -430,11 +430,11 @@ async def _create_user(app, user, skip_trial_bp, cleanup):
430430
updates['trial_bp_name'] = billing_project_name
431431

432432
n_rows = await db.execute_update(
433-
f'''
433+
f"""
434434
UPDATE users
435435
SET {', '.join([f'{k} = %({k})s' for k in updates])}
436436
WHERE id = %(id)s AND state = 'creating';
437-
''',
437+
""",
438438
{'id': user['id'], **updates},
439439
)
440440
if n_rows != 1:
@@ -502,10 +502,10 @@ async def delete_user(app, user):
502502
await bp.delete()
503503

504504
await db.just_execute(
505-
'''
505+
"""
506506
DELETE FROM sessions WHERE user_id = %s;
507507
UPDATE users SET state = 'deleted' WHERE id = %s;
508-
''',
508+
""",
509509
(user['id'], user['id']),
510510
)
511511

@@ -523,11 +523,11 @@ async def resolve_identity_uid(app, hail_identity):
523523
hail_identity_uid = await sp.get_service_principal_object_id()
524524

525525
await db.just_execute(
526-
'''
526+
"""
527527
UPDATE users
528528
SET hail_identity_uid = %s
529529
WHERE hail_identity = %s
530-
''',
530+
""",
531531
(hail_identity_uid, hail_identity),
532532
)
533533

batch/batch/batch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ async def cancel_batch_in_db(db, batch_id):
112112
@transaction(db)
113113
async def cancel(tx):
114114
record = await tx.execute_and_fetchone(
115-
'''
115+
"""
116116
SELECT `state` FROM batches
117117
WHERE id = %s AND NOT deleted
118118
FOR UPDATE;
119-
''',
119+
""",
120120
(batch_id,),
121121
)
122122
if not record:

batch/batch/cloud/azure/driver/create_instance.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def create_vm_config(
9292

9393
jvm_touch_command = '\n'.join(touch_commands)
9494

95-
startup_script = r'''#cloud-config
95+
startup_script = r"""#cloud-config
9696
9797
mounts:
9898
- [ ephemeral0, null ]
@@ -123,10 +123,10 @@ def create_vm_config(
123123
124124
runcmd:
125125
- sh /startup.sh
126-
'''
126+
"""
127127
startup_script = base64.b64encode(startup_script.encode('utf-8')).decode('utf-8')
128128

129-
run_script = f'''
129+
run_script = f"""
130130
#!/bin/bash
131131
set -x
132132
@@ -302,7 +302,7 @@ def create_vm_config(
302302
az vm delete -g $RESOURCE_GROUP -n $NAME --yes
303303
sleep 1
304304
done
305-
'''
305+
"""
306306

307307
user_data = {
308308
'run_script': run_script,

batch/batch/cloud/azure/driver/driver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ async def create(
3737

3838
region_args = [(r,) for r in regions]
3939
await db.execute_many(
40-
'''
40+
"""
4141
INSERT INTO regions (region) VALUES (%s)
4242
ON DUPLICATE KEY UPDATE region = region;
43-
''',
43+
""",
4444
region_args,
4545
)
4646

batch/batch/cloud/azure/instance_config.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ def create(
3535
else:
3636
data_disk_resource = AzureStaticSizedDiskResource.create(product_versions, 'P', data_disk_size_gb, location)
3737

38-
resources: List[AzureResource] = filter_none(
39-
[
40-
AzureVMResource.create(product_versions, machine_type, preemptible, location),
41-
AzureStaticSizedDiskResource.create(product_versions, 'E', boot_disk_size_gb, location),
42-
data_disk_resource,
43-
AzureDynamicSizedDiskResource.create(product_versions, 'P', location),
44-
AzureIPFeeResource.create(product_versions, 1024),
45-
AzureServiceFeeResource.create(product_versions),
46-
]
47-
)
38+
resources: List[AzureResource] = filter_none([
39+
AzureVMResource.create(product_versions, machine_type, preemptible, location),
40+
AzureStaticSizedDiskResource.create(product_versions, 'E', boot_disk_size_gb, location),
41+
data_disk_resource,
42+
AzureDynamicSizedDiskResource.create(product_versions, 'P', location),
43+
AzureIPFeeResource.create(product_versions, 1024),
44+
AzureServiceFeeResource.create(product_versions),
45+
])
4846

4947
return AzureSlimInstanceConfig(
5048
machine_type=machine_type,

batch/batch/cloud/azure/worker/worker_api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ def instance_config_from_config_dict(self, config_dict: Dict[str, str]) -> Azure
6666
def _blobfuse_credentials(self, credentials: Dict[str, str], account: str, container: str) -> str:
6767
credentials = orjson.loads(base64.b64decode(credentials['key.json']).decode())
6868
# https://github.com/Azure/azure-storage-fuse
69-
return f'''
69+
return f"""
7070
accountName {account}
7171
authType SPN
7272
servicePrincipalClientId {credentials["appId"]}
7373
servicePrincipalClientSecret {credentials["password"]}
7474
servicePrincipalTenantId {credentials["tenant"]}
7575
containerName {container}
76-
'''
76+
"""
7777

7878
def _write_blobfuse_credentials(
7979
self,

batch/batch/cloud/gcp/driver/activity_logs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ async def process_activity_log_events_since(
9595
project: str,
9696
mark: str,
9797
) -> str:
98-
filter = f'''
98+
filter = f"""
9999
(logName="projects/{project}/logs/cloudaudit.googleapis.com%2Factivity" OR
100100
logName="projects/{project}/logs/cloudaudit.googleapis.com%2Fsystem_event"
101101
) AND
102102
resource.type=gce_instance AND
103103
protoPayload.resourceName:"{machine_name_prefix}" AND
104104
timestamp >= "{mark}"
105-
'''
105+
"""
106106

107107
body = {
108108
'resourceNames': [f'projects/{project}'],

batch/batch/cloud/gcp/driver/create_instance.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ def scheduling() -> dict:
8585
}
8686

8787
if preemptible:
88-
result.update(
89-
{
90-
'provisioningModel': 'SPOT',
91-
'instanceTerminationAction': 'DELETE',
92-
}
93-
)
88+
result.update({
89+
'provisioningModel': 'SPOT',
90+
'instanceTerminationAction': 'DELETE',
91+
})
9492

9593
return result
9694

@@ -129,7 +127,7 @@ def scheduling() -> dict:
129127
'items': [
130128
{
131129
'key': 'startup-script',
132-
'value': '''
130+
'value': """
133131
#!/bin/bash
134132
set -x
135133
@@ -150,11 +148,11 @@ def scheduling() -> dict:
150148
curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/run_script" >./run.sh
151149
152150
nohup /bin/bash run.sh >run.log 2>&1 &
153-
''',
151+
""",
154152
},
155153
{
156154
'key': 'run_script',
157-
'value': rf'''
155+
'value': rf"""
158156
#!/bin/bash
159157
set -x
160158
@@ -346,18 +344,18 @@ def scheduling() -> dict:
346344
gcloud -q compute instances delete $NAME --zone=$ZONE
347345
sleep 1
348346
done
349-
''',
347+
""",
350348
},
351349
{
352350
'key': 'shutdown-script',
353-
'value': '''
351+
'value': """
354352
set -x
355353
356354
INSTANCE_ID=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/instance_id")
357355
NAME=$(curl -s http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google')
358356
359357
journalctl -u docker.service > dockerd.log
360-
''',
358+
""",
361359
},
362360
{'key': 'activation_token', 'value': activation_token},
363361
{'key': 'batch_worker_image', 'value': BATCH_WORKER_IMAGE},

0 commit comments

Comments
 (0)