Skip to content

Commit e449c7f

Browse files
rsareddy0329Roja Reddy Sareddy
andauthored
chore(codestyle): fix black formatting and unused import (#6394)
Apply black (26.3.1, line-length 100) to files that were committed unformatted, and remove an unused import, fixing the failing codestyle-doc-tests (black-check + flake8) on sagemaker-core, sagemaker-mlops, and sagemaker-train. - sagemaker-core: reformat workflow/job_config_document.py, workflow/pipeline_capture.py and three workflow unit tests. - sagemaker-mlops: reformat workflow/steps.py and two workflow tests. - sagemaker-train: reformat test_multi_turn_rl_trainer.py and drop the unused unittest.mock.PropertyMock import (flake8 F401). Formatting-only (black preserves the AST); the sole semantic change is the removal of the unused import. Co-authored-by: Roja Reddy Sareddy <rsareddy@amazon.com>
1 parent 5ca8000 commit e449c7f

9 files changed

Lines changed: 54 additions & 37 deletions

File tree

‎sagemaker-core/src/sagemaker/core/workflow/job_config_document.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
number or boolean reaches the service quoted. Parameterise string-valued
2929
fields only.
3030
"""
31+
3132
from __future__ import absolute_import
3233

3334
import json
@@ -67,9 +68,7 @@ def _placeholder(obj):
6768
if isinstance(obj, PipelineVariable):
6869
variables.append(obj)
6970
return "%s%d__" % (token_prefix, len(variables) - 1)
70-
raise TypeError(
71-
"Object of type %s is not JSON serializable" % obj.__class__.__name__
72-
)
71+
raise TypeError("Object of type %s is not JSON serializable" % obj.__class__.__name__)
7372

7473
document = json.dumps(job_config, default=_placeholder)
7574
if not variables:

‎sagemaker-core/src/sagemaker/core/workflow/pipeline_capture.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Shared capture paths for producers running under a ``PipelineSession``."""
14+
1415
from __future__ import absolute_import
1516

1617
from typing import Any, Dict, List, Optional
@@ -87,9 +88,11 @@ def capture_training_request(pipeline_session, create_args: Dict[str, Any]) -> N
8788
# Dict-form tags arrive in both shapes: lowercase keys from the SDK's own
8889
# tag builders, PascalCase from callers passing wire-form dicts through.
8990
request["Tags"] = [
90-
Tag(key=tag.get("key", tag.get("Key")), value=tag.get("value", tag.get("Value")))
91-
if isinstance(tag, dict)
92-
else tag
91+
(
92+
Tag(key=tag.get("key", tag.get("Key")), value=tag.get("value", tag.get("Value")))
93+
if isinstance(tag, dict)
94+
else tag
95+
)
9396
for tag in request["Tags"]
9497
]
9598
pipeline_session._intercept_create_request(serialize(request), None, "train")

‎sagemaker-core/tests/unit/workflow/test_job_config_document.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Tests for the ``JobConfigDocument`` encoder."""
14+
1415
from __future__ import absolute_import
1516

1617
import json

‎sagemaker-core/tests/unit/workflow/test_pipeline_capture.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Tests for the shared ``PipelineSession`` capture helpers."""
14+
1415
from __future__ import absolute_import
1516

1617
import json

‎sagemaker-core/tests/unit/workflow/test_retrieve_caller_name.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-- `ProcessingStep` expects `"run"` from here while interception is called with
2020
`"process"` -- so a step guard cannot be satisfied by the interception name alone.
2121
"""
22+
2223
from __future__ import absolute_import
2324

2425
import pytest

‎sagemaker-mlops/src/sagemaker/mlops/workflow/steps.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,9 @@ def arguments(self) -> RequestType:
871871
"""
872872
from sagemaker.core.workflow.execution_variables import ExecutionVariables
873873
from sagemaker.core.workflow.functions import Join
874-
from sagemaker.core.workflow.job_config_document import convert_job_config_document_to_string
874+
from sagemaker.core.workflow.job_config_document import (
875+
convert_job_config_document_to_string,
876+
)
875877
from sagemaker.core.workflow.utilities import execute_job_functions
876878
from sagemaker.core.workflow.utilities import _pipeline_config
877879

‎sagemaker-mlops/tests/integ/workflow/test_job_step_mtrl.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
resolves the execution-scoped output path inside `JobConfigDocument`, and
1515
creates the AgentRFT job from it. The execution is stopped once the job exists.
1616
"""
17+
1718
from __future__ import absolute_import
1819

1920
import json

‎sagemaker-mlops/tests/unit/workflow/test_job_step.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Unit tests for `StepTypeEnum.JOB` and `JobStep`."""
14+
1415
from __future__ import absolute_import
1516

1617
import pytest

‎sagemaker-train/tests/unit/train/test_multi_turn_rl_trainer.py‎

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
import warnings
5-
from unittest.mock import MagicMock, patch, PropertyMock
5+
from unittest.mock import MagicMock, patch
66

77
import pytest
88

@@ -1057,9 +1057,10 @@ def test_declaration_wins_over_the_model_trainer_branch(self):
10571057
def test_train_returns_step_arguments_and_submits_nothing(self):
10581058
session = self._pipeline_session()
10591059
trainer = self._make_trainer(sagemaker_session=session)
1060-
with self._pinned_name(), patch(
1061-
"sagemaker.train.multi_turn_rl_trainer.Job.create"
1062-
) as mock_create:
1060+
with (
1061+
self._pinned_name(),
1062+
patch("sagemaker.train.multi_turn_rl_trainer.Job.create") as mock_create,
1063+
):
10631064
step_args = trainer.train()
10641065
assert isinstance(step_args, _StepArguments)
10651066
assert step_args.caller_name == "create_job"
@@ -1137,9 +1138,7 @@ def test_wait_is_overridden_and_announced(self):
11371138
warnings.simplefilter("always")
11381139
step_args = trainer.train(wait=True)
11391140
assert step_args.func_kwargs.get("wait") is False
1140-
assert any(
1141-
"No Wait" in str(w.message) for w in caught
1142-
), [str(w.message) for w in caught]
1141+
assert any("No Wait" in str(w.message) for w in caught), [str(w.message) for w in caught]
11431142

11441143
# --- parity with the direct submission path -------------------------------
11451144

@@ -1151,11 +1150,13 @@ def _record(**kwargs):
11511150
recorded.update(kwargs)
11521151
return MagicMock()
11531152

1154-
with self._pinned_name(), patch(
1155-
"sagemaker.train.multi_turn_rl_trainer.Job.create", side_effect=_record
1156-
), patch(
1157-
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1158-
return_value=MagicMock(),
1153+
with (
1154+
self._pinned_name(),
1155+
patch("sagemaker.train.multi_turn_rl_trainer.Job.create", side_effect=_record),
1156+
patch(
1157+
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1158+
return_value=MagicMock(),
1159+
),
11591160
):
11601161
trainer.train(wait=False)
11611162
return recorded
@@ -1203,9 +1204,9 @@ def test_captured_request_matches_what_job_create_would_send(self):
12031204
}
12041205

12051206
session = self._pipeline_session()
1206-
captured = dict(self._capture(
1207-
self._make_trainer(sagemaker_session=session, tags=tags), session
1208-
).args)
1207+
captured = dict(
1208+
self._capture(self._make_trainer(sagemaker_session=session, tags=tags), session).args
1209+
)
12091210
# The document is captured as the raw config dict for JobStep to scope and
12101211
# encode; compare it to the direct route's config, and the rest to the wire.
12111212
document = captured.pop("JobConfigDocument")
@@ -1221,9 +1222,9 @@ def test_captured_request_matches_job_create_with_both_tag_forms(self):
12211222
self._make_trainer(sagemaker_session=self._direct_session(), tags=tags)
12221223
)
12231224
session = self._pipeline_session()
1224-
captured = dict(self._capture(
1225-
self._make_trainer(sagemaker_session=session, tags=tags), session
1226-
).args)
1225+
captured = dict(
1226+
self._capture(self._make_trainer(sagemaker_session=session, tags=tags), session).args
1227+
)
12271228
document = captured.pop("JobConfigDocument")
12281229
assert document == json.loads(direct["job_config_document"])
12291230
wire = self._job_create_wire_request(direct, direct["job_config_document"])
@@ -1256,7 +1257,9 @@ def test_document_describes_the_same_config_on_both_routes(self):
12561257
session = self._pipeline_session()
12571258
trainer = self._make_trainer(sagemaker_session=session)
12581259
captured = self._capture(trainer, session).args["JobConfigDocument"]
1259-
direct = self._make_trainer(sagemaker_session=self._direct_session())._build_job_config_document()
1260+
direct = self._make_trainer(
1261+
sagemaker_session=self._direct_session()
1262+
)._build_job_config_document()
12601263
assert isinstance(captured, dict)
12611264
assert captured == json.loads(direct)
12621265

@@ -1281,7 +1284,8 @@ def test_pipeline_variable_in_the_job_config_survives_capture(self):
12811284
def test_pipeline_variable_document_would_be_a_type_error_unencoded(self):
12821285
"""Locks the reason the encoder is needed rather than assuming it."""
12831286
trainer = self._make_trainer(
1284-
sagemaker_session=self._direct_session(), s3_output_path=ParameterString(name="OutputPath")
1287+
sagemaker_session=self._direct_session(),
1288+
s3_output_path=ParameterString(name="OutputPath"),
12851289
)
12861290
with pytest.raises(TypeError, match="not JSON serializable"):
12871291
trainer._build_job_config_document()
@@ -1292,11 +1296,13 @@ def test_direct_path_still_submits_and_returns_a_job(self):
12921296
"""Criterion: a normal session behaves exactly as before."""
12931297
job_handle = MagicMock()
12941298
trainer = self._make_trainer(sagemaker_session=self._direct_session())
1295-
with self._pinned_name(), patch(
1296-
"sagemaker.train.multi_turn_rl_trainer.Job.create"
1297-
) as mock_create, patch(
1298-
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1299-
return_value=job_handle,
1299+
with (
1300+
self._pinned_name(),
1301+
patch("sagemaker.train.multi_turn_rl_trainer.Job.create") as mock_create,
1302+
patch(
1303+
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1304+
return_value=job_handle,
1305+
),
13001306
):
13011307
returned = trainer.train(wait=False)
13021308
mock_create.assert_called_once()
@@ -1307,11 +1313,13 @@ def test_direct_path_still_submits_and_returns_a_job(self):
13071313
def test_direct_path_honours_wait(self):
13081314
job_handle = MagicMock()
13091315
trainer = self._make_trainer(sagemaker_session=self._direct_session())
1310-
with self._pinned_name(), patch(
1311-
"sagemaker.train.multi_turn_rl_trainer.Job.create"
1312-
), patch(
1313-
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1314-
return_value=job_handle,
1316+
with (
1317+
self._pinned_name(),
1318+
patch("sagemaker.train.multi_turn_rl_trainer.Job.create"),
1319+
patch(
1320+
"sagemaker.train.multi_turn_rl_trainer.AgentRFTJob.from_job",
1321+
return_value=job_handle,
1322+
),
13151323
):
13161324
trainer.train(wait=True)
13171325
job_handle.wait.assert_called_once()

0 commit comments

Comments
 (0)