42
42
default='yes'
43
43
)
44
44
)
45
- ...
46
- if env['x11'] == True:
45
+ env = Environment(variables=opts)
46
+ if env['x11'] is True:
47
47
dir = ... # search X11 in some standard places ...
48
48
env['x11'] = dir
49
49
if env['x11']:
50
50
... # build with x11 ...
51
51
"""
52
52
53
- from typing import Tuple , Callable
53
+ import os
54
+ from typing import Callable , Optional , Tuple
54
55
55
56
import SCons .Errors
56
57
60
61
DISABLE_STRINGS = ('0' , 'no' , 'false' , 'off' , 'disable' )
61
62
62
63
def _converter (val ):
63
- """ """
64
+ """Convert package variables.
65
+
66
+ Returns True or False if one of the recognized truthy or falsy
67
+ values is seen, else return the value unchanged (expected to
68
+ be a path string).
69
+ """
64
70
lval = val .lower ()
65
71
if lval in ENABLE_STRINGS :
66
72
return True
@@ -70,35 +76,45 @@ def _converter(val):
70
76
71
77
72
78
def _validator (key , val , env , searchfunc ) -> None :
73
- """ """
74
- # NB: searchfunc is currently undocumented and unsupported
75
- # TODO write validator, check for path
76
- import os
79
+ """Validate package variable for valid path.
77
80
81
+ Checks that if a path is given as the value, that pathname actually exists.
82
+ """
83
+ # NOTE: searchfunc is currently undocumented and unsupported
78
84
if env [key ] is True :
79
85
if searchfunc :
80
86
env [key ] = searchfunc (key , val )
87
+ # TODO: need to check path, or be sure searchfunc raises.
81
88
elif env [key ] and not os .path .exists (val ):
82
- raise SCons . Errors . UserError (
83
- 'Path does not exist for option %s: %s' % ( key , val ))
89
+ msg = f'Path does not exist for variable { key !r } : { val !r } '
90
+ raise SCons . Errors . UserError ( msg ) from None
84
91
85
92
86
- def PackageVariable (key , help , default , searchfunc = None ) -> Tuple [str , str , str , Callable , Callable ]:
93
+ # lint: W0622: Redefining built-in 'help' (redefined-builtin)
94
+ def PackageVariable (
95
+ key : str , help : str , default , searchfunc : Optional [Callable ] = None
96
+ ) -> Tuple [str , str , str , Callable , Callable ]:
87
97
"""Return a tuple describing a package list SCons Variable.
88
98
89
- The input parameters describe a 'package list' option . Returns
90
- a tuple including the correct converter and validator appended.
91
- The result is usable as input to :meth:`Add` .
99
+ The input parameters describe a 'package list' variable . Returns
100
+ a tuple with the correct converter and validator appended.
101
+ The result is usable as input to :meth:`~SCons.Variables.Variables. Add`.
92
102
93
- A 'package list' option may either be 'all', 'none' or a pathname
94
- string. This information is appended to *help*.
103
+ A 'package list' variable may either be a truthy string from
104
+ :const:`ENABLE_STRINGS`, a falsy string from
105
+ :const:`DISABLE_STRINGS`, or a pathname string.
106
+ This information is appended to *help* using only one string
107
+ each for truthy/falsy.
95
108
"""
96
109
# NB: searchfunc is currently undocumented and unsupported
97
- help = '\n ' .join (
98
- (help , '( yes | no | /path/to/%s )' % key ))
99
- return (key , help , default ,
100
- lambda k , v , e : _validator (k , v , e , searchfunc ),
101
- _converter )
110
+ help = '\n ' .join ((help , f'( yes | no | /path/to/{ key } )' ))
111
+ return (
112
+ key ,
113
+ help ,
114
+ default ,
115
+ lambda k , v , e : _validator (k , v , e , searchfunc ),
116
+ _converter ,
117
+ )
102
118
103
119
# Local Variables:
104
120
# tab-width:4
0 commit comments