Skip to content

Commit 2a633ee

Browse files
feat: upgrade sample style (Infra) (GoogleCloudPlatform#9939)
* feat: upgrade sample style (Infra) * copyright header updates * Update create_instance.py --------- Co-authored-by: Maciej Strzelczyk <strzelczyk@google.com>
1 parent a11f7e8 commit 2a633ee

File tree

90 files changed

+224
-222
lines changed

Some content is hidden

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

90 files changed

+224
-222
lines changed

auth/api-client/snippets_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
import os
16+
from unittest import mock
1617

1718
import google.auth
18-
import mock
1919

2020
import snippets
2121

auth/cloud-client/snippets_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
import os
16+
from unittest import mock
1617

1718
import google.auth
18-
import mock
1919

2020
import snippets
2121

auth/downscoping/snippets_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_bucket():
2929
"""Yields a bucket that is deleted after the test completes."""
3030
bucket = None
3131
while bucket is None or bucket.exists():
32-
bucket_name = "bucket-downscoping-test-{}".format(uuid.uuid4())
32+
bucket_name = f"bucket-downscoping-test-{uuid.uuid4()}"
3333
bucket = storage.Client().bucket(bucket_name)
3434
bucket = storage.Client().create_bucket(bucket.name)
3535
yield bucket

compute/api/create_instance.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import time
3030

3131
import googleapiclient.discovery
32-
from six.moves import input
3332

3433

3534
# [START list_instances]
@@ -50,7 +49,7 @@ def create_instance(compute, project, zone, name, bucket):
5049
machine_type = "zones/%s/machineTypes/n1-standard-1" % zone
5150
startup_script = open(
5251
os.path.join(
53-
os.path.dirname(__file__), 'startup-script.sh'), 'r').read()
52+
os.path.dirname(__file__), 'startup-script.sh')).read()
5453
image_url = "http://storage.googleapis.com/gce-demo-input/photo.jpg"
5554
image_caption = "Ready for dessert?"
5655

@@ -154,16 +153,16 @@ def main(project, bucket, zone, instance_name, wait=True):
154153

155154
instances = list_instances(compute, project, zone)
156155

157-
print('Instances in project %s and zone %s:' % (project, zone))
156+
print(f'Instances in project {project} and zone {zone}:')
158157
for instance in instances:
159-
print(' - ' + instance['name'])
158+
print(f' - {instance["name"]}')
160159

161-
print("""
160+
print(f"""
162161
Instance created.
163162
It will take a minute or two for the instance to complete work.
164-
Check this URL: http://storage.googleapis.com/{}/output.png
163+
Check this URL: http://storage.googleapis.com/{bucket}/output.png
165164
Once the image is uploaded press enter to delete the instance.
166-
""".format(bucket))
165+
""")
167166

168167
if wait:
169168
input()

compute/api/create_instance_test.py

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

2525
@pytest.mark.flaky(max_runs=3, min_passes=1)
2626
def test_main(capsys):
27-
instance_name = 'test-instance-{}'.format(uuid.uuid4())
27+
instance_name = f'test-instance-{uuid.uuid4()}'
2828
main(
2929
PROJECT,
3030
BUCKET,

compute/auth/access_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def list_buckets(project_id, access_token):
5151
'project': project_id
5252
}
5353
headers = {
54-
'Authorization': 'Bearer {}'.format(access_token)
54+
'Authorization': f'Bearer {access_token}'
5555
}
5656

5757
r = requests.get(url, params=params, headers=headers)

compute/auth/access_token_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Copyright 2016, Google, Inc.
2-
# Licensed under the Apache License, Version 2.0 (the "License");
3-
# you may not use this file except in compliance with the License.
4-
# You may obtain a copy of the License at
1+
# Copyright 2016 Google, Inc.
52
#
6-
# http://www.apache.org/licenses/LICENSE-2.0
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
76
#
8-
# Unless required by applicable law or agreed to in writing, software
9-
# distributed under the License is distributed on an "AS IS" BASIS,
10-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
# See the License for the specific language governing permissions and
12-
# limitations under the License.
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
1314

1415
import os
15-
16-
import mock
16+
from unittest import mock
1717

1818
import access_token
1919

compute/encryption/generate_wrapped_rsa_key_test.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# Copyright 2016, Google, Inc.
2-
# Licensed under the Apache License, Version 2.0 (the "License");
3-
# you may not use this file except in compliance with the License.
4-
# You may obtain a copy of the License at
1+
# Copyright 2016 Google, Inc.
52
#
6-
# http://www.apache.org/licenses/LICENSE-2.0
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
76
#
8-
# Unless required by applicable law or agreed to in writing, software
9-
# distributed under the License is distributed on an "AS IS" BASIS,
10-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
# See the License for the specific language governing permissions and
12-
# limitations under the License.
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
1314

1415
import os
1516
import uuid
@@ -33,7 +34,7 @@ def test_create_disk():
3334
google_public_key = generate_wrapped_rsa_key.get_google_public_cert_key()
3435
wrapped_rsa_key = generate_wrapped_rsa_key.wrap_rsa_key(
3536
google_public_key, key_bytes)
36-
disk_name = 'new-encrypted-disk-{}'.format(uuid.uuid4().hex)
37+
disk_name = f'new-encrypted-disk-{uuid.uuid4().hex}'
3738

3839
try:
3940
# Create the disk, if the encryption key is invalid, this will raise.

compute/metadata/detect_legacy_usage.py

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

3131
# [START compute_wait_for_legacy_usage]
3232
def wait_for_legacy_usage(callback):
33-
url = '{}/instance/legacy-endpoint-access'.format(METADATA_URL)
33+
url = f'{METADATA_URL}/instance/legacy-endpoint-access'
3434
last_etag = '0'
3535
counts = None
3636
while True:

compute/metadata/detect_legacy_usage_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import json
16+
from unittest import mock
1617

17-
import mock
1818
import requests
1919

2020
import detect_legacy_usage

0 commit comments

Comments
 (0)