@@ -400,22 +400,56 @@ def _escape_command(self, cmd):
400
400
return command
401
401
402
402
403
- class BaseEnvironment :
403
+ class BaseBuildEnvironment :
404
404
405
405
"""
406
- Base environment class.
406
+ Base build environment.
407
+
408
+ Base class for wrapping command execution for build steps. This class is in
409
+ charge of raising ``BuildAppError`` for internal application errors that
410
+ should be communicated to the user as a general unknown error and
411
+ ``BuildUserError`` that will be exposed to the user with a proper message
412
+ for them to debug by themselves since they are _not_ a Read the Docs issue.
407
413
408
- Used to run arbitrary commands outside a build.
414
+ :param project: Project that is being built
415
+ :param version: Project version that is being built
416
+ :param build: Build instance
417
+ :param environment: shell environment variables
418
+ :param record: whether or not record a build commands in the databse via
419
+ the API. The only case where we want this to be `False` is when
420
+ instantiating this class from `sync_repository_task` because it's a
421
+ background task that does not expose commands to the user.
409
422
"""
410
423
411
- def __init__ (self , project , environment = None ):
412
- # TODO: maybe we can remove this Project dependency also
424
+ def __init__ (
425
+ self ,
426
+ project = None ,
427
+ version = None ,
428
+ build = None ,
429
+ config = None ,
430
+ environment = None ,
431
+ record = True ,
432
+ ** kwargs ,
433
+ ):
413
434
self .project = project
414
435
self ._environment = environment or {}
415
436
self .commands = []
437
+ self .version = version
438
+ self .build = build
439
+ self .config = config
440
+ self .record = record
441
+
442
+ # TODO: remove these methods, we are not using LocalEnvironment anymore. We
443
+ # need to find a way for tests to not require this anymore
444
+ def __enter__ (self ):
445
+ return self
446
+
447
+ def __exit__ (self , exc_type , exc_value , tb ):
448
+ return
416
449
417
450
def record_command (self , command ):
418
- pass
451
+ if self .record :
452
+ command .save ()
419
453
420
454
def run (self , * cmd , ** kwargs ):
421
455
"""Shortcut to run command from environment."""
@@ -447,15 +481,13 @@ def run_command_class(
447
481
448
482
# Remove PATH from env, and set it to bin_path if it isn't passed in
449
483
environment = self ._environment .copy ()
450
- env_path = environment .pop ('BIN_PATH' , None )
451
- if 'bin_path' not in kwargs and env_path :
452
- kwargs ['bin_path' ] = env_path
453
- if 'environment' in kwargs :
454
- raise BuildAppError ('environment can\' t be passed in via commands.' )
455
- kwargs ['environment' ] = environment
456
-
457
- # ``build_env`` is passed as ``kwargs`` when it's called from a
458
- # ``*BuildEnvironment``
484
+ env_path = environment .pop ("BIN_PATH" , None )
485
+ if "bin_path" not in kwargs and env_path :
486
+ kwargs ["bin_path" ] = env_path
487
+ if "environment" in kwargs :
488
+ raise BuildAppError ("environment can't be passed in via commands." )
489
+ kwargs ["environment" ] = environment
490
+ kwargs ["build_env" ] = self
459
491
build_cmd = cls (cmd , ** kwargs )
460
492
build_cmd .run ()
461
493
@@ -497,82 +529,14 @@ def run_command_class(
497
529
return build_cmd
498
530
499
531
500
- class LocalEnvironment (BaseEnvironment ):
501
-
502
- # TODO: BuildCommand name doesn't make sense here, should be just Command
503
- command_class = BuildCommand
504
-
505
-
506
- class BuildEnvironment (BaseEnvironment ):
507
-
508
- """
509
- Base build environment.
510
-
511
- Base class for wrapping command execution for build steps. This class is in
512
- charge of raising ``BuildAppError`` for internal application errors that
513
- should be communicated to the user as a general unknown error and
514
- ``BuildUserError`` that will be exposed to the user with a proper message
515
- for them to debug by themselves since they are _not_ a Read the Docs issue.
516
-
517
- :param project: Project that is being built
518
- :param version: Project version that is being built
519
- :param build: Build instance
520
- :param environment: shell environment variables
521
- :param record: whether or not record a build commands in the databse via
522
- the API. The only case where we want this to be `False` is when
523
- instantiating this class from `sync_repository_task` because it's a
524
- background task that does not expose commands to the user.
525
- """
526
-
527
- def __init__ (
528
- self ,
529
- project = None ,
530
- version = None ,
531
- build = None ,
532
- config = None ,
533
- environment = None ,
534
- record = True ,
535
- ** kwargs ,
536
- ):
537
- super ().__init__ (project , environment )
538
- self .version = version
539
- self .build = build
540
- self .config = config
541
- self .record = record
542
-
543
- # TODO: remove these methods, we are not using LocalEnvironment anymore. We
544
- # need to find a way for tests to not require this anymore
545
- def __enter__ (self ):
546
- return self
547
-
548
- def __exit__ (self , exc_type , exc_value , tb ):
549
- return
550
-
551
- def record_command (self , command ):
552
- if self .record :
553
- command .save ()
554
-
555
- def run (self , * cmd , ** kwargs ):
556
- kwargs .update ({
557
- 'build_env' : self ,
558
- })
559
- return super ().run (* cmd , ** kwargs )
560
-
561
- def run_command_class (self , * cmd , ** kwargs ): # pylint: disable=arguments-differ
562
- kwargs .update ({
563
- 'build_env' : self ,
564
- })
565
- return super ().run_command_class (* cmd , ** kwargs )
566
-
567
-
568
- class LocalBuildEnvironment (BuildEnvironment ):
532
+ class LocalBuildEnvironment (BaseBuildEnvironment ):
569
533
570
534
"""Local execution build environment."""
571
535
572
536
command_class = BuildCommand
573
537
574
538
575
- class DockerBuildEnvironment (BuildEnvironment ):
539
+ class DockerBuildEnvironment (BaseBuildEnvironment ):
576
540
577
541
"""
578
542
Docker build environment, uses docker to contain builds.
0 commit comments