@@ -285,14 +285,14 @@ def __init__(self, project, environment=None):
285
285
self .environment = environment or {}
286
286
self .commands = []
287
287
288
- def pre_run_command (self ):
288
+ def pre_run_command (self , kwargs ):
289
289
"""
290
290
Method to be called before the command is executed.
291
291
292
292
The command that will be executed can be accessed as
293
293
the last element of ``self.commands``.
294
294
"""
295
- pass
295
+ super ( BaseEnvironment , self ). pre_run_command ( kwargs )
296
296
297
297
def post_run_command (self ):
298
298
"""
@@ -301,7 +301,7 @@ def post_run_command(self):
301
301
The command that was executed can be accessed as
302
302
the last element of ``self.commands``.
303
303
"""
304
- pass
304
+ super ( BaseEnvironment , self ). post_run_command ()
305
305
306
306
def run (self , * cmd , ** kwargs ):
307
307
"""Shortcut to run command from environment."""
@@ -315,6 +315,7 @@ def run_command_class(self, cls, cmd, warn_only=False, **kwargs):
315
315
:param cmd: command (as a list) to execute in this environment
316
316
:param warn_only: don't raise an exception on command failure
317
317
"""
318
+ self .pre_run_command (kwargs )
318
319
# Remove PATH from env, and set it to bin_path if it isn't passed in
319
320
env_path = self .environment .pop ('BIN_PATH' , None )
320
321
if 'bin_path' not in kwargs and env_path :
@@ -326,7 +327,6 @@ def run_command_class(self, cls, cmd, warn_only=False, **kwargs):
326
327
# ``*BuildEnvironment``
327
328
build_cmd = cls (cmd , ** kwargs )
328
329
self .commands .append (build_cmd )
329
- self .pre_run_command ()
330
330
build_cmd .run ()
331
331
self .post_run_command ()
332
332
@@ -347,10 +347,21 @@ def run_command_class(self, cls, cmd, warn_only=False, **kwargs):
347
347
return build_cmd
348
348
349
349
350
- class LocalEnvironment ( BaseEnvironment ):
350
+ class EnvironmentRecordCommandMixin ( object ):
351
351
352
- # TODO: BuildCommand name doesn't make sense here, should be just Command
353
- command_class = BuildCommand
352
+ # record, force_success, warn_only
353
+ def pre_run_command (self , kwargs ):
354
+ # kwargs.update({
355
+ # 'build_env': self,
356
+ # })
357
+ self .record = kwargs .pop ('record' , True )
358
+ self .record_as_success = kwargs .pop ('record_as_success' , False )
359
+ if not self .record :
360
+ pass
361
+ # kwargs['warn_only'] = True
362
+ if self .record_as_success :
363
+ self .record = True
364
+ # kwargs['warn_only'] = True
354
365
355
366
def post_run_command (self ):
356
367
command = self .commands [- 1 ]
@@ -359,29 +370,14 @@ def post_run_command(self):
359
370
if self .record :
360
371
command .save ()
361
372
362
- def run (self , * cmd , ** kwargs ):
363
- self .record = kwargs .pop ('record' , False )
364
- self .record_as_success = kwargs .pop ('record_as_success' , False )
365
- if not self .record :
366
- kwargs ['warn_only' ] = True
367
- if self .record_as_success :
368
- self .record = True
369
- kwargs ['warn_only' ] = True
370
- return super (LocalEnvironment , self ).run (* cmd , ** kwargs )
371
373
372
- # record, force_success, warn_only
373
- def run_command_class (self , * cmd , ** kwargs ): # noqa
374
- self .record = kwargs .pop ('record' , False )
375
- self .record_as_success = kwargs .pop ('record_as_success' , False )
376
- if not self .record :
377
- kwargs ['warn_only' ] = True
378
- if self .record_as_success :
379
- self .record = True
380
- kwargs ['warn_only' ] = True
381
- return super (LocalEnvironment , self ).run_command_class (* cmd , ** kwargs )
374
+ class LocalEnvironment (BaseEnvironment , EnvironmentRecordCommandMixin ):
382
375
376
+ # TODO: BuildCommand name doesn't make sense here, should be just Command
377
+ command_class = BuildCommand
383
378
384
- class BuildEnvironment (BaseEnvironment ):
379
+
380
+ class BuildEnvironment (BaseEnvironment , EnvironmentRecordCommandMixin ):
385
381
386
382
"""
387
383
Base build environment.
@@ -459,39 +455,6 @@ def handle_exception(self, exc_type, exc_value, _):
459
455
self .failure = exc_value
460
456
return True
461
457
462
- def post_run_command (self ):
463
- command = self .commands [- 1 ]
464
- if self .record_as_success :
465
- command .exit_code = 0
466
- if self .record :
467
- command .save ()
468
-
469
- def run (self , * cmd , ** kwargs ):
470
- kwargs .update ({
471
- 'build_env' : self ,
472
- })
473
- self .record = kwargs .pop ('record' , self .record )
474
- self .record_as_success = kwargs .pop ('record_as_success' , False )
475
- if not self .record :
476
- kwargs ['warn_only' ] = True
477
- if self .record_as_success :
478
- self .record = True
479
- kwargs ['warn_only' ] = True
480
- return super (BuildEnvironment , self ).run (* cmd , ** kwargs )
481
-
482
- def run_command_class (self , * cmd , ** kwargs ): # noqa
483
- kwargs .update ({
484
- 'build_env' : self ,
485
- })
486
- self .record = kwargs .pop ('record' , True )
487
- self .record_as_success = kwargs .pop ('record_as_success' , False )
488
- if not self .record :
489
- kwargs ['warn_only' ] = True
490
- if self .record_as_success :
491
- self .record = True
492
- kwargs ['warn_only' ] = True
493
- return super (BuildEnvironment , self ).run_command_class (* cmd , ** kwargs )
494
-
495
458
@property
496
459
def successful (self ):
497
460
"""Is build completed, without top level failures or failing commands.""" # noqa
0 commit comments