109
109
from abc import ABC , abstractmethod
110
110
from collections import OrderedDict
111
111
from subprocess import DEVNULL , PIPE
112
+ from typing import Optional
112
113
113
114
import SCons .Debug
114
115
import SCons .Errors
119
120
from SCons .Debug import logInstanceCreation
120
121
from SCons .Subst import SUBST_SIG , SUBST_RAW
121
122
from SCons .Util import is_String , is_List
123
+ from SCons .Util .sctyping import ExecutorType
122
124
123
125
class _null :
124
126
pass
@@ -530,7 +532,7 @@ def __call__(
530
532
show = _null ,
531
533
execute = _null ,
532
534
chdir = _null ,
533
- executor = None ,
535
+ executor : Optional [ ExecutorType ] = None ,
534
536
):
535
537
raise NotImplementedError
536
538
@@ -542,15 +544,15 @@ def no_batch_key(self, env, target, source):
542
544
543
545
batch_key = no_batch_key
544
546
545
- def genstring (self , target , source , env , executor = None ) -> str :
547
+ def genstring (self , target , source , env , executor : Optional [ ExecutorType ] = None ) -> str :
546
548
return str (self )
547
549
548
550
@abstractmethod
549
- def get_presig (self , target , source , env , executor = None ):
551
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
550
552
raise NotImplementedError
551
553
552
554
@abstractmethod
553
- def get_implicit_deps (self , target , source , env , executor = None ):
555
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
554
556
raise NotImplementedError
555
557
556
558
def get_contents (self , target , source , env ):
@@ -602,10 +604,10 @@ def presub_lines(self, env):
602
604
self .presub_env = None # don't need this any more
603
605
return lines
604
606
605
- def get_varlist (self , target , source , env , executor = None ):
607
+ def get_varlist (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
606
608
return self .varlist
607
609
608
- def get_targets (self , env , executor ):
610
+ def get_targets (self , env , executor : Optional [ ExecutorType ] ):
609
611
"""
610
612
Returns the type of targets ($TARGETS, $CHANGED_TARGETS) used
611
613
by this action.
@@ -659,7 +661,7 @@ def __call__(self, target, source, env,
659
661
show = _null ,
660
662
execute = _null ,
661
663
chdir = _null ,
662
- executor = None ):
664
+ executor : Optional [ ExecutorType ] = None ):
663
665
if not is_List (target ):
664
666
target = [target ]
665
667
if not is_List (source ):
@@ -743,10 +745,10 @@ def __call__(self, target, source, env,
743
745
# an ABC like parent ActionBase, but things reach in and use it. It's
744
746
# not just unittests or we could fix it up with a concrete subclass there.
745
747
746
- def get_presig (self , target , source , env , executor = None ):
748
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
747
749
raise NotImplementedError
748
750
749
- def get_implicit_deps (self , target , source , env , executor = None ):
751
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
750
752
raise NotImplementedError
751
753
752
754
@@ -1010,7 +1012,7 @@ def __str__(self) -> str:
1010
1012
return ' ' .join (map (str , self .cmd_list ))
1011
1013
return str (self .cmd_list )
1012
1014
1013
- def process (self , target , source , env , executor = None , overrides : bool = False ):
1015
+ def process (self , target , source , env , executor : Optional [ ExecutorType ] = None , overrides : bool = False ):
1014
1016
if executor :
1015
1017
result = env .subst_list (self .cmd_list , 0 , executor = executor , overrides = overrides )
1016
1018
else :
@@ -1031,7 +1033,7 @@ def process(self, target, source, env, executor=None, overrides: bool=False):
1031
1033
pass
1032
1034
return result , ignore , silent
1033
1035
1034
- def strfunction (self , target , source , env , executor = None , overrides : bool = False ):
1036
+ def strfunction (self , target , source , env , executor : Optional [ ExecutorType ] = None , overrides : bool = False ):
1035
1037
if self .cmdstr is None :
1036
1038
return None
1037
1039
if self .cmdstr is not _null :
@@ -1046,7 +1048,7 @@ def strfunction(self, target, source, env, executor=None, overrides: bool=False)
1046
1048
return ''
1047
1049
return _string_from_cmd_list (cmd_list [0 ])
1048
1050
1049
- def execute (self , target , source , env , executor = None ):
1051
+ def execute (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1050
1052
"""Execute a command action.
1051
1053
1052
1054
This will handle lists of commands as well as individual commands,
@@ -1108,7 +1110,7 @@ def execute(self, target, source, env, executor=None):
1108
1110
command = cmd_line )
1109
1111
return 0
1110
1112
1111
- def get_presig (self , target , source , env , executor = None ):
1113
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1112
1114
"""Return the signature contents of this action's command line.
1113
1115
1114
1116
This strips $(-$) and everything in between the string,
@@ -1123,7 +1125,7 @@ def get_presig(self, target, source, env, executor=None):
1123
1125
return env .subst_target_source (cmd , SUBST_SIG , executor = executor )
1124
1126
return env .subst_target_source (cmd , SUBST_SIG , target , source )
1125
1127
1126
- def get_implicit_deps (self , target , source , env , executor = None ):
1128
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1127
1129
"""Return the implicit dependencies of this action's command line."""
1128
1130
icd = env .get ('IMPLICIT_COMMAND_DEPENDENCIES' , True )
1129
1131
if is_String (icd ) and icd [:1 ] == '$' :
@@ -1145,7 +1147,7 @@ def get_implicit_deps(self, target, source, env, executor=None):
1145
1147
# lightweight dependency scanning.
1146
1148
return self ._get_implicit_deps_lightweight (target , source , env , executor )
1147
1149
1148
- def _get_implicit_deps_lightweight (self , target , source , env , executor ):
1150
+ def _get_implicit_deps_lightweight (self , target , source , env , executor : Optional [ ExecutorType ] ):
1149
1151
"""
1150
1152
Lightweight dependency scanning involves only scanning the first entry
1151
1153
in an action string, even if it contains &&.
@@ -1166,7 +1168,7 @@ def _get_implicit_deps_lightweight(self, target, source, env, executor):
1166
1168
res .append (env .fs .File (d ))
1167
1169
return res
1168
1170
1169
- def _get_implicit_deps_heavyweight (self , target , source , env , executor ,
1171
+ def _get_implicit_deps_heavyweight (self , target , source , env , executor : Optional [ ExecutorType ] ,
1170
1172
icd_int ):
1171
1173
"""
1172
1174
Heavyweight dependency scanning involves scanning more than just the
@@ -1234,7 +1236,7 @@ def __init__(self, generator, kw) -> None:
1234
1236
self .varlist = kw .get ('varlist' , ())
1235
1237
self .targets = kw .get ('targets' , '$TARGETS' )
1236
1238
1237
- def _generate (self , target , source , env , for_signature , executor = None ):
1239
+ def _generate (self , target , source , env , for_signature , executor : Optional [ ExecutorType ] = None ):
1238
1240
# ensure that target is a list, to make it easier to write
1239
1241
# generator functions:
1240
1242
if not is_List (target ):
@@ -1265,11 +1267,11 @@ def __str__(self) -> str:
1265
1267
def batch_key (self , env , target , source ):
1266
1268
return self ._generate (target , source , env , 1 ).batch_key (env , target , source )
1267
1269
1268
- def genstring (self , target , source , env , executor = None ) -> str :
1270
+ def genstring (self , target , source , env , executor : Optional [ ExecutorType ] = None ) -> str :
1269
1271
return self ._generate (target , source , env , 1 , executor ).genstring (target , source , env )
1270
1272
1271
1273
def __call__ (self , target , source , env , exitstatfunc = _null , presub = _null ,
1272
- show = _null , execute = _null , chdir = _null , executor = None ):
1274
+ show = _null , execute = _null , chdir = _null , executor : Optional [ ExecutorType ] = None ):
1273
1275
act = self ._generate (target , source , env , 0 , executor )
1274
1276
if act is None :
1275
1277
raise SCons .Errors .UserError (
@@ -1281,21 +1283,21 @@ def __call__(self, target, source, env, exitstatfunc=_null, presub=_null,
1281
1283
target , source , env , exitstatfunc , presub , show , execute , chdir , executor
1282
1284
)
1283
1285
1284
- def get_presig (self , target , source , env , executor = None ):
1286
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1285
1287
"""Return the signature contents of this action's command line.
1286
1288
1287
1289
This strips $(-$) and everything in between the string,
1288
1290
since those parts don't affect signatures.
1289
1291
"""
1290
1292
return self ._generate (target , source , env , 1 , executor ).get_presig (target , source , env )
1291
1293
1292
- def get_implicit_deps (self , target , source , env , executor = None ):
1294
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1293
1295
return self ._generate (target , source , env , 1 , executor ).get_implicit_deps (target , source , env )
1294
1296
1295
- def get_varlist (self , target , source , env , executor = None ):
1297
+ def get_varlist (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1296
1298
return self ._generate (target , source , env , 1 , executor ).get_varlist (target , source , env , executor )
1297
1299
1298
- def get_targets (self , env , executor ):
1300
+ def get_targets (self , env , executor : Optional [ ExecutorType ] ):
1299
1301
return self ._generate (None , None , env , 1 , executor ).get_targets (env , executor )
1300
1302
1301
1303
@@ -1341,22 +1343,22 @@ def _generate_cache(self, env):
1341
1343
raise SCons .Errors .UserError ("$%s value %s cannot be used to create an Action." % (self .var , repr (c )))
1342
1344
return gen_cmd
1343
1345
1344
- def _generate (self , target , source , env , for_signature , executor = None ):
1346
+ def _generate (self , target , source , env , for_signature , executor : Optional [ ExecutorType ] = None ):
1345
1347
return self ._generate_cache (env )
1346
1348
1347
1349
def __call__ (self , target , source , env , * args , ** kw ):
1348
1350
c = self .get_parent_class (env )
1349
1351
return c .__call__ (self , target , source , env , * args , ** kw )
1350
1352
1351
- def get_presig (self , target , source , env , executor = None ):
1353
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1352
1354
c = self .get_parent_class (env )
1353
1355
return c .get_presig (self , target , source , env )
1354
1356
1355
- def get_implicit_deps (self , target , source , env , executor = None ):
1357
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1356
1358
c = self .get_parent_class (env )
1357
1359
return c .get_implicit_deps (self , target , source , env )
1358
1360
1359
- def get_varlist (self , target , source , env , executor = None ):
1361
+ def get_varlist (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1360
1362
c = self .get_parent_class (env )
1361
1363
return c .get_varlist (self , target , source , env , executor )
1362
1364
@@ -1389,7 +1391,7 @@ def function_name(self):
1389
1391
except AttributeError :
1390
1392
return "unknown_python_function"
1391
1393
1392
- def strfunction (self , target , source , env , executor = None ):
1394
+ def strfunction (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1393
1395
if self .cmdstr is None :
1394
1396
return None
1395
1397
if self .cmdstr is not _null :
@@ -1430,7 +1432,7 @@ def __str__(self) -> str:
1430
1432
return str (self .execfunction )
1431
1433
return "%s(target, source, env)" % name
1432
1434
1433
- def execute (self , target , source , env , executor = None ):
1435
+ def execute (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1434
1436
exc_info = (None ,None ,None )
1435
1437
try :
1436
1438
if executor :
@@ -1471,14 +1473,14 @@ def execute(self, target, source, env, executor=None):
1471
1473
# more information about this issue.
1472
1474
del exc_info
1473
1475
1474
- def get_presig (self , target , source , env , executor = None ):
1476
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1475
1477
"""Return the signature contents of this callable action."""
1476
1478
try :
1477
1479
return self .gc (target , source , env )
1478
1480
except AttributeError :
1479
1481
return self .funccontents
1480
1482
1481
- def get_implicit_deps (self , target , source , env , executor = None ):
1483
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1482
1484
return []
1483
1485
1484
1486
class ListAction (ActionBase ):
@@ -1495,7 +1497,7 @@ def list_of_actions(x):
1495
1497
self .varlist = ()
1496
1498
self .targets = '$TARGETS'
1497
1499
1498
- def genstring (self , target , source , env , executor = None ) -> str :
1500
+ def genstring (self , target , source , env , executor : Optional [ ExecutorType ] = None ) -> str :
1499
1501
return '\n ' .join ([a .genstring (target , source , env ) for a in self .list ])
1500
1502
1501
1503
def __str__ (self ) -> str :
@@ -1505,15 +1507,15 @@ def presub_lines(self, env):
1505
1507
return SCons .Util .flatten_sequence (
1506
1508
[a .presub_lines (env ) for a in self .list ])
1507
1509
1508
- def get_presig (self , target , source , env , executor = None ):
1510
+ def get_presig (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1509
1511
"""Return the signature contents of this action list.
1510
1512
1511
1513
Simple concatenation of the signatures of the elements.
1512
1514
"""
1513
1515
return b"" .join ([bytes (x .get_contents (target , source , env )) for x in self .list ])
1514
1516
1515
1517
def __call__ (self , target , source , env , exitstatfunc = _null , presub = _null ,
1516
- show = _null , execute = _null , chdir = _null , executor = None ):
1518
+ show = _null , execute = _null , chdir = _null , executor : Optional [ ExecutorType ] = None ):
1517
1519
if executor :
1518
1520
target = executor .get_all_targets ()
1519
1521
source = executor .get_all_sources ()
@@ -1524,13 +1526,13 @@ def __call__(self, target, source, env, exitstatfunc=_null, presub=_null,
1524
1526
return stat
1525
1527
return 0
1526
1528
1527
- def get_implicit_deps (self , target , source , env , executor = None ):
1529
+ def get_implicit_deps (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1528
1530
result = []
1529
1531
for act in self .list :
1530
1532
result .extend (act .get_implicit_deps (target , source , env ))
1531
1533
return result
1532
1534
1533
- def get_varlist (self , target , source , env , executor = None ):
1535
+ def get_varlist (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1534
1536
result = OrderedDict ()
1535
1537
for act in self .list :
1536
1538
for var in act .get_varlist (target , source , env , executor ):
@@ -1596,7 +1598,7 @@ def subst_kw(self, target, source, env):
1596
1598
kw [key ] = self .subst (self .kw [key ], target , source , env )
1597
1599
return kw
1598
1600
1599
- def __call__ (self , target , source , env , executor = None ):
1601
+ def __call__ (self , target , source , env , executor : Optional [ ExecutorType ] = None ):
1600
1602
args = self .subst_args (target , source , env )
1601
1603
kw = self .subst_kw (target , source , env )
1602
1604
return self .parent .actfunc (* args , ** kw )
0 commit comments