Skip to content

Commit 9e74c0c

Browse files
authored
Merge branch 'modernize' into the-latest-commands
2 parents 4c74983 + 4bfb29d commit 9e74c0c

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

+325
-667
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
@@ -230,13 +230,13 @@ def compute_hash_and_branch(ws: List[Workspace]):
230230
kv = r.split('=')
231231
if len(kv) != 2:
232232
typer.secho(
233-
"Expected --repo-branch-map REPO=BRANCHNAME but got {}".format(kv),
233+
f"Expected --repo-branch-map REPO=BRANCHNAME but got {kv}",
234234
fg=typer.colors.YELLOW, err=True)
235235
raise typer.Exit(1)
236236

237237
if not ws_by_name.get(kv[0]):
238238
typer.secho(
239-
"Invalid repository name {} in a --repo-branch-map option. ".format(kv[0]),
239+
f"Invalid repository name {kv[0]} in a --repo-branch-map option. ",
240240
fg=typer.colors.YELLOW, err=True)
241241
# TODO: is there any reason this is not an error? for now erring on caution
242242
# sys.exit(1)
@@ -250,7 +250,7 @@ def compute_hash_and_branch(ws: List[Workspace]):
250250
except Exception as e:
251251
typer.secho(
252252
"Can't get commit hash for {}. Do you run command under git-controlled directory? "
253-
"If not, please set a directory use by --source option.".format(w.dir),
253+
"If not, please set a directory use by --source option.",
254254
fg=typer.colors.YELLOW, err=True)
255255
print(e, file=sys.stderr)
256256
raise typer.Exit(1)
@@ -268,7 +268,7 @@ def synthesize_workspaces() -> List[Workspace]:
268268
for name, hash in parsed_commits:
269269
if not commit_pattern.match(hash):
270270
typer.secho(
271-
"{}'s commit hash `{}` is invalid.".format(name, hash),
271+
f"{name}'s commit hash `{hash}` is invalid.",
272272
fg=typer.colors.YELLOW, err=True)
273273
raise typer.Exit(1)
274274

@@ -314,26 +314,16 @@ def compute_links():
314314
def report(ws: List[Workspace], build_id: str):
315315
org, workspace = get_org_workspace()
316316
typer.echo(
317-
"Launchable recorded build {} to workspace {}/{} with commits from {} {}:\n".format(
318-
build_name,
319-
org,
320-
workspace,
321-
len(ws),
322-
("repositories" if len(ws) > 1 else "repository"),
323-
)
324-
)
317+
f"Launchable recorded build {build_name} to workspace {org}/{workspace} with commits from {
318+
len(ws)} {
319+
'repositories' if len(ws) > 1 else 'repository'}:\n")
325320

326321
header = ["Name", "Path", "HEAD Commit"]
327322
rows = [[w.name, w.dir, w.commit_hash] for w in ws]
328323
typer.echo(tabulate(rows, header, tablefmt="github"))
329324
typer.echo(
330-
"\nVisit https://app.launchableinc.com/organizations/{organization}/workspaces/"
331-
"{workspace}/data/builds/{build_id} to view this build and its test sessions"
332-
.format(
333-
organization=org,
334-
workspace=workspace,
335-
build_id=build_id,
336-
))
325+
f"\nVisit https://app.launchableinc.com/organizations/{org}/workspaces/"
326+
f"{workspace}/data/builds/{build_id} to view this build and its test sessions")
337327

338328
# all the logics at the high level
339329
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
@@ -126,12 +126,12 @@ def session(
126126
client = LaunchableClient(app=app, tracking_client=tracking_client)
127127

128128
if session:
129-
sub_path = "builds/{}/test_sessions/{}".format(build_name, session)
129+
sub_path = f"builds/{build_name}/test_sessions/{session}"
130130
try:
131131
res = client.request("get", sub_path)
132132

133133
if res.status_code != 404:
134-
msg = "This session name ({}) is already used. Please set another name.".format(session)
134+
msg = f"This session name ({session}) is already used. Please set another name."
135135
typer.secho(msg, fg=typer.colors.RED, err=True)
136136
tracking_client.send_error_event(
137137
event_name=Tracking.ErrorEvent.USER_ERROR,
@@ -165,13 +165,12 @@ def session(
165165
payload["links"] = _links
166166

167167
try:
168-
sub_path = "builds/{}/test_sessions".format(build_name)
168+
sub_path = f"builds/{build_name}/test_sessions"
169169
res = client.request("post", sub_path, payload=payload)
170170

171171
if res.status_code == HTTPStatus.NOT_FOUND:
172-
msg = "Build {} was not found." \
173-
"Make sure to run `launchable record build --build {}` before you run this command.".format(
174-
build_name, build_name)
172+
msg = f"Build {build_name} was not found." \
173+
f"Make sure to run `launchable record build --build {build_name}` before you run this command."
175174
tracking_client.send_error_event(
176175
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
177176
stack_trace=msg,
@@ -185,15 +184,15 @@ def session(
185184
if is_no_build:
186185
build_name = res.json().get("buildNumber", "")
187186
assert build_name is not None
188-
sub_path = "builds/{}/test_sessions".format(build_name)
187+
sub_path = f"builds/{build_name}/test_sessions"
189188

190189
if print_session:
191190
# what we print here gets captured and passed to `--session` in
192191
# later commands
193-
typer.echo("{}/{}".format(sub_path, session_id), nl=False)
192+
typer.echo(f"{sub_path}/{session_id}", nl=False)
194193

195194
# Return the session ID for use by calling functions
196-
return "{}/{}".format(sub_path, session_id)
195+
return f"{sub_path}/{session_id}"
197196

198197
except Exception as e:
199198
tracking_client.send_error_event(
@@ -226,22 +225,22 @@ def add_session_name(
226225
session_id: str,
227226
session_name: str,
228227
):
229-
sub_path = "builds/{}/test_sessions/{}".format(build_name, session_id)
228+
sub_path = f"builds/{build_name}/test_sessions/{session_id}"
230229
payload = {
231230
"name": session_name
232231
}
233232
res = client.request("patch", sub_path, payload=payload)
234233

235234
if res.status_code == HTTPStatus.NOT_FOUND:
236235
typer.secho(
237-
"Test session {} was not found. Record session may have failed.".format(session_id),
236+
f"Test session {session_id} was not found. Record session may have failed.",
238237
fg=typer.colors.YELLOW, err=True
239238
)
240239
sys.exit(1)
241240
if res.status_code == HTTPStatus.BAD_REQUEST:
242241
typer.secho(
243242
"You cannot use test session name {} since it is already used by other test session in your workspace. "
244-
"The record session is completed successfully without session name.".format(session_name),
243+
"The record session is completed successfully without session name.",
245244
fg=typer.colors.YELLOW, err=True)
246245
sys.exit(1)
247246

0 commit comments

Comments
 (0)