Skip to content

Commit cfc3c7b

Browse files
committed
improve tasks file
1 parent d064aa4 commit cfc3c7b

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

tasks.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from typing import Any
44
import shlex
55

6-
from invoke import Context, task
7-
from typing import Any
86

97

108
@task
@@ -39,14 +37,16 @@ def test(c: Context) -> None:
3937
result = c.run(command, warn=True, pty=False)
4038

4139
# Check the exit code and report accordingly.
42-
if result.ok:
40+
if result is not None and getattr(result, "ok", False):
4341
print("✔️ All tests passed.")
4442
else:
4543
print("❌ Some tests failed.")
46-
print(f"Exit code: {result.exited}")
47-
if result.stderr:
44+
exit_code = result.exited if result is not None and hasattr(result, "exited") else "Unknown"
45+
print(f"Exit code: {exit_code}")
46+
stderr_output = result.stderr if result is not None and hasattr(result, "stderr") else None
47+
if stderr_output:
4848
print("Error output:")
49-
print(result.stderr)
49+
print(stderr_output)
5050

5151

5252
@task
@@ -76,17 +76,16 @@ def docs(c: Context) -> None:
7676
result = c.run(command, warn=True, pty=False)
7777

7878
# Report on the result of the documentation build.
79-
if result.ok:
79+
if result is not None and getattr(result, "ok", False):
8080
print("✔️ Documentation built successfully.")
8181
else:
8282
print("❌ Documentation build failed.")
83-
print(f"Exit code: {result.exited}")
84-
if result.stderr:
83+
exit_code = result.exited if result is not None and hasattr(result, "exited") else "Unknown"
84+
print(f"Exit code: {exit_code}")
85+
stderr_output = result.stderr if result is not None and hasattr(result, "stderr") else None
86+
if stderr_output:
8587
print("Error output:")
86-
print(result.stderr)
87-
88-
from invoke import Context, task
89-
from typing import Any
88+
print(stderr_output)
9089

9190

9291
@task
@@ -114,14 +113,16 @@ def stubs(c: Context) -> None:
114113
result = c.run(command, warn=True, pty=False)
115114

116115
# Report on the outcome of stub generation.
117-
if result.ok:
116+
if result is not None and getattr(result, "ok", False):
118117
print("✔️ Type stubs generated successfully in 'stubs/'.")
119118
else:
120119
print("❌ Stub generation failed.")
121-
print(f"Exit code: {result.exited}")
122-
if result.stderr:
120+
exit_code = result.exited if result is not None and hasattr(result, "exited") else "Unknown"
121+
print(f"Exit code: {exit_code}")
122+
stderr_output = result.stderr if result is not None and hasattr(result, "stderr") else None
123+
if stderr_output:
123124
print("Error output:")
124-
print(result.stderr)
125+
print(stderr_output)
125126

126127

127128
@task
@@ -149,14 +150,16 @@ def build(c: Context) -> None:
149150
result = c.run(command, warn=True, pty=False)
150151

151152
# Report the result of the build process.
152-
if result.ok:
153+
if result is not None and getattr(result, "ok", False):
153154
print("✔️ Build completed successfully. Artifacts are in the 'dist/' directory.")
154155
else:
155156
print("❌ Build failed.")
156-
print(f"Exit code: {result.exited}")
157-
if result.stderr:
157+
exit_code = result.exited if result is not None and hasattr(result, "exited") else "Unknown"
158+
print(f"Exit code: {exit_code}")
159+
stderr_output = result.stderr if result is not None and hasattr(result, "stderr") else None
160+
if stderr_output:
158161
print("Error output:")
159-
print(result.stderr)
162+
print(stderr_output)
160163

161164
@task
162165
def publish(c: Context) -> None:
@@ -264,12 +267,14 @@ def gitpush(c: Context) -> None:
264267

265268
# Stage all changes.
266269
result_add = c.run("git add .", warn=True, pty=False)
267-
if not result_add.ok:
270+
if result_add is None or not getattr(result_add, "ok", False):
268271
print("❌ Failed to stage changes (git add).")
269-
print(f"Exit code: {result_add.exited}")
270-
if result_add.stderr:
272+
exit_code = result_add.exited if result_add is not None and hasattr(result_add, "exited") else "Unknown"
273+
print(f"Exit code: {exit_code}")
274+
stderr_output = result_add.stderr if result_add is not None and hasattr(result_add, "stderr") else None
275+
if stderr_output:
271276
print("Error output:")
272-
print(result_add.stderr)
277+
print(stderr_output)
273278
return
274279

275280
try:
@@ -288,23 +293,27 @@ def gitpush(c: Context) -> None:
288293
warn=True,
289294
pty=True,
290295
)
291-
if not result_commit.ok:
296+
if result_commit is None or not getattr(result_commit, "ok", False):
292297
print("❌ Commit failed.")
293-
print(f"Exit code: {result_commit.exited}")
294-
if result_commit.stderr:
298+
exit_code = getattr(result_commit, "exited", "Unknown")
299+
print(f"Exit code: {exit_code}")
300+
stderr_output = getattr(result_commit, "stderr", None)
301+
if stderr_output:
295302
print("Error output:")
296-
print(result_commit.stderr)
303+
print(stderr_output)
297304
return
298305

299306
# Push to the remote repository.
300307
result_push = c.run("git push", warn=True, pty=False)
301-
if result_push.ok:
308+
if result_push is not None and getattr(result_push, "ok", False):
302309
print("✔️ Changes pushed successfully.")
303310
else:
304311
print("❌ Push failed.")
305-
print(f"Exit code: {result_push.exited}")
306-
if result_push.stderr:
312+
exit_code = getattr(result_push, "exited", "Unknown") if result_push is not None else "Unknown"
313+
print(f"Exit code: {exit_code}")
314+
stderr_output = getattr(result_push, "stderr", None) if result_push is not None else None
315+
if stderr_output:
307316
print("Error output:")
308-
print(result_push.stderr)
317+
print(stderr_output)
309318
except KeyboardInterrupt:
310319
print("\nAborted by user.")

0 commit comments

Comments
 (0)