Skip to content

Commit ea2013d

Browse files
chore: run blacken on all directories with a noxfile (#16)
* chore: run blacken on all directories with a noxfile * add missing import * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent bd3825c commit ea2013d

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

optimization/snippets/async_api.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@
2424
# model_solution_gcs_path = 'gs://YOUR_PROJECT/YOUR_BUCKET/YOUR_SOLUCTION_PATH'
2525

2626

27-
def call_async_api(project_id: str, request_model_gcs_path: str, model_solution_gcs_path_prefix: str) -> None:
27+
def call_async_api(
28+
project_id: str, request_model_gcs_path: str, model_solution_gcs_path_prefix: str
29+
) -> None:
2830
"""Call the async api for fleet routing."""
2931
# Use the default credentials for the environment to authenticate the client.
3032
fleet_routing_client = optimization_v1.FleetRoutingClient()
3133
request_file_name = "resources/async_request.json"
3234

33-
with open(request_file_name, 'r') as f:
34-
fleet_routing_request = optimization_v1.BatchOptimizeToursRequest.from_json(f.read())
35+
with open(request_file_name, "r") as f:
36+
fleet_routing_request = optimization_v1.BatchOptimizeToursRequest.from_json(
37+
f.read()
38+
)
3539
fleet_routing_request.parent = f"projects/{project_id}"
3640
for idx, mc in enumerate(fleet_routing_request.model_configs):
3741
mc.input_config.gcs_source.uri = request_model_gcs_path
38-
model_solution_gcs_path = f'{model_solution_gcs_path_prefix}_{idx}'
42+
model_solution_gcs_path = f"{model_solution_gcs_path_prefix}_{idx}"
3943
mc.output_config.gcs_destination.uri = model_solution_gcs_path
4044

4145
# The timeout argument for the gRPC call is independent from the `timeout`

optimization/snippets/async_api_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# TODO(developer): Replace the variables in the file before use.
2424
# A sample request model can be found at resources/async_request_model.json.
2525
TEST_UUID = uuid.uuid4()
26-
BUCKET = f'optimization-ai-{TEST_UUID}'
27-
OUTPUT_PREFIX = f'code_snippets_test_output_{TEST_UUID}'
26+
BUCKET = f"optimization-ai-{TEST_UUID}"
27+
OUTPUT_PREFIX = f"code_snippets_test_output_{TEST_UUID}"
2828
INPUT_URI = "gs://cloud-samples-data/optimization-ai/async_request_model.json"
2929
BATCH_OUTPUT_URI_PREFIX = "gs://{}/{}/".format(BUCKET, OUTPUT_PREFIX)
3030

optimization/snippets/get_operation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ def get_operation(operation_full_id: str) -> None:
2929
print("Name: {}".format(response.name))
3030
print("Operation details:")
3131
print(response)
32+
33+
3234
# [END cloudoptimization_get_operation]

optimization/snippets/get_operation_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def operation_id() -> str:
3333
yield operation.operation.name
3434

3535

36-
def test_get_operation_status(capsys: pytest.LogCaptureFixture, operation_id: str) -> None:
36+
def test_get_operation_status(
37+
capsys: pytest.LogCaptureFixture, operation_id: str
38+
) -> None:
3739
get_operation.get_operation(operation_id)
3840
out, _ = capsys.readouterr()
3941
assert "Operation details" in out

optimization/snippets/noxfile.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ def _session_tests(
208208

209209
if os.path.exists("requirements-test.txt"):
210210
if os.path.exists("constraints-test.txt"):
211-
session.install(
212-
"-r", "requirements-test.txt", "-c", "constraints-test.txt"
213-
)
211+
session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt")
214212
else:
215213
session.install("-r", "requirements-test.txt")
216214
with open("requirements-test.txt") as rtfile:
@@ -223,9 +221,9 @@ def _session_tests(
223221
post_install(session)
224222

225223
if "pytest-parallel" in packages:
226-
concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto'])
224+
concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"])
227225
elif "pytest-xdist" in packages:
228-
concurrent_args.extend(['-n', 'auto'])
226+
concurrent_args.extend(["-n", "auto"])
229227

230228
session.run(
231229
"pytest",
@@ -255,7 +253,7 @@ def py(session: nox.sessions.Session) -> None:
255253

256254

257255
def _get_repo_root() -> Optional[str]:
258-
""" Returns the root folder of the project. """
256+
"""Returns the root folder of the project."""
259257
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
260258
p = Path(os.getcwd())
261259
for i in range(10):

optimization/snippets/sync_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def call_sync_api(project_id: str) -> None:
2727
request_file_name = "resources/sync_request.json"
2828
fleet_routing_client = optimization_v1.FleetRoutingClient()
2929

30-
with open(request_file_name, 'r') as f:
30+
with open(request_file_name, "r") as f:
3131
# The request must include the `parent` field with the value set to
3232
# 'projects/{YOUR_GCP_PROJECT_ID}'.
3333
fleet_routing_request = optimization_v1.OptimizeToursRequest.from_json(f.read())
@@ -36,10 +36,12 @@ def call_sync_api(project_id: str) -> None:
3636
# Fleet Routing will return a response by the earliest of the `timeout`
3737
# field in the request payload and the gRPC timeout specified below.
3838
fleet_routing_response = fleet_routing_client.optimize_tours(
39-
fleet_routing_request, timeout=100)
39+
fleet_routing_request, timeout=100
40+
)
4041
print(fleet_routing_response)
4142
# If you want to format the response to JSON, you can do the following:
4243
# from google.protobuf.json_format import MessageToJson
4344
# json_obj = MessageToJson(fleet_routing_response._pb)
4445

46+
4547
# [END cloudoptimization_sync_api]

optimization/snippets/sync_api_with_long_timeout.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
from google.cloud import optimization_v1
1818
from google.cloud.optimization_v1.services import fleet_routing
1919
from google.cloud.optimization_v1.services.fleet_routing import transports
20-
from google.cloud.optimization_v1.services.fleet_routing.transports import grpc as fleet_routing_grpc
20+
from google.cloud.optimization_v1.services.fleet_routing.transports import (
21+
grpc as fleet_routing_grpc,
22+
)
2123

2224
# TODO(developer): Uncomment these variables before running the sample.
2325
# project_id= 'YOUR_PROJECT_ID'
2426

2527

2628
def long_timeout(request_file_name: str, project_id: str) -> None:
27-
with open(request_file_name, 'r') as f:
29+
with open(request_file_name, "r") as f:
2830
fleet_routing_request = optimization_v1.OptimizeToursRequest.from_json(f.read())
2931
fleet_routing_request.parent = f"projects/{project_id}"
3032

@@ -33,9 +35,9 @@ def long_timeout(request_file_name: str, project_id: str) -> None:
3335
# the channel behavior in order to send keep-alive pings every 5 minutes.
3436
channel = fleet_routing_grpc.FleetRoutingGrpcTransport.create_channel(
3537
options=[
36-
('grpc.keepalive_time_ms', 500),
37-
('grpc.max_send_message_length', -1),
38-
('grpc.max_receive_message_length', -1),
38+
("grpc.keepalive_time_ms", 500),
39+
("grpc.max_send_message_length", -1),
40+
("grpc.max_receive_message_length", -1),
3941
],
4042
)
4143
# Keep-alive pings are sent on the transport. Create the transport using the
@@ -45,4 +47,5 @@ def long_timeout(request_file_name: str, project_id: str) -> None:
4547
fleet_routing_response = client.optimize_tours(fleet_routing_request)
4648
print(fleet_routing_response)
4749

50+
4851
# [END cloudoptimization_long_timeout]

0 commit comments

Comments
 (0)