Skip to content

Commit 876d15b

Browse files
knakadpengk19
authored andcommitted
change: enable logging-format-interpolation pylint check (aws#904)
1 parent 0ee1170 commit 876d15b

File tree

11 files changed

+49
-54
lines changed

11 files changed

+49
-54
lines changed

.pylintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ disable=
8383
too-many-instance-attributes,
8484
line-too-long, # We let Flake8 take care of this # TODO: Fix these and stop relying on flake8
8585
len-as-condition, # TODO: Enable this check once pylint 2.4.0 is released and consumed due to the fix in https://github.com/PyCQA/pylint/issues/2684
86-
logging-format-interpolation, # TODO: Fix logging so as to remove this.
8786
import-error, # TODO: Fix import errors
8887
logging-not-lazy, # TODO: Fix logging
8988
attribute-defined-outside-init, # TODO: Fix scope

src/sagemaker/amazon/amazon_estimator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ def record_set(self, train, labels=None, channel="train", encrypt=False):
195195
bucket, key_prefix = parsed_s3_url.netloc, parsed_s3_url.path
196196
key_prefix = key_prefix + "{}-{}/".format(type(self).__name__, sagemaker_timestamp())
197197
key_prefix = key_prefix.lstrip("/")
198-
logger.debug("Uploading to bucket {} and key_prefix {}".format(bucket, key_prefix))
198+
logger.debug("Uploading to bucket %s and key_prefix %s", bucket, key_prefix)
199199
manifest_s3_file = upload_numpy_to_s3_shards(
200200
self.train_instance_count, s3, bucket, key_prefix, train, labels, encrypt
201201
)
202-
logger.debug("Created manifest file {}".format(manifest_s3_file))
202+
logger.debug("Created manifest file %s", manifest_s3_file)
203203
return RecordSet(
204204
manifest_s3_file,
205205
num_records=train.shape[0],
@@ -279,7 +279,7 @@ def upload_numpy_to_s3_shards(
279279
shard_index_string = str(shard_index).zfill(len(str(len(shards))))
280280
file_name = "matrix_{}.pbr".format(shard_index_string)
281281
key = key_prefix + file_name
282-
logger.debug("Creating object {} in bucket {}".format(key, bucket))
282+
logger.debug("Creating object %s in bucket %s", key, bucket)
283283
s3.Object(bucket, key).put(Body=file, **extra_put_kwargs)
284284
uploaded_files.append(file_name)
285285
manifest_key = key_prefix + ".amazon.manifest"

src/sagemaker/cli/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def start(self):
108108
data_url = self.upload_training_data()
109109
estimator = self.create_estimator()
110110
estimator.fit(data_url)
111-
logger.debug("code location: {}".format(estimator.uploaded_code.s3_prefix))
111+
logger.debug("code location: %s", estimator.uploaded_code.s3_prefix)
112112
logger.debug(
113-
"model location: {}{}/output/model.tar.gz".format(
114-
estimator.output_path, estimator._current_job_name
115-
)
113+
"model location: %s%s/output/model.tar.gz",
114+
estimator.output_path,
115+
estimator._current_job_name,
116116
)

src/sagemaker/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def configure_logging(args):
134134
def main():
135135
args = parse_arguments(sys.argv[1:])
136136
configure_logging(args)
137-
logger.debug("args: {}".format(args))
137+
logger.debug("args: %s", args)
138138
args.func(args)
139139

140140

src/sagemaker/estimator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,8 @@ def start_new(cls, estimator, inputs):
687687
if isinstance(inputs, s3_input):
688688
if "InputMode" in inputs.config:
689689
logging.debug(
690-
"Selecting s3_input's input_mode ({}) for TrainingInputMode.".format(
691-
inputs.config["InputMode"]
692-
)
690+
"Selecting s3_input's input_mode (%s) for TrainingInputMode.",
691+
inputs.config["InputMode"],
693692
)
694693
train_args["input_mode"] = inputs.config["InputMode"]
695694

src/sagemaker/local/image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def serve(self, model_dir, environment):
172172
logger.info("serving")
173173

174174
self.container_root = self._create_tmp_folder()
175-
logger.info("creating hosting dir in {}".format(self.container_root))
175+
logger.info("creating hosting dir in %s", self.container_root)
176176

177177
volumes = self._prepare_serving_volumes(model_dir)
178178

@@ -424,7 +424,7 @@ def _generate_compose_file(self, command, additional_volumes=None, additional_en
424424

425425
docker_compose_path = os.path.join(self.container_root, DOCKER_COMPOSE_FILENAME)
426426
yaml_content = yaml.dump(content, default_flow_style=False)
427-
logger.info("docker compose file: \n{}".format(yaml_content))
427+
logger.info("docker compose file: \n%s", yaml_content)
428428
with open(docker_compose_path, "w") as f:
429429
f.write(yaml_content)
430430

@@ -445,7 +445,7 @@ def _compose(self, detached=False):
445445
if detached:
446446
command.append("-d")
447447

448-
logger.info("docker command: {}".format(" ".join(command)))
448+
logger.info("docker command: %s", " ".join(command))
449449
return command
450450

451451
def _create_docker_host(self, host, environment, optml_subdirs, command, volumes):
@@ -739,7 +739,7 @@ def _ecr_login_if_needed(boto_session, image):
739739

740740
def _pull_image(image):
741741
pull_image_command = ("docker pull %s" % image).strip()
742-
logger.info("docker command: {}".format(pull_image_command))
742+
logger.info("docker command: %s", pull_image_command)
743743

744744
subprocess.check_output(pull_image_command, shell=True)
745-
logger.info("image pulled: {}".format(image))
745+
logger.info("image pulled: %s", image)

src/sagemaker/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ def compile(
298298
self._is_compiled_model = True
299299
else:
300300
LOGGER.warning(
301-
"The intance type {} is not supported to deploy via SageMaker,"
302-
"please deploy the model on the device by yourself.".format(target_instance_family)
301+
"The instance type %s is not supported to deploy via SageMaker,"
302+
"please deploy the model manually.",
303+
target_instance_family,
303304
)
304305
return self
305306

src/sagemaker/rl/estimator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,8 @@ def _validate_images_args(cls, toolkit, toolkit_version, framework, image_name):
363363
if found_args:
364364
logger.warning(
365365
"Parameter `image_name` is specified, "
366-
"`{}` are going to be ignored when choosing the image.".format(
367-
"`, `".join(found_args)
368-
)
366+
"`%s` are going to be ignored when choosing the image.",
367+
"`, `".join(found_args),
369368
)
370369

371370
@classmethod

src/sagemaker/session.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def default_bucket(self):
206206
Bucket=default_bucket, CreateBucketConfiguration={"LocationConstraint": region}
207207
)
208208

209-
LOGGER.info("Created S3 bucket: {}".format(default_bucket))
209+
LOGGER.info("Created S3 bucket: %s", default_bucket)
210210
except ClientError as e:
211211
error_code = e.response["Error"]["Code"]
212212
message = e.response["Error"]["Message"]
@@ -343,8 +343,8 @@ def train( # noqa: C901
343343
if encrypt_inter_container_traffic:
344344
train_request["EnableInterContainerTrafficEncryption"] = encrypt_inter_container_traffic
345345

346-
LOGGER.info("Creating training-job with name: {}".format(job_name))
347-
LOGGER.debug("train request: {}".format(json.dumps(train_request, indent=4)))
346+
LOGGER.info("Creating training-job with name: %s", job_name)
347+
LOGGER.debug("train request: %s", json.dumps(train_request, indent=4))
348348
self.sagemaker_client.create_training_job(**train_request)
349349

350350
def compile_model(
@@ -379,7 +379,7 @@ def compile_model(
379379
if tags is not None:
380380
compilation_job_request["Tags"] = tags
381381

382-
LOGGER.info("Creating compilation-job with name: {}".format(job_name))
382+
LOGGER.info("Creating compilation-job with name: %s", job_name)
383383
self.sagemaker_client.create_compilation_job(**compilation_job_request)
384384

385385
def tune(
@@ -521,8 +521,8 @@ def tune(
521521
if encrypt_inter_container_traffic:
522522
tune_request["TrainingJobDefinition"]["EnableInterContainerTrafficEncryption"] = True
523523

524-
LOGGER.info("Creating hyperparameter tuning job with name: {}".format(job_name))
525-
LOGGER.debug("tune request: {}".format(json.dumps(tune_request, indent=4)))
524+
LOGGER.info("Creating hyperparameter tuning job with name: %s", job_name)
525+
LOGGER.debug("tune request: %s", json.dumps(tune_request, indent=4))
526526
self.sagemaker_client.create_hyper_parameter_tuning_job(**tune_request)
527527

528528
def stop_tuning_job(self, name):
@@ -535,18 +535,17 @@ def stop_tuning_job(self, name):
535535
ClientError: If an error occurs while trying to stop the hyperparameter tuning job.
536536
"""
537537
try:
538-
LOGGER.info("Stopping tuning job: {}".format(name))
538+
LOGGER.info("Stopping tuning job: %s", name)
539539
self.sagemaker_client.stop_hyper_parameter_tuning_job(HyperParameterTuningJobName=name)
540540
except ClientError as e:
541541
error_code = e.response["Error"]["Code"]
542542
# allow to pass if the job already stopped
543543
if error_code == "ValidationException":
544-
LOGGER.info("Tuning job: {} is already stopped or not running.".format(name))
544+
LOGGER.info("Tuning job: %s is already stopped or not running.", name)
545545
else:
546546
LOGGER.error(
547-
"Error occurred while attempting to stop tuning job: {}. Please try again.".format(
548-
name
549-
)
547+
"Error occurred while attempting to stop tuning job: %s. Please try again.",
548+
name,
550549
)
551550
raise
552551

@@ -608,8 +607,8 @@ def transform(
608607
if data_processing is not None:
609608
transform_request["DataProcessing"] = data_processing
610609

611-
LOGGER.info("Creating transform job with name: {}".format(job_name))
612-
LOGGER.debug("Transform request: {}".format(json.dumps(transform_request, indent=4)))
610+
LOGGER.info("Creating transform job with name: %s", job_name)
611+
LOGGER.debug("Transform request: %s", json.dumps(transform_request, indent=4))
613612
self.sagemaker_client.create_transform_job(**transform_request)
614613

615614
def create_model(
@@ -681,8 +680,8 @@ def create_model(
681680
if enable_network_isolation:
682681
create_model_request["EnableNetworkIsolation"] = True
683682

684-
LOGGER.info("Creating model with name: {}".format(name))
685-
LOGGER.debug("CreateModel request: {}".format(json.dumps(create_model_request, indent=4)))
683+
LOGGER.info("Creating model with name: %s", name)
684+
LOGGER.debug("CreateModel request: %s", json.dumps(create_model_request, indent=4))
686685

687686
try:
688687
self.sagemaker_client.create_model(**create_model_request)
@@ -694,7 +693,7 @@ def create_model(
694693
error_code == "ValidationException"
695694
and "Cannot create already existing model" in message
696695
):
697-
LOGGER.warning("Using already existing model: {}".format(name))
696+
LOGGER.warning("Using already existing model: %s", name)
698697
else:
699698
raise
700699

@@ -765,14 +764,14 @@ def create_model_package_from_algorithm(self, name, description, algorithm_arn,
765764
},
766765
}
767766
try:
768-
LOGGER.info("Creating model package with name: {}".format(name))
767+
LOGGER.info("Creating model package with name: %s", name)
769768
self.sagemaker_client.create_model_package(**request)
770769
except ClientError as e:
771770
error_code = e.response["Error"]["Code"]
772771
message = e.response["Error"]["Message"]
773772

774773
if error_code == "ValidationException" and "ModelPackage already exists" in message:
775-
LOGGER.warning("Using already existing model package: {}".format(name))
774+
LOGGER.warning("Using already existing model package: %s", name)
776775
else:
777776
raise
778777

@@ -833,7 +832,7 @@ def create_endpoint_config(
833832
Returns:
834833
str: Name of the endpoint point configuration created.
835834
"""
836-
LOGGER.info("Creating endpoint-config with name {}".format(name))
835+
LOGGER.info("Creating endpoint-config with name %s", name)
837836

838837
tags = tags or []
839838

@@ -872,7 +871,7 @@ def create_endpoint(self, endpoint_name, config_name, tags=None, wait=True):
872871
Returns:
873872
str: Name of the Amazon SageMaker ``Endpoint`` created.
874873
"""
875-
LOGGER.info("Creating endpoint with name {}".format(endpoint_name))
874+
LOGGER.info("Creating endpoint with name %s", endpoint_name)
876875

877876
tags = tags or []
878877

@@ -915,7 +914,7 @@ def delete_endpoint(self, endpoint_name):
915914
Args:
916915
endpoint_name (str): Name of the Amazon SageMaker ``Endpoint`` to delete.
917916
"""
918-
LOGGER.info("Deleting endpoint with name: {}".format(endpoint_name))
917+
LOGGER.info("Deleting endpoint with name: %s", endpoint_name)
919918
self.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
920919

921920
def delete_endpoint_config(self, endpoint_config_name):
@@ -924,7 +923,7 @@ def delete_endpoint_config(self, endpoint_config_name):
924923
Args:
925924
endpoint_config_name (str): Name of the Amazon SageMaker endpoint configuration to delete.
926925
"""
927-
LOGGER.info("Deleting endpoint configuration with name: {}".format(endpoint_config_name))
926+
LOGGER.info("Deleting endpoint configuration with name: %s", endpoint_config_name)
928927
self.sagemaker_client.delete_endpoint_config(EndpointConfigName=endpoint_config_name)
929928

930929
def delete_model(self, model_name):
@@ -934,7 +933,7 @@ def delete_model(self, model_name):
934933
model_name (str): Name of the Amazon SageMaker model to delete.
935934
936935
"""
937-
LOGGER.info("Deleting model with name: {}".format(model_name))
936+
LOGGER.info("Deleting model with name: %s", model_name)
938937
self.sagemaker_client.delete_model(ModelName=model_name)
939938

940939
def wait_for_job(self, job, poll=5):
@@ -1258,9 +1257,8 @@ def get_caller_identity_arn(self):
12581257
role = self.boto_session.client("iam").get_role(RoleName=role_name)["Role"]["Arn"]
12591258
except ClientError:
12601259
LOGGER.warning(
1261-
"Couldn't call 'get_role' to get Role ARN from role name {} to get Role path.".format(
1262-
role_name
1263-
)
1260+
"Couldn't call 'get_role' to get Role ARN from role name %s to get Role path.",
1261+
role_name,
12641262
)
12651263

12661264
return role

src/sagemaker/tensorflow/estimator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
)
4747
_SCRIPT_MODE_TENSORBOARD_WARNING = (
4848
"Tensorboard is not supported with script mode. You can run the following "
49-
"command: tensorboard --logdir {} --host localhost --port 6006 This can be "
49+
"command: tensorboard --logdir %s --host localhost --port 6006 This can be "
5050
"run from anywhere with access to the S3 URI used as the logdir."
5151
)
5252

@@ -173,7 +173,7 @@ def run(self):
173173
"""Run TensorBoard process."""
174174
port, tensorboard_process = self.create_tensorboard_process()
175175

176-
logger.info("TensorBoard 0.1.7 at http://localhost:{}".format(port))
176+
logger.info("TensorBoard 0.1.7 at http://localhost:%s", port)
177177
while not self.estimator.checkpoint_path:
178178
self.event.wait(1)
179179
with self._temporary_directory() as aws_sync_dir:
@@ -388,7 +388,7 @@ def fit_super():
388388
raise ValueError("Tensorboard is not supported with async fit")
389389

390390
if self._script_mode_enabled() and run_tensorboard_locally:
391-
logger.warning(_SCRIPT_MODE_TENSORBOARD_WARNING.format(self.model_dir))
391+
logger.warning(_SCRIPT_MODE_TENSORBOARD_WARNING, self.model_dir)
392392
fit_super()
393393
elif run_tensorboard_locally:
394394
tensorboard = Tensorboard(self)

src/sagemaker/tuner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,8 @@ def start_new(cls, tuner, inputs):
734734
if isinstance(inputs, s3_input):
735735
if "InputMode" in inputs.config:
736736
logging.debug(
737-
"Selecting s3_input's input_mode ({}) for TrainingInputMode.".format(
738-
inputs.config["InputMode"]
739-
)
737+
"Selecting s3_input's input_mode (%s) for TrainingInputMode.",
738+
inputs.config["InputMode"],
740739
)
741740
tuner_args["input_mode"] = inputs.config["InputMode"]
742741

0 commit comments

Comments
 (0)