Skip to content

Commit 4bfb29d

Browse files
committed
refactor: replace all .format() with f-strings
1 parent c20a3ee commit 4bfb29d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+327
-673
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
hooks:
1010
- id: flake8
1111
args:
12-
- --ignore=C901,E741
12+
- --ignore=C901,E741,E126
1313
- --max-line-length=130
1414
- smart_tests/
1515
- tests/
@@ -34,5 +34,6 @@ repos:
3434
- --aggressive
3535
- --experimental
3636
- --max-line-length=130
37+
- --ignore=E126
3738
- smart_tests/
3839
- tests/

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ dev-dependencies = [
4949

5050
[tool.poe.tasks]
5151
format = "/bin/bash -c 'isort -l 130 --balanced smart_tests/*.py tests/*.py && autopep8 --in-place --recursive --aggressive --experimental --max-line-length=130 --verbose smart_tests/ tests/'"
52-
lint = "flake8 --count --ignore=C901,E741,F401 --show-source --max-line-length=130 --statistics smart_tests/ tests/"
53-
lint-warn = "flake8 --count --exit-zero --max-complexity=15 --max-line-length=130 --statistics smart_tests/ tests/"
52+
lint = "flake8 --count --ignore=C901,E741,F401,E126 --show-source --max-line-length=130 --statistics smart_tests/ tests/"
53+
lint-warn = "flake8 --count --exit-zero --max-complexity=15 --max-line-length=130 --ignore=E126 --statistics smart_tests/ tests/"
5454
test = "python -m unittest"
5555
test-xml = "python -m test-runner"
5656
type = "mypy smart_tests tests"

smart_tests/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def main(
124124
if plugin_dir:
125125
for f in glob(join(plugin_dir, '*.py')):
126126
spec = importlib.util.spec_from_file_location(
127-
"smart_tests.plugins.{}".format(basename(f)[:-3]), f)
127+
f"smart_tests.plugins.{basename(f)[:-3]}", f)
128128
if spec is None:
129129
raise ImportError(f"Failed to create module spec for plugin: {f}")
130130
if spec.loader is None:

smart_tests/commands/inspect/subset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ def subset(
115115
rest = []
116116
client = LaunchableClient(app=app)
117117
try:
118-
res = client.request("get", "subset/{}".format(subset_id))
118+
res = client.request("get", f"subset/{subset_id}")
119119

120120
if res.status_code == HTTPStatus.NOT_FOUND:
121121
typer.echo(typer.style(
122-
"Subset {} not found. Check subset ID and try again.".format(subset_id), fg=typer.colors.YELLOW), err=True)
122+
f"Subset {subset_id} not found. Check subset ID and try again.", fg=typer.colors.YELLOW), err=True)
123123
sys.exit(1)
124124

125125
res.raise_for_status()

smart_tests/commands/record/attachment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def attachment(
3333
session_id = get_session_id(session, build, no_build, client)
3434

3535
for a in attachments:
36-
typer.echo("Sending {}".format(a))
36+
typer.echo(f"Sending {a}")
3737
with open(a, mode='rb') as f:
3838
res = client.request(
39-
"post", "{}/attachment".format(session_id), compress=True, payload=f,
40-
additional_headers={"Content-Disposition": "attachment;filename=\"{}\"".format(a)})
39+
"post", f"{session_id}/attachment", compress=True, payload=f,
40+
additional_headers={"Content-Disposition": f"attachment;filename=\"{a}\""})
4141
res.raise_for_status()
4242
except Exception as e:
4343
client.print_exception_and_recover(e)

smart_tests/commands/record/build.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ def compute_hash_and_branch(ws: List[Workspace]):
238238
kv = b.split('=')
239239
if len(kv) != 2:
240240
typer.secho(
241-
"Expected --branch REPO=BRANCHNAME but got {}".format(kv),
241+
f"Expected --branch REPO=BRANCHNAME but got {kv}",
242242
fg=typer.colors.YELLOW, err=True)
243243
raise typer.Exit(1)
244244

245245
if not ws_by_name.get(kv[0]):
246246
typer.secho(
247-
"Invalid repository name {} in a --branch option. ".format(kv[0]),
247+
f"Invalid repository name {kv[0]} in a --branch option. ",
248248
fg=typer.colors.YELLOW, err=True)
249249
# TODO: is there any reason this is not an error? for now erring on caution
250250
# sys.exit(1)
@@ -258,7 +258,7 @@ def compute_hash_and_branch(ws: List[Workspace]):
258258
except Exception as e:
259259
typer.secho(
260260
"Can't get commit hash for {}. Do you run command under git-controlled directory? "
261-
"If not, please set a directory use by --source option.".format(w.dir),
261+
"If not, please set a directory use by --source option.",
262262
fg=typer.colors.YELLOW, err=True)
263263
print(e, file=sys.stderr)
264264
raise typer.Exit(1)
@@ -276,7 +276,7 @@ def synthesize_workspaces() -> List[Workspace]:
276276
for name, hash in parsed_commits:
277277
if not commit_pattern.match(hash):
278278
typer.secho(
279-
"{}'s commit hash `{}` is invalid.".format(name, hash),
279+
f"{name}'s commit hash `{hash}` is invalid.",
280280
fg=typer.colors.YELLOW, err=True)
281281
raise typer.Exit(1)
282282

@@ -328,26 +328,16 @@ def compute_links():
328328
def report(ws: List[Workspace], build_id: str):
329329
org, workspace = get_org_workspace()
330330
typer.echo(
331-
"Launchable recorded build {} to workspace {}/{} with commits from {} {}:\n".format(
332-
build_name,
333-
org,
334-
workspace,
335-
len(ws),
336-
("repositories" if len(ws) > 1 else "repository"),
337-
)
338-
)
331+
f"Launchable recorded build {build_name} to workspace {org}/{workspace} with commits from {
332+
len(ws)} {
333+
'repositories' if len(ws) > 1 else 'repository'}:\n")
339334

340335
header = ["Name", "Path", "HEAD Commit"]
341336
rows = [[w.name, w.dir, w.commit_hash] for w in ws]
342337
typer.echo(tabulate(rows, header, tablefmt="github"))
343338
typer.echo(
344-
"\nVisit https://app.launchableinc.com/organizations/{organization}/workspaces/"
345-
"{workspace}/data/builds/{build_id} to view this build and its test sessions"
346-
.format(
347-
organization=org,
348-
workspace=workspace,
349-
build_id=build_id,
350-
))
339+
f"\nVisit https://app.launchableinc.com/organizations/{org}/workspaces/"
340+
f"{workspace}/data/builds/{build_id} to view this build and its test sessions")
351341

352342
# all the logics at the high level
353343
if len(commits) == 0:

smart_tests/commands/record/commit.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ def commit(
7979
raise e
8080
else:
8181
typer.secho(
82-
"Couldn't get commit history from `{}`. Do you run command root of git-controlled directory? "
83-
"If not, please set a directory use by --source option."
84-
.format(cwd),
82+
f"Couldn't get commit history from `{cwd}`. Do you run command root of git-controlled directory? "
83+
f"If not, please set a directory use by --source option.",
8584
fg=typer.colors.YELLOW, err=True)
8685
print(e)
8786

@@ -103,7 +102,7 @@ def exec_jar(source: str, max_days: int, app: Application, is_collect_message: b
103102
cygpath(jar_file_path),
104103
"ingest:commit",
105104
"-endpoint",
106-
"{}/intake/".format(base_url),
105+
f"{base_url}/intake/",
107106
"-max-days",
108107
str(max_days),
109108
"-scrub-pii"
@@ -151,7 +150,7 @@ def _build_proxy_option(https_proxy: str | None) -> List[str]:
151150

152151
options = []
153152
if proxy_url.hostname:
154-
options.append("-Dhttps.proxyHost={}".format(proxy_url.hostname))
153+
options.append(f"-Dhttps.proxyHost={proxy_url.hostname}")
155154
if proxy_url.port:
156-
options.append("-Dhttps.proxyPort={}".format(proxy_url.port))
155+
options.append(f"-Dhttps.proxyPort={proxy_url.port}")
157156
return options

smart_tests/commands/record/session.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def session(
130130
client = LaunchableClient(app=app, tracking_client=tracking_client)
131131

132132
if session:
133-
sub_path = "builds/{}/test_sessions/{}".format(build_name, session)
133+
sub_path = f"builds/{build_name}/test_sessions/{session}"
134134
try:
135135
res = client.request("get", sub_path)
136136

137137
if res.status_code != 404:
138-
msg = "This session name ({}) is already used. Please set another name.".format(session)
138+
msg = f"This session name ({session}) is already used. Please set another name."
139139
typer.secho(msg, fg=typer.colors.RED, err=True)
140140
tracking_client.send_error_event(
141141
event_name=Tracking.ErrorEvent.USER_ERROR,
@@ -170,13 +170,12 @@ def session(
170170
payload["links"] = _links
171171

172172
try:
173-
sub_path = "builds/{}/test_sessions".format(build_name)
173+
sub_path = f"builds/{build_name}/test_sessions"
174174
res = client.request("post", sub_path, payload=payload)
175175

176176
if res.status_code == HTTPStatus.NOT_FOUND:
177-
msg = "Build {} was not found." \
178-
"Make sure to run `launchable record build --build {}` before you run this command.".format(
179-
build_name, build_name)
177+
msg = f"Build {build_name} was not found." \
178+
f"Make sure to run `launchable record build --build {build_name}` before you run this command."
180179
tracking_client.send_error_event(
181180
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
182181
stack_trace=msg,
@@ -190,15 +189,15 @@ def session(
190189
if is_no_build:
191190
build_name = res.json().get("buildNumber", "")
192191
assert build_name is not None
193-
sub_path = "builds/{}/test_sessions".format(build_name)
192+
sub_path = f"builds/{build_name}/test_sessions"
194193

195194
if print_session:
196195
# what we print here gets captured and passed to `--session` in
197196
# later commands
198-
typer.echo("{}/{}".format(sub_path, session_id), nl=False)
197+
typer.echo(f"{sub_path}/{session_id}", nl=False)
199198

200199
# Return the session ID for use by calling functions
201-
return "{}/{}".format(sub_path, session_id)
200+
return f"{sub_path}/{session_id}"
202201

203202
except Exception as e:
204203
tracking_client.send_error_event(
@@ -231,22 +230,22 @@ def add_session_name(
231230
session_id: str,
232231
session_name: str,
233232
):
234-
sub_path = "builds/{}/test_sessions/{}".format(build_name, session_id)
233+
sub_path = f"builds/{build_name}/test_sessions/{session_id}"
235234
payload = {
236235
"name": session_name
237236
}
238237
res = client.request("patch", sub_path, payload=payload)
239238

240239
if res.status_code == HTTPStatus.NOT_FOUND:
241240
typer.secho(
242-
"Test session {} was not found. Record session may have failed.".format(session_id),
241+
f"Test session {session_id} was not found. Record session may have failed.",
243242
fg=typer.colors.YELLOW, err=True
244243
)
245244
sys.exit(1)
246245
if res.status_code == HTTPStatus.BAD_REQUEST:
247246
typer.secho(
248247
"You cannot use test session name {} since it is already used by other test session in your workspace. "
249-
"The record session is completed successfully without session name.".format(session_name),
248+
"The record session is completed successfully without session name.",
250249
fg=typer.colors.YELLOW, err=True)
251250
sys.exit(1)
252251

0 commit comments

Comments
 (0)