@@ -489,23 +489,33 @@ def str_int_to_timestamp(s):
489
489
################################################################################
490
490
# Building
491
491
492
- def patterns_list (patterns ):
492
+ def patterns_list (args , patterns ):
493
+ _filter = str .strip
494
+ if args .pattern_comments :
495
+ def _filter (x ):
496
+ x = x .strip ()
497
+ p = re .search ("^(.*?)[ \t ]*(?:[ \t ]{2}#.*)?$" , x ).group (1 ).rstrip ()
498
+ if p .startswith ('#' ):
499
+ return
500
+ if p :
501
+ return p
493
502
if isinstance (patterns , str ):
494
- return list (map (str . strip , patterns .splitlines ()))
503
+ return list (filter ( None , map (_filter , patterns .splitlines () )))
495
504
return patterns
496
505
497
506
498
507
class ZipContentFilter :
499
508
""""""
500
509
501
- def __init__ (self ):
510
+ def __init__ (self , args ):
511
+ self ._args = args
502
512
self ._rules = None
503
513
self ._excludes = set ()
504
514
self ._log = logging .getLogger ('zip' )
505
515
506
516
def compile (self , patterns ):
507
517
rules = []
508
- for p in patterns_list (patterns ):
518
+ for p in patterns_list (self . _args , patterns ):
509
519
self ._log .debug ("pattern '%s'" , p )
510
520
if p .startswith ('!' ):
511
521
r = re .compile (p [1 :])
@@ -571,7 +581,8 @@ def emit_file(fpath, opath):
571
581
class BuildPlanManager :
572
582
""""""
573
583
574
- def __init__ (self , log = None ):
584
+ def __init__ (self , args , log = None ):
585
+ self ._args = args
575
586
self ._source_paths = None
576
587
self ._log = log or logging .root
577
588
@@ -655,7 +666,7 @@ def commands_step(path, commands):
655
666
patterns = claim .get ('patterns' )
656
667
commands = claim .get ('commands' )
657
668
if patterns :
658
- step ('set:filter' , patterns_list (patterns ))
669
+ step ('set:filter' , patterns_list (self . _args , patterns ))
659
670
if commands :
660
671
commands_step (path , commands )
661
672
else :
@@ -891,7 +902,7 @@ def prepare_command(args):
891
902
recreate_missing_package = yesno_bool (args .recreate_missing_package )
892
903
docker = query .docker
893
904
894
- bpm = BuildPlanManager (log = log )
905
+ bpm = BuildPlanManager (args , log = log )
895
906
build_plan = bpm .plan (source_path , query )
896
907
897
908
if log .isEnabledFor (DEBUG2 ):
@@ -985,7 +996,7 @@ def build_command(args):
985
996
# Zip up the build plan and write it to the target filename.
986
997
# This will be used by the Lambda function as the source code package.
987
998
with ZipWriteStream (filename ) as zs :
988
- bpm = BuildPlanManager (log = log )
999
+ bpm = BuildPlanManager (args , log = log )
989
1000
bpm .execute (build_plan , zs , query )
990
1001
991
1002
os .utime (filename , ns = (timestamp , timestamp ))
@@ -1074,10 +1085,13 @@ def args_parser():
1074
1085
1075
1086
def main ():
1076
1087
ns = argparse .Namespace (
1088
+ pattern_comments = yesno_bool (os .environ .get (
1089
+ 'TF_LAMBDA_PACKAGE_PATTERN_COMMENTS' , False )),
1077
1090
recreate_missing_package = os .environ .get (
1078
1091
'TF_RECREATE_MISSING_LAMBDA_PACKAGE' , True ),
1079
1092
log_level = os .environ .get ('TF_LAMBDA_PACKAGE_LOG_LEVEL' , 'INFO' ),
1080
1093
)
1094
+
1081
1095
p = args_parser ()
1082
1096
args = p .parse_args (namespace = ns )
1083
1097
0 commit comments