Skip to content

Commit ca65df7

Browse files
committed
fix formatting
1 parent e4ebcb7 commit ca65df7

9 files changed

Lines changed: 108 additions & 58 deletions

File tree

dapi/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ def queues(self, system_id: str, verbose: bool = True) -> List[Any]:
287287
self._tapis, system_id, verbose=verbose
288288
)
289289

290-
def check_credentials(
291-
self, system_id: str, username: str = None
292-
) -> bool:
290+
def check_credentials(self, system_id: str, username: str = None) -> bool:
293291
"""Check whether TMS credentials exist for a user on a system.
294292
295293
Args:
@@ -407,8 +405,12 @@ def generate(
407405
*preview* is ``True``.
408406
"""
409407
return launcher_module.generate_sweep(
410-
command, sweep, directory,
411-
placeholder_style=placeholder_style, debug=debug, preview=preview,
408+
command,
409+
sweep,
410+
directory,
411+
placeholder_style=placeholder_style,
412+
debug=debug,
413+
preview=preview,
412414
)
413415

414416
def submit(

dapi/jobs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,7 @@ def list_jobs(
14121412
results = [j for j in results if getattr(j, "appId", None) == app_id]
14131413
if status:
14141414
results = [
1415-
j for j in results
1416-
if getattr(j, "status", "").upper() == status.upper()
1415+
j for j in results if getattr(j, "status", "").upper() == status.upper()
14171416
]
14181417
if verbose:
14191418
print(f"Found {len(results)} jobs.")
@@ -1451,8 +1450,13 @@ def list_jobs(
14511450

14521451
# Reorder: priority columns first
14531452
priority = [
1454-
"name", "uuid", "status", "appId", "appVersion",
1455-
"created_dt", "ended_dt",
1453+
"name",
1454+
"uuid",
1455+
"status",
1456+
"appId",
1457+
"appVersion",
1458+
"created_dt",
1459+
"ended_dt",
14561460
]
14571461
priority_present = [c for c in priority if c in df.columns]
14581462
remaining = [c for c in df.columns if c not in priority_present]

dapi/launcher.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def generate_sweep(
119119
dirpath.mkdir(parents=True, exist_ok=True)
120120

121121
# Write runsList.txt
122-
(dirpath / "runsList.txt").write_text(
123-
"\n".join(commands) + "\n", encoding="utf-8"
124-
)
122+
(dirpath / "runsList.txt").write_text("\n".join(commands) + "\n", encoding="utf-8")
125123

126124
# Write call_pylauncher.py
127125
if debug is not None:
@@ -130,10 +128,7 @@ def generate_sweep(
130128
f'pylauncher.ClassicLauncher("runsList.txt", debug="{debug}")\n'
131129
)
132130
else:
133-
script = (
134-
"import pylauncher\n"
135-
'pylauncher.ClassicLauncher("runsList.txt")\n'
136-
)
131+
script = "import pylauncher\n" 'pylauncher.ClassicLauncher("runsList.txt")\n'
137132
(dirpath / "call_pylauncher.py").write_text(script, encoding="utf-8")
138133

139134
return commands

dapi/systems.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def _resolve_username(t: Tapis, username: Optional[str] = None) -> str:
118118
return effective
119119

120120

121-
def check_credentials(
122-
t: Tapis, system_id: str, username: Optional[str] = None
123-
) -> bool:
121+
def check_credentials(t: Tapis, system_id: str, username: Optional[str] = None) -> bool:
124122
"""Check whether TMS credentials exist for a user on a Tapis system.
125123
126124
Args:
@@ -141,9 +139,7 @@ def check_credentials(
141139
effective_username = _resolve_username(t, username)
142140

143141
try:
144-
t.systems.checkUserCredential(
145-
systemId=system_id, userName=effective_username
146-
)
142+
t.systems.checkUserCredential(systemId=system_id, userName=effective_username)
147143
return True
148144
except (UnauthorizedError, NotFoundError):
149145
return False
@@ -194,12 +190,8 @@ def establish_credentials(
194190
authn_method = getattr(system_details, "defaultAuthnMethod", None)
195191
except BaseTapyException as e:
196192
if hasattr(e, "response") and e.response and e.response.status_code == 404:
197-
raise CredentialError(
198-
f"System '{system_id}' not found."
199-
) from e
200-
raise CredentialError(
201-
f"Failed to retrieve system '{system_id}': {e}"
202-
) from e
193+
raise CredentialError(f"System '{system_id}' not found.") from e
194+
raise CredentialError(f"Failed to retrieve system '{system_id}': {e}") from e
203195

204196
if authn_method != "TMS_KEYS":
205197
raise CredentialError(
@@ -268,9 +260,7 @@ def revoke_credentials(
268260
effective_username = _resolve_username(t, username)
269261

270262
try:
271-
t.systems.removeUserCredential(
272-
systemId=system_id, userName=effective_username
273-
)
263+
t.systems.removeUserCredential(systemId=system_id, userName=effective_username)
274264
if verbose:
275265
print(
276266
f"Credentials revoked for user '{effective_username}' "

examples/mpm/mpm.ipynb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,31 @@
825825
"id": "e074a3c3",
826826
"metadata": {},
827827
"outputs": [],
828-
"source": "# --- Translate Path with Verification ---\nds_path: str = \"/MyData/mpm-benchmarks/2d/uniaxial_stress/\"\nds_path_nonexistent: str = \"/MyData/this/path/does/not/exist/\"\n\ntry:\n # Translate and verify the existing path\n print(f\"\\nTranslating and verifying path: {ds_path}\")\n input_uri = ds.files.to_uri(ds_path, verify_exists=True)\n print(f\"Input Directory Tapis URI (verified): {input_uri}\")\n\n # Example: Try translating a non-existent path with verification (will raise error)\n print(f\"\\nTranslating and verifying non-existent path: {ds_path_nonexistent}\")\n input_uri_bad = ds.files.to_uri(\n ds_path_nonexistent, verify_exists=True\n )\n print(f\"This line should not be reached.\")\n\nexcept FileOperationError as e:\n print(f\"Error during path translation/verification: {e}\")\n # Decide how to handle the error (e.g., stop notebook, use default, etc.)\n # For this example, we'll stop if verification fails.\n raise SystemExit(\"Stopping notebook due to path verification error.\")\nexcept Exception as e:\n print(f\"An unexpected error occurred during path translation: {e}\")\n raise SystemExit(\"Stopping notebook due to unexpected path translation error.\")"
828+
"source": [
829+
"# --- Translate Path with Verification ---\n",
830+
"ds_path: str = \"/MyData/mpm-benchmarks/2d/uniaxial_stress/\"\n",
831+
"ds_path_nonexistent: str = \"/MyData/this/path/does/not/exist/\"\n",
832+
"\n",
833+
"try:\n",
834+
" # Translate and verify the existing path\n",
835+
" print(f\"\\nTranslating and verifying path: {ds_path}\")\n",
836+
" input_uri = ds.files.to_uri(ds_path, verify_exists=True)\n",
837+
" print(f\"Input Directory Tapis URI (verified): {input_uri}\")\n",
838+
"\n",
839+
" # Example: Try translating a non-existent path with verification (will raise error)\n",
840+
" print(f\"\\nTranslating and verifying non-existent path: {ds_path_nonexistent}\")\n",
841+
" input_uri_bad = ds.files.to_uri(ds_path_nonexistent, verify_exists=True)\n",
842+
" print(f\"This line should not be reached.\")\n",
843+
"\n",
844+
"except FileOperationError as e:\n",
845+
" print(f\"Error during path translation/verification: {e}\")\n",
846+
" # Decide how to handle the error (e.g., stop notebook, use default, etc.)\n",
847+
" # For this example, we'll stop if verification fails.\n",
848+
" raise SystemExit(\"Stopping notebook due to path verification error.\")\n",
849+
"except Exception as e:\n",
850+
" print(f\"An unexpected error occurred during path translation: {e}\")\n",
851+
" raise SystemExit(\"Stopping notebook due to unexpected path translation error.\")"
852+
]
829853
}
830854
],
831855
"metadata": {

examples/pylauncher_sweep.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"source": [
113113
"sweep = {\n",
114114
" \"ALPHA\": [0.3, 0.5, 3.7],\n",
115-
" \"BETA\": [1.1, 2.0, 3.0],\n",
115+
" \"BETA\": [1.1, 2.0, 3.0],\n",
116116
"}"
117117
]
118118
},
@@ -130,7 +130,7 @@
130130
"outputs": [],
131131
"source": [
132132
"ds.jobs.parametric_sweep.generate(\n",
133-
" 'python3 simulate.py --alpha ALPHA --beta BETA --output out_ALPHA_BETA',\n",
133+
" \"python3 simulate.py --alpha ALPHA --beta BETA --output out_ALPHA_BETA\",\n",
134134
" sweep,\n",
135135
" preview=True,\n",
136136
")"
@@ -150,7 +150,7 @@
150150
"outputs": [],
151151
"source": [
152152
"commands = ds.jobs.parametric_sweep.generate(\n",
153-
" 'python3 simulate.py --alpha ALPHA --beta BETA --output out_ALPHA_BETA',\n",
153+
" \"python3 simulate.py --alpha ALPHA --beta BETA --output out_ALPHA_BETA\",\n",
154154
" sweep,\n",
155155
" input_dir_generic,\n",
156156
" debug=\"host+job\",\n",
@@ -245,7 +245,7 @@
245245
"input_dir_opensees = os.path.expanduser(\"~/MyData/opensees_sweep/\")\n",
246246
"os.makedirs(input_dir_opensees, exist_ok=True)\n",
247247
"\n",
248-
"cantilever_script = '''\\\n",
248+
"cantilever_script = \"\"\"\\\n",
249249
"# Ex1a.Canti2D.Push — OpenSeesPy cantilever pushover\n",
250250
"# Adapted from Silvia Mazzoni & Frank McKenna, 2006/2020\n",
251251
"# Units: kip, inch, second\n",
@@ -317,7 +317,7 @@
317317
"ops.analyze(1000)\n",
318318
"\n",
319319
"print(f\"Done: NodalMass={NodalMass}, LCol={LCol}\")\n",
320-
"'''\n",
320+
"\"\"\"\n",
321321
"\n",
322322
"with open(os.path.join(input_dir_opensees, \"cantilever.py\"), \"w\") as f:\n",
323323
" f.write(cantilever_script)\n",

tests/jobs/test_list_jobs.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
from dapi.exceptions import JobMonitorError
99

1010

11-
def _make_job(uuid, name, status, app_id, app_version="1.0",
12-
created="2025-06-15T10:00:00.000Z",
13-
ended="2025-06-15T11:00:00.000Z",
14-
remote_started="2025-06-15T10:05:00.000Z",
15-
last_updated="2025-06-15T11:00:00.000Z"):
11+
def _make_job(
12+
uuid,
13+
name,
14+
status,
15+
app_id,
16+
app_version="1.0",
17+
created="2025-06-15T10:00:00.000Z",
18+
ended="2025-06-15T11:00:00.000Z",
19+
remote_started="2025-06-15T10:05:00.000Z",
20+
last_updated="2025-06-15T11:00:00.000Z",
21+
):
1622
"""Create a mock TapisResult job object."""
1723
job = Mock()
1824
job.__dict__ = {
@@ -37,8 +43,14 @@ def _make_job(uuid, name, status, app_id, app_version="1.0",
3743
_make_job("uuid-001", "matlab-run-1", "FINISHED", "matlab-r2023a"),
3844
_make_job("uuid-002", "opensees-run-1", "FINISHED", "opensees-mp-s3"),
3945
_make_job("uuid-003", "matlab-run-2", "FAILED", "matlab-r2023a"),
40-
_make_job("uuid-004", "mpm-run-1", "RUNNING", "mpm-s3",
41-
ended=None, remote_started="2025-06-15T10:10:00.000Z"),
46+
_make_job(
47+
"uuid-004",
48+
"mpm-run-1",
49+
"RUNNING",
50+
"mpm-s3",
51+
ended=None,
52+
remote_started="2025-06-15T10:10:00.000Z",
53+
),
4254
]
4355

4456

@@ -79,8 +91,14 @@ def test_combined_filters(self):
7991

8092
def test_datetime_columns_exist(self):
8193
df = list_jobs(self.t)
82-
for col in ["created_dt", "created_date", "ended_dt", "ended_date",
83-
"remoteStarted_dt", "lastUpdated_dt"]:
94+
for col in [
95+
"created_dt",
96+
"created_date",
97+
"ended_dt",
98+
"ended_date",
99+
"remoteStarted_dt",
100+
"lastUpdated_dt",
101+
]:
84102
self.assertIn(col, df.columns)
85103

86104
def test_datetime_nat_for_missing(self):
@@ -91,9 +109,16 @@ def test_datetime_nat_for_missing(self):
91109

92110
def test_priority_column_order(self):
93111
df = list_jobs(self.t)
94-
expected_first = ["name", "uuid", "status", "appId", "appVersion",
95-
"created_dt", "ended_dt"]
96-
actual_first = list(df.columns[:len(expected_first)])
112+
expected_first = [
113+
"name",
114+
"uuid",
115+
"status",
116+
"appId",
117+
"appVersion",
118+
"created_dt",
119+
"ended_dt",
120+
]
121+
actual_first = list(df.columns[: len(expected_first)])
97122
self.assertEqual(actual_first, expected_first)
98123

99124
def test_passes_limit_to_api(self):

tests/jobs/test_parametric_sweep.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ def test_empty_sweep_returns_base_command(self):
1717

1818
def test_single_param(self):
1919
with tempfile.TemporaryDirectory() as d:
20-
cmds = generate_sweep("python run.py --alpha ALPHA", {"ALPHA": [1, 2, 3]}, d)
20+
cmds = generate_sweep(
21+
"python run.py --alpha ALPHA", {"ALPHA": [1, 2, 3]}, d
22+
)
2123
self.assertEqual(len(cmds), 3)
2224
self.assertEqual(cmds[0], "python run.py --alpha 1")
2325
self.assertEqual(cmds[2], "python run.py --alpha 3")
2426

2527
def test_multi_param_cartesian_product(self):
2628
with tempfile.TemporaryDirectory() as d:
27-
cmds = generate_sweep("python run.py --a A --b B", {"A": [1, 2], "B": [10, 20]}, d)
29+
cmds = generate_sweep(
30+
"python run.py --a A --b B", {"A": [1, 2], "B": [10, 20]}, d
31+
)
2832
self.assertEqual(len(cmds), 4)
2933
self.assertIn("python run.py --a 1 --b 10", cmds)
3034
self.assertIn("python run.py --a 2 --b 20", cmds)
@@ -36,17 +40,23 @@ def test_deterministic_order(self):
3640

3741
def test_token_placeholder(self):
3842
with tempfile.TemporaryDirectory() as d:
39-
cmds = generate_sweep("echo ALPHA", {"ALPHA": [1]}, d, placeholder_style="token")
43+
cmds = generate_sweep(
44+
"echo ALPHA", {"ALPHA": [1]}, d, placeholder_style="token"
45+
)
4046
self.assertEqual(cmds, ["echo 1"])
4147

4248
def test_braces_placeholder(self):
4349
with tempfile.TemporaryDirectory() as d:
44-
cmds = generate_sweep("echo {ALPHA}", {"ALPHA": [1]}, d, placeholder_style="braces")
50+
cmds = generate_sweep(
51+
"echo {ALPHA}", {"ALPHA": [1]}, d, placeholder_style="braces"
52+
)
4553
self.assertEqual(cmds, ["echo 1"])
4654

4755
def test_env_vars_preserved(self):
4856
with tempfile.TemporaryDirectory() as d:
49-
cmds = generate_sweep('run --out "$WORK/$SLURM_JOB_ID" --a A', {"A": [1]}, d)
57+
cmds = generate_sweep(
58+
'run --out "$WORK/$SLURM_JOB_ID" --a A', {"A": [1]}, d
59+
)
5060
self.assertIn("$WORK", cmds[0])
5161
self.assertIn("$SLURM_JOB_ID", cmds[0])
5262

tests/systems/test_credentials.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ def test_raises_value_error_for_empty_system_id(self):
144144

145145
def test_uses_explicit_username(self):
146146
self.t.systems.checkUserCredential.side_effect = UnauthorizedError()
147-
establish_credentials(
148-
self.t, "frontera", username="otheruser", verbose=False
149-
)
147+
establish_credentials(self.t, "frontera", username="otheruser", verbose=False)
150148
self.t.systems.createUserCredential.assert_called_once_with(
151149
systemId="frontera", userName="otheruser", createTmsKeys=True
152150
)
@@ -159,7 +157,9 @@ def test_raises_credential_error_on_create_failure(self):
159157
with self.assertRaises(CredentialError):
160158
establish_credentials(self.t, "frontera", verbose=False)
161159

162-
def test_verbose_prints_skip_message(self, ):
160+
def test_verbose_prints_skip_message(
161+
self,
162+
):
163163
self.t.systems.checkUserCredential.return_value = Mock()
164164
# Should not raise; just prints a message
165165
establish_credentials(self.t, "frontera", verbose=True)

0 commit comments

Comments
 (0)