Skip to content

Commit 123a8ca

Browse files
committed
change: linting for black
Weird - my local black came up different than tox
1 parent c796bd4 commit 123a8ca

File tree

3 files changed

+36
-72
lines changed

3 files changed

+36
-72
lines changed

src/sagemaker/processing.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@ def __init__(
454454
self._CODE_CONTAINER_INPUT_NAME = "code"
455455
self.command = command
456456
self.code_location = (
457-
code_location[:-1]
458-
if (code_location and code_location.endswith("/"))
459-
else code_location
457+
code_location[:-1] if (code_location and code_location.endswith("/")) else code_location
460458
)
461459

462460
super(ScriptProcessor, self).__init__(

tests/integ/test_processing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,11 @@ def test_sklearn_with_network_config(sagemaker_session, sklearn_latest_version,
701701

702702

703703
def test_processing_job_inputs_and_output_config(
704-
sagemaker_session, image_uri, cpu_instance_type, output_kms_key, custom_bucket_name,
704+
sagemaker_session,
705+
image_uri,
706+
cpu_instance_type,
707+
output_kms_key,
708+
custom_bucket_name,
705709
):
706710
custom_code_location = f"s3://{custom_bucket_name}/customized-processing-code"
707711
script_processor = ScriptProcessor(

tests/unit/test_processing.py

+30-68
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def tar_and_upload_dir(session, bucket, s3_key_prefix, script, *args, **kwargs):
9999
def test_sklearn_processor_with_required_parameters(
100100
exists_mock, isfile_mock, botocore_resolver, sagemaker_session, sklearn_version
101101
):
102-
botocore_resolver.return_value.construct_endpoint.return_value = {
103-
"hostname": ECR_HOSTNAME
104-
}
102+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
105103
processor = SKLearnProcessor(
106104
role=ROLE,
107105
instance_type="ml.m4.xlarge",
@@ -127,9 +125,7 @@ def test_sklearn_processor_with_required_parameters(
127125
def test_sklearn_with_all_parameters(
128126
exists_mock, isfile_mock, botocore_resolver, sklearn_version, sagemaker_session
129127
):
130-
botocore_resolver.return_value.construct_endpoint.return_value = {
131-
"hostname": ECR_HOSTNAME
132-
}
128+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
133129

134130
processor = SKLearnProcessor(
135131
role=ROLE,
@@ -196,9 +192,7 @@ def test_local_mode_disables_local_code_by_default(localsession_mock):
196192
def test_sklearn_with_all_parameters_via_run_args(
197193
exists_mock, isfile_mock, botocore_resolver, sklearn_version, sagemaker_session
198194
):
199-
botocore_resolver.return_value.construct_endpoint.return_value = {
200-
"hostname": ECR_HOSTNAME
201-
}
195+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
202196

203197
processor = SKLearnProcessor(
204198
role=ROLE,
@@ -257,9 +251,7 @@ def test_sklearn_with_all_parameters_via_run_args(
257251
def test_sklearn_with_all_parameters_via_run_args_called_twice(
258252
exists_mock, isfile_mock, botocore_resolver, sklearn_version, sagemaker_session
259253
):
260-
botocore_resolver.return_value.construct_endpoint.return_value = {
261-
"hostname": ECR_HOSTNAME
262-
}
254+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
263255

264256
processor = SKLearnProcessor(
265257
role=ROLE,
@@ -324,9 +316,7 @@ def test_normalize_args_prepares_framework_processor(
324316
sagemaker_session,
325317
mock_fw_tar_and_upload_dir,
326318
):
327-
botocore_resolver.return_value.construct_endpoint.return_value = {
328-
"hostname": ECR_HOSTNAME
329-
}
319+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
330320

331321
processor = PyTorchProcessor(
332322
role=ROLE,
@@ -361,9 +351,7 @@ def test_normalize_args_prepares_framework_processor(
361351
assert code_inputs[0].source == "/".join(
362352
("s3:/", BUCKET_NAME, process_args["job_name"], "source/sourcedir.tar.gz")
363353
)
364-
entrypoint_inputs = list(
365-
filter(lambda i: i.input_name == "entrypoint", normalized_inputs)
366-
)
354+
entrypoint_inputs = list(filter(lambda i: i.input_name == "entrypoint", normalized_inputs))
367355
assert len(entrypoint_inputs) == 1
368356

369357
# Outputs should be as per raw:
@@ -390,9 +378,7 @@ def test_pytorch_processor_with_all_parameters(
390378
pytorch_training_py_version,
391379
mock_fw_tar_and_upload_dir,
392380
):
393-
botocore_resolver.return_value.construct_endpoint.return_value = {
394-
"hostname": ECR_HOSTNAME
395-
}
381+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
396382

397383
processor = PyTorchProcessor(
398384
role=ROLE,
@@ -437,12 +423,16 @@ def test_pytorch_processor_with_all_parameters(
437423
)
438424

439425
if version.parse(pytorch_training_version) < version.parse("1.2"):
440-
pytorch_image_uri = "520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-pytorch:{}-cpu-{}".format(
441-
pytorch_training_version, pytorch_training_py_version
426+
pytorch_image_uri = (
427+
"520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-pytorch:{}-cpu-{}".format(
428+
pytorch_training_version, pytorch_training_py_version
429+
)
442430
)
443431
else:
444-
pytorch_image_uri = "763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:{}-cpu-{}".format(
445-
pytorch_training_version, pytorch_training_py_version
432+
pytorch_image_uri = (
433+
"763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:{}-cpu-{}".format(
434+
pytorch_training_version, pytorch_training_py_version
435+
)
446436
)
447437

448438
expected_args["app_specification"]["ImageUri"] = pytorch_image_uri
@@ -461,9 +451,7 @@ def test_xgboost_processor_with_source_dir_bundle(
461451
xgboost_framework_version,
462452
mock_fw_tar_and_upload_dir,
463453
):
464-
botocore_resolver.return_value.construct_endpoint.return_value = {
465-
"hostname": ECR_HOSTNAME
466-
}
454+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
467455

468456
processor = XGBoostProcessor(
469457
role=ROLE,
@@ -506,9 +494,7 @@ def test_mxnet_processor_via_run_args(
506494
mxnet_training_py_version,
507495
mock_fw_tar_and_upload_dir,
508496
):
509-
botocore_resolver.return_value.construct_endpoint.return_value = {
510-
"hostname": ECR_HOSTNAME
511-
}
497+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
512498

513499
processor = MXNetProcessor(
514500
role=ROLE,
@@ -591,9 +577,7 @@ def test_tensorflow_processor_with_required_parameters(
591577
mock_fw_tar_and_upload_dir,
592578
):
593579

594-
botocore_resolver.return_value.construct_endpoint.return_value = {
595-
"hostname": ECR_HOSTNAME
596-
}
580+
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
597581

598582
if version.parse(tensorflow_training_version) <= version.parse("1.13.1"):
599583

@@ -637,19 +621,15 @@ def test_tensorflow_processor_with_required_parameters(
637621

638622

639623
@patch("os.path.exists", return_value=False)
640-
def test_script_processor_errors_with_nonexistent_local_code(
641-
exists_mock, sagemaker_session
642-
):
624+
def test_script_processor_errors_with_nonexistent_local_code(exists_mock, sagemaker_session):
643625
processor = _get_script_processor(sagemaker_session)
644626
with pytest.raises(ValueError):
645627
processor.run(code="/local/path/to/processing_code.py")
646628

647629

648630
@patch("os.path.exists", return_value=True)
649631
@patch("os.path.isfile", return_value=False)
650-
def test_script_processor_errors_with_code_directory(
651-
exists_mock, isfile_mock, sagemaker_session
652-
):
632+
def test_script_processor_errors_with_code_directory(exists_mock, isfile_mock, sagemaker_session):
653633
processor = _get_script_processor(sagemaker_session)
654634
with pytest.raises(ValueError):
655635
processor.run(code="/local/path/to/code")
@@ -715,16 +695,12 @@ def test_script_processor_works_with_file_code_url_scheme(
715695

716696
@patch("os.path.exists", return_value=True)
717697
@patch("os.path.isfile", return_value=True)
718-
def test_script_processor_works_with_s3_code_url(
719-
exists_mock, isfile_mock, sagemaker_session
720-
):
698+
def test_script_processor_works_with_s3_code_url(exists_mock, isfile_mock, sagemaker_session):
721699
processor = _get_script_processor(sagemaker_session)
722700
processor.run(code="s3://bucket/path/to/processing_code.py")
723701

724702
expected_args = _get_expected_args(processor._current_job_name)
725-
expected_args["inputs"][0]["S3Input"][
726-
"S3Uri"
727-
] = "s3://bucket/path/to/processing_code.py"
703+
expected_args["inputs"][0]["S3Input"]["S3Uri"] = "s3://bucket/path/to/processing_code.py"
728704
sagemaker_session.process.assert_called_with(**expected_args)
729705

730706

@@ -735,9 +711,7 @@ def test_script_processor_with_one_input(exists_mock, isfile_mock, sagemaker_ses
735711
processor.run(
736712
code="/local/path/to/processing_code.py",
737713
inputs=[
738-
ProcessingInput(
739-
source="/local/path/to/my/dataset/census.csv", destination="/data/"
740-
)
714+
ProcessingInput(source="/local/path/to/my/dataset/census.csv", destination="/data/")
741715
],
742716
)
743717

@@ -771,9 +745,7 @@ def test_script_processor_with_one_input(exists_mock, isfile_mock, sagemaker_ses
771745

772746
@patch("os.path.exists", return_value=True)
773747
@patch("os.path.isfile", return_value=True)
774-
def test_script_processor_with_required_parameters(
775-
exists_mock, isfile_mock, sagemaker_session
776-
):
748+
def test_script_processor_with_required_parameters(exists_mock, isfile_mock, sagemaker_session):
777749
processor = _get_script_processor(sagemaker_session)
778750

779751
processor.run(code="/local/path/to/processing_code.py")
@@ -784,9 +756,7 @@ def test_script_processor_with_required_parameters(
784756

785757
@patch("os.path.exists", return_value=True)
786758
@patch("os.path.isfile", return_value=True)
787-
def test_script_processor_with_all_parameters(
788-
exists_mock, isfile_mock, sagemaker_session
789-
):
759+
def test_script_processor_with_all_parameters(exists_mock, isfile_mock, sagemaker_session):
790760
processor = ScriptProcessor(
791761
role=ROLE,
792762
image_uri=CUSTOM_IMAGE_URI,
@@ -994,18 +964,14 @@ def test_processing_job_from_processing_arn(sagemaker_session):
994964

995965
assert isinstance(processing_job, ProcessingJob)
996966
assert [
997-
processing_input._to_request_dict()
998-
for processing_input in processing_job.inputs
967+
processing_input._to_request_dict() for processing_input in processing_job.inputs
999968
] == _get_describe_response_inputs_and_ouputs()["ProcessingInputs"]
1000969
assert [
1001-
processing_output._to_request_dict()
1002-
for processing_output in processing_job.outputs
970+
processing_output._to_request_dict() for processing_output in processing_job.outputs
1003971
] == _get_describe_response_inputs_and_ouputs()["ProcessingOutputConfig"]["Outputs"]
1004972
assert (
1005973
processing_job.output_kms_key
1006-
== _get_describe_response_inputs_and_ouputs()["ProcessingOutputConfig"][
1007-
"KmsKeyId"
1008-
]
974+
== _get_describe_response_inputs_and_ouputs()["ProcessingOutputConfig"]["KmsKeyId"]
1009975
)
1010976

1011977

@@ -1215,9 +1181,7 @@ def _get_data_outputs_all_parameters():
12151181
ProcessingOutput(
12161182
output_name="feature_store_output",
12171183
app_managed=True,
1218-
feature_store_output=FeatureStoreOutput(
1219-
feature_group_name="FeatureGroupName"
1220-
),
1184+
feature_store_output=FeatureStoreOutput(feature_group_name="FeatureGroupName"),
12211185
),
12221186
]
12231187

@@ -1514,7 +1478,5 @@ def _get_expected_args_all_parameters(job_name, code_location=None):
15141478
def _get_describe_response_inputs_and_ouputs():
15151479
return {
15161480
"ProcessingInputs": _get_expected_args_all_parameters(None)["inputs"],
1517-
"ProcessingOutputConfig": _get_expected_args_all_parameters(None)[
1518-
"output_config"
1519-
],
1481+
"ProcessingOutputConfig": _get_expected_args_all_parameters(None)["output_config"],
15201482
}

0 commit comments

Comments
 (0)