Skip to content

Commit 254702f

Browse files
nammnfealebenpae
authored andcommitted
fix black and add isort (#3269)
1 parent a6a23bb commit 254702f

File tree

246 files changed

+2426
-5801
lines changed

Some content is hidden

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

246 files changed

+2426
-5801
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503
3+
max-line-length = 120
4+
max-complexity = 18
5+
select = B,C,E,F,W,T4,B9

.githooks/pre-commit

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ function generate_standalone_yaml() {
3636
cat "${charttmpdir}/enterprise-operator/templates/"{operator-roles.yaml,database-roles.yaml,operator.yaml} >public/mongodb-enterprise-openshift.yaml
3737
}
3838

39-
function black_formatting() {
39+
function python_formatting() {
4040
# installing Black
4141
if ! command -v "black" >/dev/null ; then
4242
pip install -r docker/mongodb-enterprise-tests/requirements-dev.txt
4343
fi
4444

45+
echo "formatting isort"
46+
isort .
47+
echo "formatting black"
4548
black .
4649
}
4750

@@ -76,7 +79,7 @@ function pre_commit() {
7679
# The values files are used for generating the standalone yaml
7780
generate_standalone_yaml
7881
# Run black on python files that have changed
79-
black_formatting
82+
python_formatting
8083

8184
source scripts/evergreen/lint_code.sh
8285

.pylintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[GENERAL]
2+
max-line-length=120
3+
4+
[MESSAGES CONTROL]
5+
disable=
6+
C0114, # missing-module-docstring
7+
C0115, # missing-class-docstring
8+
C0116, # missing-docstring
9+
R0201, # no-self-use
10+
W0621, # redefined-outer-name

docker/cluster-cleaner/scripts/is_older_than.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
# ./is_older_than.py 1980-25-04T11:00:04Z 39 years
2525
#
2626

27-
from datetime import datetime, timedelta
2827
import sys
28+
from datetime import datetime, timedelta
2929

3030

3131
def is_older_than(date, amount, unit):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
ignore = E203, E266, E501, W503
3-
max-line-length = 80
3+
max-line-length = 120
44
max-complexity = 18
55
select = B,C,E,F,W,T4,B9

docker/mongodb-enterprise-tests/kubetester/__init__.py

Lines changed: 31 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from typing import Any, Callable, Dict, List, Optional
88

99
import kubernetes.client
10-
from kubernetes import client, utils
11-
1210
from kubeobject import CustomObject
11+
from kubernetes import client, utils
1312
from kubetester.kubetester import run_periodically, running_locally
1413

1514
# Re-exports
@@ -19,7 +18,6 @@
1918
assert_pod_container_security_context,
2019
assert_pod_security_context,
2120
)
22-
from kubernetes import client
2321

2422

2523
def create_secret(
@@ -30,9 +28,7 @@ def create_secret(
3028
api_client: Optional[client.ApiClient] = None,
3129
) -> str:
3230
"""Creates a Secret with `name` in `namespace`. String contents are passed as the `data` parameter."""
33-
secret = client.V1Secret(
34-
metadata=client.V1ObjectMeta(name=name), string_data=data, type=type
35-
)
31+
secret = client.V1Secret(metadata=client.V1ObjectMeta(name=name), string_data=data, type=type)
3632

3733
client.CoreV1Api(api_client=api_client).create_namespaced_secret(namespace, secret)
3834

@@ -63,14 +59,10 @@ def update_secret(
6359
):
6460
"""Updates a secret in a given namespace with the given name and data—handles base64 encoding."""
6561
secret = client.V1Secret(metadata=client.V1ObjectMeta(name=name), string_data=data)
66-
client.CoreV1Api(api_client=api_client).patch_namespaced_secret(
67-
name, namespace, secret
68-
)
62+
client.CoreV1Api(api_client=api_client).patch_namespaced_secret(name, namespace, secret)
6963

7064

71-
def delete_secret(
72-
namespace: str, name: str, api_client: Optional[kubernetes.client.ApiClient] = None
73-
):
65+
def delete_secret(namespace: str, name: str, api_client: Optional[kubernetes.client.ApiClient] = None):
7466
client.CoreV1Api(api_client=api_client).delete_namespaced_secret(name, namespace)
7567

7668

@@ -88,18 +80,12 @@ def create_or_update_service(
8880
api_client: Optional[kubernetes.client.ApiClient] = None,
8981
):
9082
"""Creates a service with `name` in `namespace`"""
91-
service = client.V1Service(
92-
metadata=client.V1ObjectMeta(name=name, namespace=namespace), spec=spec
93-
)
83+
service = client.V1Service(metadata=client.V1ObjectMeta(name=name, namespace=namespace), spec=spec)
9484
try:
95-
client.CoreV1Api(api_client=api_client).create_namespaced_service(
96-
namespace=namespace, body=service
97-
)
85+
client.CoreV1Api(api_client=api_client).create_namespaced_service(namespace=namespace, body=service)
9886
except kubernetes.client.ApiException as e:
9987
if e.status == 409:
100-
client.CoreV1Api(api_client=api_client).patch_namespaced_service(
101-
name, namespace, body=service
102-
)
88+
client.CoreV1Api(api_client=api_client).patch_namespaced_service(name, namespace, body=service)
10389
else:
10490
raise e
10591

@@ -117,9 +103,7 @@ def get_service(
117103
:return None if the service does not exist
118104
"""
119105
try:
120-
return client.CoreV1Api(api_client=api_client).read_namespaced_service(
121-
name, namespace
122-
)
106+
return client.CoreV1Api(api_client=api_client).read_namespaced_service(name, namespace)
123107
except kubernetes.client.ApiException as e:
124108
if e.status == 404:
125109
return None
@@ -129,24 +113,16 @@ def get_service(
129113

130114
def delete_pvc(namespace: str, name: str):
131115
"""Deletes a persistent volument claim(pvc) with `name` in `namespace`"""
132-
client.CoreV1Api().delete_namespaced_persistent_volume_claim(
133-
namespace=namespace, name=name
134-
)
116+
client.CoreV1Api().delete_namespaced_persistent_volume_claim(namespace=namespace, name=name)
135117

136118

137119
def create_object_from_dict(data, namespace: str) -> List:
138120
k8s_client = client.ApiClient()
139121
return utils.create_from_dict(k8s_client=k8s_client, data=data, namespace=namespace)
140122

141123

142-
def read_configmap(
143-
namespace: str, name: str, api_client: Optional[client.ApiClient] = None
144-
) -> Dict[str, str]:
145-
return (
146-
client.CoreV1Api(api_client=api_client)
147-
.read_namespaced_config_map(name, namespace)
148-
.data
149-
)
124+
def read_configmap(namespace: str, name: str, api_client: Optional[client.ApiClient] = None) -> Dict[str, str]:
125+
return client.CoreV1Api(api_client=api_client).read_namespaced_config_map(name, namespace).data
150126

151127

152128
def create_configmap(
@@ -156,9 +132,7 @@ def create_configmap(
156132
api_client: Optional[kubernetes.client.ApiClient] = None,
157133
):
158134
configmap = client.V1ConfigMap(metadata=client.V1ObjectMeta(name=name), data=data)
159-
client.CoreV1Api(api_client=api_client).create_namespaced_config_map(
160-
namespace, configmap
161-
)
135+
client.CoreV1Api(api_client=api_client).create_namespaced_config_map(namespace, configmap)
162136

163137

164138
def update_configmap(
@@ -168,9 +142,7 @@ def update_configmap(
168142
api_client: Optional[kubernetes.client.ApiClient] = None,
169143
):
170144
configmap = client.V1ConfigMap(metadata=client.V1ObjectMeta(name=name), data=data)
171-
client.CoreV1Api(api_client=api_client).replace_namespaced_config_map(
172-
name, namespace, configmap
173-
)
145+
client.CoreV1Api(api_client=api_client).replace_namespaced_config_map(name, namespace, configmap)
174146

175147

176148
def create_or_update_configmap(
@@ -201,9 +173,7 @@ def create_service(
201173

202174
service = client.V1Service(
203175
metadata=client.V1ObjectMeta(name=name, namespace=namespace),
204-
spec=client.V1ServiceSpec(
205-
ports=ports, cluster_ip=cluster_ip, selector=selector
206-
),
176+
spec=client.V1ServiceSpec(ports=ports, cluster_ip=cluster_ip, selector=selector),
207177
)
208178
client.CoreV1Api().create_namespaced_service(namespace, service)
209179

@@ -242,26 +212,18 @@ def read_service(
242212
name: str,
243213
api_client: Optional[client.ApiClient] = None,
244214
) -> client.V1Service:
245-
return client.CoreV1Api(api_client=api_client).read_namespaced_service(
246-
name, namespace
247-
)
215+
return client.CoreV1Api(api_client=api_client).read_namespaced_service(name, namespace)
248216

249217

250218
def read_secret(
251219
namespace: str,
252220
name: str,
253221
api_client: Optional[client.ApiClient] = None,
254222
) -> Dict[str, str]:
255-
return decode_secret(
256-
client.CoreV1Api(api_client=api_client)
257-
.read_namespaced_secret(name, namespace)
258-
.data
259-
)
223+
return decode_secret(client.CoreV1Api(api_client=api_client).read_namespaced_secret(name, namespace).data)
260224

261225

262-
def delete_pod(
263-
namespace: str, name: str, api_client: Optional[kubernetes.client.ApiClient] = None
264-
):
226+
def delete_pod(namespace: str, name: str, api_client: Optional[kubernetes.client.ApiClient] = None):
265227
client.CoreV1Api(api_client=api_client).delete_namespaced_pod(name, namespace)
266228

267229

@@ -282,9 +244,7 @@ def create_or_update_namespace(
282244
client.CoreV1Api(api_client=api_client).create_namespace(namespace_resource)
283245
except kubernetes.client.ApiException as e:
284246
if e.status == 409:
285-
client.CoreV1Api(api_client=api_client).patch_namespace(
286-
namespace, namespace_resource
287-
)
247+
client.CoreV1Api(api_client=api_client).patch_namespace(namespace, namespace_resource)
288248

289249

290250
def delete_namespace(name: str):
@@ -312,14 +272,10 @@ def get_statefulset(
312272
name: str,
313273
api_client: Optional[client.ApiClient] = None,
314274
) -> client.V1StatefulSet:
315-
return client.AppsV1Api(api_client=api_client).read_namespaced_stateful_set(
316-
name, namespace
317-
)
275+
return client.AppsV1Api(api_client=api_client).read_namespaced_stateful_set(name, namespace)
318276

319277

320-
def statefulset_is_deleted(
321-
namespace: str, name: str, api_client: Optional[client.ApiClient]
322-
):
278+
def statefulset_is_deleted(namespace: str, name: str, api_client: Optional[client.ApiClient]):
323279
try:
324280
get_statefulset(namespace, name, api_client=api_client)
325281
return False
@@ -338,13 +294,9 @@ def delete_cluster_role(name: str, api_client: Optional[client.ApiClient] = None
338294
raise e
339295

340296

341-
def delete_cluster_role_binding(
342-
name: str, api_client: Optional[client.ApiClient] = None
343-
):
297+
def delete_cluster_role_binding(name: str, api_client: Optional[client.ApiClient] = None):
344298
try:
345-
client.RbacAuthorizationV1Api(
346-
api_client=api_client
347-
).delete_cluster_role_binding(name)
299+
client.RbacAuthorizationV1Api(api_client=api_client).delete_cluster_role_binding(name)
348300
except client.rest.ApiException as e:
349301
if e.status != 404:
350302
raise e
@@ -367,9 +319,7 @@ def get_pod_when_running(
367319
time.sleep(3)
368320

369321
try:
370-
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(
371-
namespace, label_selector=label_selector
372-
)
322+
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(namespace, label_selector=label_selector)
373323
try:
374324
pod = pods.items[0]
375325
except IndexError:
@@ -397,17 +347,13 @@ def get_pod_when_ready(
397347
cnt = 0
398348

399349
while True and cnt < default_retry:
400-
print(
401-
f"get_pod_when_ready: namespace={namespace}, label_selector={label_selector}"
402-
)
350+
print(f"get_pod_when_ready: namespace={namespace}, label_selector={label_selector}")
403351

404352
if cnt > 0:
405353
time.sleep(1)
406354
cnt += 1
407355
try:
408-
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(
409-
namespace, label_selector=label_selector
410-
)
356+
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(namespace, label_selector=label_selector)
411357

412358
if len(pods.items) == 0:
413359
continue
@@ -440,13 +386,9 @@ def is_pod_ready(
440386
if it does not exist or there is any other kind of error.
441387
This function is intended to check if installing third party components is needed.
442388
"""
443-
print(
444-
f"Checking if pod is ready: namespace={namespace}, label_selector={label_selector}"
445-
)
389+
print(f"Checking if pod is ready: namespace={namespace}, label_selector={label_selector}")
446390
try:
447-
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(
448-
namespace, label_selector=label_selector
449-
)
391+
pods = client.CoreV1Api(api_client=api_client).list_namespaced_pod(namespace, label_selector=label_selector)
450392

451393
if len(pods.items) == 0:
452394
return None
@@ -507,9 +449,7 @@ def create_or_update(resource: CustomObject) -> CustomObject:
507449
while tries < 10:
508450
if tries > 0: # The first try we don't need to do client-side merge apply
509451
# do a client-side-apply
510-
new_back_obj_to_apply = copy.deepcopy(
511-
resource.backing_obj
512-
) # resource and changes we want to apply
452+
new_back_obj_to_apply = copy.deepcopy(resource.backing_obj) # resource and changes we want to apply
513453

514454
resource.load() # resource from the server overwrites resource.backing_obj
515455

@@ -521,13 +461,9 @@ def create_or_update(resource: CustomObject) -> CustomObject:
521461
# we want to apply has them. But that is highly unlikely, and we can add that code in case that happens.
522462
resource["spec"] = new_back_obj_to_apply["spec"]
523463
if "metadata" in resource and "annotations" in resource["metadata"]:
524-
resource["metadata"]["annotations"].update(
525-
new_back_obj_to_apply["metadata"]["annotations"]
526-
)
464+
resource["metadata"]["annotations"].update(new_back_obj_to_apply["metadata"]["annotations"])
527465
if "metadata" in resource and "labels" in resource["metadata"]:
528-
resource["metadata"]["labels"].update(
529-
new_back_obj_to_apply["metadata"]["labels"]
530-
)
466+
resource["metadata"]["labels"].update(new_back_obj_to_apply["metadata"]["labels"])
531467
try:
532468
resource.update()
533469
break
@@ -541,9 +477,7 @@ def create_or_update(resource: CustomObject) -> CustomObject:
541477
)
542478
tries += 1
543479
if tries == 10:
544-
raise Exception(
545-
"Tried client side merge 10 times and did not succeed"
546-
)
480+
raise Exception("Tried client side merge 10 times and did not succeed")
547481

548482
return resource
549483

0 commit comments

Comments
 (0)