Skip to content

Commit

Permalink
no f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur-ob committed Apr 28, 2024
1 parent 01894b8 commit dafb6bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
19 changes: 9 additions & 10 deletions metaflow/click_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ def _method_sanity_check(
for supplied_k, supplied_v in kwargs.items():
if supplied_k not in possible_params:
raise ValueError(
f"Unknown argument: '{supplied_k}', "
f"possible args are: {list(possible_params.keys())}"
"Unknown argument: '%s', possible args are: %s"
% (supplied_k, list(possible_params.keys()))
)

try:
check_type(supplied_v, annotations[supplied_k])
except TypeCheckError:
raise TypeError(
f"Invalid type for '{supplied_k}', "
f"expected: '{annotations[supplied_k]}', "
f"default is '{defaults[supplied_k]}'"
"Invalid type for '%s', expected: '%s', default is '%s'"
% (supplied_k, annotations[supplied_k], defaults[supplied_k])
)

if supplied_k in possible_arg_params:
Expand Down Expand Up @@ -105,7 +104,7 @@ def _method_sanity_check(
(cli_name not in method_params["args"])
and (cli_name not in method_params["options"])
) and possible_v.required:
raise ValueError(f"Missing argument: {cli_name} is required.")
raise ValueError("Missing argument: %s is required." % cli_name)

return method_params

Expand Down Expand Up @@ -189,7 +188,7 @@ def from_cli(cls, flow_file: str, cli_collection: Callable) -> Callable:
class_dict[cmd_obj.name] = extract_command(cmd_obj, flow_parameters)
else:
raise RuntimeError(
f"Cannot handle {cmd_obj.name} of type {type(cmd_obj)}"
"Cannot handle %s of type %s" % (cmd_obj.name, type(cmd_obj))
)

to_return = type(flow_file, (MetaflowAPI,), class_dict)
Expand Down Expand Up @@ -252,10 +251,10 @@ def execute(self) -> List[str]:
for k, v in options.items():
if isinstance(v, list):
for i in v:
components.append(f"--{k}")
components.append("--%s" % k)
components.append(str(i))
else:
components.append(f"--{k}")
components.append("--%s" % k)
if v != "flag":
components.append(str(v))

Expand Down Expand Up @@ -307,7 +306,7 @@ def extract_group(cmd_obj: click.Group, flow_parameters: List[Parameter]) -> Cal
class_dict[sub_cmd_obj.name] = extract_command(sub_cmd_obj, flow_parameters)
else:
raise RuntimeError(
f"Cannot handle {sub_cmd_obj.name} of type {type(sub_cmd_obj)}"
"Cannot handle %s of type %s" % (sub_cmd_obj.name, type(sub_cmd_obj))
)

resulting_class = type(cmd_obj.name, (MetaflowAPI,), class_dict)
Expand Down
2 changes: 1 addition & 1 deletion metaflow/metaflow_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __getattr__(self, name: str):
else:
return command_attr
else:
raise AttributeError(f"Invalid attribute {name}")
raise AttributeError("Invalid attribute %s" % name)


class Runner(object):
Expand Down
23 changes: 14 additions & 9 deletions metaflow/subprocess_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ async def wait(
except asyncio.TimeoutError:
command_string = " ".join(self.command)
print(
f"Timeout: The process: '{command_string}' didn't complete within {timeout} seconds."
"Timeout: The process: '%s' didn't complete within %s seconds."
% (command_string, timeout)
)

async def run(self):
Expand All @@ -128,7 +129,7 @@ async def run(self):
self.run_called = True
return self.process
except Exception as e:
print(f"Error starting subprocess: {e}")
print("Error starting subprocess: %s" % e)
await self.cleanup()

async def stream_logs(
Expand All @@ -145,7 +146,8 @@ async def stream_logs(

if stream not in self.log_files:
raise ValueError(
f"No log file found for '{stream}', valid values are: {list(self.log_files.keys())}"
"No log file found for '%s', valid values are: %s"
% (stream, list(self.log_files.keys()))
)

log_file = self.log_files[stream]
Expand All @@ -167,7 +169,8 @@ async def stream_logs(
line = await asyncio.wait_for(f.readline(), timeout_per_line)
except asyncio.TimeoutError as e:
raise LogReadTimeoutError(
f"Timeout while reading a line from the log file for the stream: {stream}"
"Timeout while reading a line from the log file for the stream: %s"
% stream
) from e

# when we encounter an empty line
Expand Down Expand Up @@ -209,7 +212,8 @@ async def kill(self, termination_timeout: float = 5):
self.process.kill()
else:
print(
f"Process has already terminated with return code: {self.process.returncode}"
"Process has already terminated with return code: %s"
% self.process.returncode
)
else:
print("No process to kill.")
Expand Down Expand Up @@ -259,7 +263,7 @@ async def main():
interesting_position = position
break

print(f"ended streaming at: {interesting_position}")
print("ended streaming at: %s" % interesting_position)

# wait / do some other processing while the process runs in background
# if the process finishes before this sleep period, the streaming of logs
Expand All @@ -268,7 +272,8 @@ async def main():

# this blocks till the process completes unless we uncomment the `time.sleep` above..
print(
f"resuming streaming from: {interesting_position} while process is still running..."
"resuming streaming from: %s while process is still running..."
% interesting_position
)
async for position, line in command_obj.stream_logs(
stream="stdout", position=interesting_position
Expand All @@ -292,12 +297,12 @@ async def main():
# two parallel streams for stdout
tasks = [
command_obj.emit_logs(
stream="stdout", custom_logger=lambda x: print(f"[STREAM A]: {x}")
stream="stdout", custom_logger=lambda x: print("[STREAM A]: %s" % x)
),
# this can be another 'command_obj' too, in which case
# we stream logs from 2 different subprocesses in parallel :)
command_obj.emit_logs(
stream="stdout", custom_logger=lambda x: print(f"[STREAM B]: {x}")
stream="stdout", custom_logger=lambda x: print("[STREAM B]: %s" % x)
),
]
await asyncio.gather(*tasks)
Expand Down

0 comments on commit dafb6bf

Please sign in to comment.