Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 7730c46

Browse files
authored
Internal: verify code formatting in build (#633)
* format all files, enforce formatting in travis build * add yapf to vsts build * update vsts build * fix * fix * fix * change queue to ubuntu * revert * temporarily enable builds on pushes to this branch * change to non preview * revert * update yapf version, rerun * update pytest parallelism * add retry to arm call to avoid failures * remove non-master trigger * update builds, formatting style
1 parent b18eb69 commit 7730c46

File tree

127 files changed

+1052
-1226
lines changed

Some content is hidden

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

127 files changed

+1052
-1226
lines changed

.style.yapf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[style]
2-
based_on_style=pep8
2+
based_on_style=google
33
spaces_before_comment=4
44
split_before_logical_operator=True
55
indent_width=4
66
column_limit=120
77
split_arguments_when_comma_terminated=True
8+
blank_line_before_nested_class_or_def=False

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ install:
88
- pip install -e .
99

1010
script:
11+
- yapf -dpr aztk/ aztk_cli/
1112
- pylint -E aztk
1213
- pytest --ignore=tests/integration_tests
1314

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515
"python.venvPath": "${workspaceFolder}/.venv/",
1616
"python.pythonPath": "${workspaceFolder}/.venv/Scripts/python.exe",
1717
"python.unitTest.pyTestEnabled": true,
18-
}
18+
"editor.formatOnSave": true,
19+
"editor.codeActionsOnSave": {
20+
"source.organizeImports": true
21+
}
22+
}

.vsts-ci.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
trigger:
22
- master
33

4-
steps:
5-
- task: UsePythonVersion@0
6-
inputs:
7-
versionSpec: '>= 3.5'
8-
addToPath: true
9-
architecture: 'x64'
104

11-
- script: |
12-
pip install -r requirements.txt
13-
pip install -e .
14-
condition: and(succeeded(), eq(variables['agent.os'], 'linux'))
15-
displayName: install aztk
5+
phases:
6+
- phase: Test
7+
queue: Hosted Linux Preview
8+
steps:
9+
- task: UsePythonVersion@0
10+
inputs:
11+
versionSpec: '>= 3.5'
12+
addToPath: true
13+
architecture: 'x64'
1614

17-
- script: |
18-
pytest -n 50
19-
condition: and(succeeded(), in(variables['agent.os'], 'linux'))
20-
displayName: pytest
15+
- script: |
16+
pip install -r requirements.txt
17+
pip install -e .
18+
condition: succeeded()
19+
displayName: install aztk
20+
21+
- script: |
22+
yapf -dpr aztk/ aztk_cli/
23+
condition: succeeded()
24+
displayName: yapf
25+
26+
- script: |
27+
pytest -n 102
28+
condition: succeeded()
29+
displayName: pytest

account_setup.py

Lines changed: 49 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ def create_resource_group(credentials, subscription_id, **kwargs):
5656
resource_group_name=kwargs.get("resource_group", DefaultSettings.resource_group),
5757
parameters={
5858
'location': kwargs.get("region", DefaultSettings.region),
59-
}
60-
)
59+
})
6160
except CloudError as e:
6261
if i == 2:
63-
raise AccountSetupError(
64-
"Unable to create resource group in region {}".format(kwargs.get("region", DefaultSettings.region)))
62+
raise AccountSetupError("Unable to create resource group in region {}".format(
63+
kwargs.get("region", DefaultSettings.region)))
6564
print(e.message)
6665
print("Please try again.")
6766
kwargs["resource_group"] = prompt_with_default("Azure Region", DefaultSettings.region)
@@ -82,15 +81,10 @@ def create_storage_account(credentials, subscription_id, **kwargs):
8281
resource_group_name=kwargs.get("resource_group", DefaultSettings.resource_group),
8382
account_name=kwargs.get("storage_account", DefaultSettings.storage_account),
8483
parameters=StorageAccountCreateParameters(
85-
sku=Sku(SkuName.standard_lrs),
86-
kind=Kind.storage,
87-
location=kwargs.get('region', DefaultSettings.region)
88-
)
89-
)
84+
sku=Sku(SkuName.standard_lrs), kind=Kind.storage, location=kwargs.get('region', DefaultSettings.region)))
9085
return storage_account.result().id
9186

9287

93-
9488
def create_batch_account(credentials, subscription_id, **kwargs):
9589
"""
9690
Create a Batch account
@@ -108,10 +102,7 @@ def create_batch_account(credentials, subscription_id, **kwargs):
108102
parameters=BatchAccountCreateParameters(
109103
location=kwargs.get('region', DefaultSettings.region),
110104
auto_storage=AutoStorageBaseProperties(
111-
storage_account_id=kwargs.get('storage_account_id', DefaultSettings.region)
112-
)
113-
)
114-
)
105+
storage_account_id=kwargs.get('storage_account_id', DefaultSettings.region))))
115106
return batch_account.result().id
116107

117108

@@ -151,19 +142,13 @@ def create_vnet(credentials, subscription_id, **kwargs):
151142
resource_group_name=resource_group_name,
152143
virtual_network_name=kwargs.get("virtual_network_name", DefaultSettings.virtual_network_name),
153144
parameters=VirtualNetwork(
154-
location=kwargs.get("region", DefaultSettings.region),
155-
address_space=AddressSpace(["10.0.0.0/24"])
156-
)
157-
)
145+
location=kwargs.get("region", DefaultSettings.region), address_space=AddressSpace(["10.0.0.0/24"])))
158146
virtual_network = virtual_network.result()
159147
subnet = network_client.subnets.create_or_update(
160148
resource_group_name=resource_group_name,
161149
virtual_network_name=virtual_network_name,
162150
subnet_name=subnet_name,
163-
subnet_parameters=Subnet(
164-
address_prefix='10.0.0.0/24'
165-
)
166-
)
151+
subnet_parameters=Subnet(address_prefix='10.0.0.0/24'))
167152
return subnet.result().id
168153

169154

@@ -175,10 +160,7 @@ def create_aad_user(credentials, tenant_id, **kwargs):
175160
:param **application_name: str
176161
"""
177162
graph_rbac_client = GraphRbacManagementClient(
178-
credentials,
179-
tenant_id,
180-
base_url=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id
181-
)
163+
credentials, tenant_id, base_url=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id)
182164
application_credential = uuid.uuid4()
183165
try:
184166
display_name = kwargs.get("application_name", DefaultSettings.application_name)
@@ -192,42 +174,32 @@ def create_aad_user(credentials, tenant_id, **kwargs):
192174
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
193175
end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
194176
value=application_credential,
195-
key_id=uuid.uuid4()
196-
)
197-
]
198-
)
199-
)
177+
key_id=uuid.uuid4())
178+
]))
200179
service_principal = graph_rbac_client.service_principals.create(
201-
ServicePrincipalCreateParameters(
202-
app_id=application.app_id,
203-
account_enabled=True
204-
)
205-
)
180+
ServicePrincipalCreateParameters(app_id=application.app_id, account_enabled=True))
206181
except GraphErrorException as e:
207182
if e.inner_exception.code == "Request_BadRequest":
208-
application = next(graph_rbac_client.applications.list(
209-
filter="identifierUris/any(c:c eq 'http://{}.com')".format(display_name)))
183+
application = next(
184+
graph_rbac_client.applications.list(
185+
filter="identifierUris/any(c:c eq 'http://{}.com')".format(display_name)))
210186

211187
confirmation_prompt = "Previously created application with name {} found. "\
212188
"Would you like to use it? (y/n): ".format(application.display_name)
213189
prompt_for_confirmation(confirmation_prompt, e, ValueError("Response not recognized. Please try again."))
214-
password_credentials = list(graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
190+
password_credentials = list(
191+
graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
215192
password_credentials.append(
216193
PasswordCredential(
217194
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
218195
end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
219196
value=application_credential,
220-
key_id=uuid.uuid4()
221-
)
222-
)
197+
key_id=uuid.uuid4()))
223198
graph_rbac_client.applications.patch(
224199
application_object_id=application.object_id,
225-
parameters=ApplicationUpdateParameters(
226-
password_credentials=password_credentials
227-
)
228-
)
229-
service_principal = next(graph_rbac_client.service_principals.list(
230-
filter="appId eq '{}'".format(application.app_id)))
200+
parameters=ApplicationUpdateParameters(password_credentials=password_credentials))
201+
service_principal = next(
202+
graph_rbac_client.service_principals.list(filter="appId eq '{}'".format(application.app_id)))
231203
else:
232204
raise e
233205

@@ -244,21 +216,15 @@ def create_role_assignment(credentials, subscription_id, scope, principal_id):
244216
"""
245217
authorization_client = AuthorizationManagementClient(credentials, subscription_id)
246218
role_name = 'Contributor'
247-
roles = list(authorization_client.role_definitions.list(
248-
scope,
249-
filter="roleName eq '{}'".format(role_name)
250-
))
219+
roles = list(authorization_client.role_definitions.list(scope, filter="roleName eq '{}'".format(role_name)))
251220
contributor_role = roles[0]
252221
for i in range(10):
253222
try:
254-
authorization_client.role_assignments.create(
255-
scope,
256-
uuid.uuid4(),
257-
{
258-
'role_definition_id': contributor_role.id,
259-
'principal_id': principal_id
260-
}
261-
)
223+
authorization_client.role_assignments.create(scope, uuid.uuid4(),
224+
{
225+
'role_definition_id': contributor_role.id,
226+
'principal_id': principal_id
227+
})
262228
break
263229
except CloudError as e:
264230
# ignore error if service principal has not yet been created
@@ -321,15 +287,15 @@ def prompt_tenant_selection(tenant_ids):
321287
raise AccountSetupError("Tenant selection not recognized after 3 attempts.")
322288

323289

324-
325290
class Spinner:
326291
busy = False
327292
delay = 0.1
328293

329294
@staticmethod
330295
def spinning_cursor():
331296
while 1:
332-
for cursor in '|/-\\': yield cursor
297+
for cursor in '|/-\\':
298+
yield cursor
333299

334300
def __init__(self, delay=None):
335301
self.spinner_generator = self.spinning_cursor()
@@ -358,7 +324,6 @@ def stop(self):
358324
time.sleep(self.delay)
359325

360326

361-
362327
if __name__ == "__main__":
363328
print("\nGetting credentials.")
364329
# get credentials and tenant_id
@@ -374,15 +339,22 @@ def stop(self):
374339
"Default values are provided in the brackets. "\
375340
"Hit enter to use default.")
376341
kwargs = {
377-
"region": prompt_with_default("Azure Region", DefaultSettings.region),
378-
"resource_group": prompt_with_default("Resource Group Name", DefaultSettings.resource_group),
379-
"storage_account": prompt_with_default("Storage Account Name", DefaultSettings.storage_account),
380-
"batch_account": prompt_with_default("Batch Account Name", DefaultSettings.batch_account),
381-
# "virtual_network_name": prompt_with_default("Virtual Network Name", DefaultSettings.virtual_network_name),
382-
# "subnet_name": prompt_with_default("Subnet Name", DefaultSettings.subnet_name),
383-
"application_name": prompt_with_default("Active Directory Application Name", DefaultSettings.application_name),
384-
"application_credential_name": prompt_with_default("Active Directory Application Credential Name", DefaultSettings.resource_group),
385-
"service_principal": prompt_with_default("Service Principal Name", DefaultSettings.service_principal)
342+
"region":
343+
prompt_with_default("Azure Region", DefaultSettings.region),
344+
"resource_group":
345+
prompt_with_default("Resource Group Name", DefaultSettings.resource_group),
346+
"storage_account":
347+
prompt_with_default("Storage Account Name", DefaultSettings.storage_account),
348+
"batch_account":
349+
prompt_with_default("Batch Account Name", DefaultSettings.batch_account),
350+
# "virtual_network_name": prompt_with_default("Virtual Network Name", DefaultSettings.virtual_network_name),
351+
# "subnet_name": prompt_with_default("Subnet Name", DefaultSettings.subnet_name),
352+
"application_name":
353+
prompt_with_default("Active Directory Application Name", DefaultSettings.application_name),
354+
"application_credential_name":
355+
prompt_with_default("Active Directory Application Credential Name", DefaultSettings.resource_group),
356+
"service_principal":
357+
prompt_with_default("Service Principal Name", DefaultSettings.service_principal)
386358
}
387359
print("Creating the Azure resources.")
388360

@@ -410,9 +382,9 @@ def stop(self):
410382
with Spinner():
411383
profile = credentials.get_cli_profile()
412384
aad_cred, subscription_id, tenant_id = profile.get_login_credentials(
413-
resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id
414-
)
415-
application_id, service_principal_object_id, application_credential = create_aad_user(aad_cred, tenant_id, **kwargs)
385+
resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id)
386+
application_id, service_principal_object_id, application_credential = create_aad_user(
387+
aad_cred, tenant_id, **kwargs)
416388

417389
print("Created Azure Active Directory service principal.")
418390

@@ -425,10 +397,9 @@ def stop(self):
425397
"tenant_id": tenant_id,
426398
"client_id": application_id,
427399
"credential": application_credential,
428-
# "subnet_id": subnet_id,
400+
# "subnet_id": subnet_id,
429401
"batch_account_resource_id": batch_account_id,
430402
"storage_account_resource_id": storage_account_id
431-
}
432-
)
403+
})
433404

434405
print("\n# Copy the following into your .aztk/secrets.yaml file\n{}".format(secrets))

aztk/client/base/helpers/create_user_on_node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def __create_user(self, id: str, node_id: str, username: str, password: str = No
3232

3333
def create_user_on_node(base_client, id, node_id, username, ssh_key=None, password=None):
3434
try:
35-
__create_user(
36-
base_client, id=id, node_id=node_id, username=username, ssh_key=ssh_key, password=password)
35+
__create_user(base_client, id=id, node_id=node_id, username=username, ssh_key=ssh_key, password=password)
3736
except batch_error.BatchErrorException as error:
3837
try:
3938
base_client.delete_user_on_node(id, node_id, username)

aztk/client/base/helpers/delete_user_on_cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import concurrent.futures
22

3+
34
#TODO: remove nodes param
45
def delete_user_on_cluster(base_client, id, nodes, username):
56
with concurrent.futures.ThreadPoolExecutor() as executor:

aztk/client/base/helpers/get_application_log.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,9 @@ def get_log(batch_client, blob_client, cluster_id: str, application_name: str, t
102102
exit_code=task.execution_info.exit_code)
103103

104104

105-
def get_application_log(base_operations,
106-
cluster_id: str,
107-
application_name: str,
108-
tail=False,
109-
current_bytes: int = 0):
105+
def get_application_log(base_operations, cluster_id: str, application_name: str, tail=False, current_bytes: int = 0):
110106
try:
111-
return get_log(base_operations.batch_client, base_operations.blob_client, cluster_id,
112-
application_name, tail, current_bytes)
107+
return get_log(base_operations.batch_client, base_operations.blob_client, cluster_id, application_name, tail,
108+
current_bytes)
113109
except batch_error.BatchErrorException as e:
114110
raise error.AztkError(helpers.format_batch_exception(e))

aztk/client/base/helpers/ssh_into_node.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
from aztk.utils import ssh as ssh_lib
33

44

5-
def ssh_into_node(base_client, pool_id, node_id, username, ssh_key=None, password=None, port_forward_list=None, internal=False):
5+
def ssh_into_node(base_client,
6+
pool_id,
7+
node_id,
8+
username,
9+
ssh_key=None,
10+
password=None,
11+
port_forward_list=None,
12+
internal=False):
613
if internal:
714
result = base_client.batch_client.compute_node.get(pool_id=pool_id, node_id=node_id)
815
rls = models.RemoteLogin(ip_address=result.ip_address, port="22")

0 commit comments

Comments
 (0)