Skip to content

Commit 9746168

Browse files
committed
Fix broken output and add DRY_RUN for debugging
1 parent 5187847 commit 9746168

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

artefacts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from util import command_runner
1212

13+
DRY_RUN = os.getenv("DRY_RUN", False)
14+
1315
BIN_DIR = Path("artefacts/bin").resolve()
1416
LIB_DIR = Path("artefacts/lib").resolve()
1517
BUILD_DIR = Path("artefacts/build").resolve()
@@ -170,7 +172,7 @@ class Crate(Artefact):
170172
def cargo_toml(self):
171173
return f"{self.src}/Cargo.toml"
172174

173-
@command_runner(description="Building")
175+
@command_runner(description="Building", dry_run=DRY_RUN)
174176
def _cargo_build(self):
175177
return [
176178
"cargo",
@@ -267,7 +269,7 @@ def path(self) -> Path:
267269
def installed(self) -> bool:
268270
return self.path.exists()
269271

270-
@command_runner(description="Building")
272+
@command_runner(dry_run=DRY_RUN)
271273
def _xpy_install(self):
272274
return [
273275
f"{self.src}/x.py",

util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ def __init__(self, desc, output):
5555

5656

5757
def command_runner(
58-
description=None,
58+
description="",
5959
write_progress=True,
6060
unit="objects",
6161
steps=None,
6262
verbose=False,
6363
allow_failure=True,
64+
dry_run=False,
6465
):
6566

6667
def decorator(method):
@@ -70,7 +71,10 @@ def wrapper(self, *args, **kwargs):
7071
cmd = method(self, *args, **kwargs)
7172
desc = f"{description} {self.name}"
7273
with _temp_log_format(logger):
73-
logger.info(f"\n[RUNNING COMMAND]\n")
74+
if dry_run:
75+
logger.info(f"\n[DRY RUN]\n")
76+
else:
77+
logger.info(f"\n[RUNNING COMMAND]\n")
7478
if hasattr(self, "env"):
7579
for key, value in self.env.items():
7680
logging.info(f"{key}={value}")
@@ -87,6 +91,9 @@ def wrapper(self, *args, **kwargs):
8791
else "{desc}:{percentage:3.0f}%"
8892
)
8993

94+
if dry_run:
95+
return wrapper
96+
9097
with subprocess.Popen(
9198
cmd,
9299
stdout=subprocess.PIPE,
@@ -113,8 +120,6 @@ def wrapper(self, *args, **kwargs):
113120
pbar.update(1)
114121
update_timer(1)
115122
pbar.close()
116-
if write_progress:
117-
tqdm.write(f"✔ {desc}")
118123
if not allow_failure and proc.returncode != 0:
119124
raise CommandError(desc, "\n".join(buffer))
120125

0 commit comments

Comments
 (0)