Skip to content

Commit 64dd214

Browse files
authored
Merge pull request #622 from jkloetzke/upper-case-keywords
input: custom properties must not start with lower case
2 parents d7af1be + 6d4cc93 commit 64dd214

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

contrib/plugins/path-fmt.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Sample plugin to modify path name calculation
22
#
33
# This plugin introduces two new properties to a recipe:
4-
# - checkoutDir: optional string that is appended to the source directory
5-
# - platform: optional string that is appenden to the build and dist directories
4+
# - CheckoutDir: optional string that is appended to the source directory
5+
# - Platform: optional string that is appenden to the build and dist directories
66

77
from os.path import join
88
from bob.errors import ParseError
99
from bob.input import PluginState, PluginProperty
1010

1111
def commonFormatter(step, states):
12-
s = states['pathFmt']
12+
s = states['PathFmt']
1313
if step.isCheckoutStep():
1414
base = step.getPackage().getRecipe().getName()
1515
ext = s.getCheckoutDir()
@@ -35,15 +35,15 @@ def __init__(self):
3535
self.__platformDir = None
3636

3737
def onEnter(self, env, properties):
38-
# checkoutDir is always taken from current recipe
39-
self.__checkoutDir = properties['checkoutDir'].getValue()
38+
# CheckoutDir is always taken from current recipe
39+
self.__checkoutDir = properties['CheckoutDir'].getValue()
4040
if self.__checkoutDir is not None:
41-
self.__checkoutDir = env.substitute(self.__checkoutDir, "checkoutDir")
41+
self.__checkoutDir = env.substitute(self.__checkoutDir, "CheckoutDir")
4242

43-
# platform is passed down to dependencies
44-
platform = properties['platform']
43+
# Platform is passed down to dependencies
44+
platform = properties['Platform']
4545
if platform.isPresent():
46-
self.__platformDir = env.substitute(platform.getValue(), "platform")
46+
self.__platformDir = env.substitute(platform.getValue(), "Platform")
4747

4848
def getCheckoutDir(self):
4949
return self.__checkoutDir
@@ -66,10 +66,10 @@ def validate(data):
6666
'jenkinsNameFormatter' : jenkinsFormatter
6767
},
6868
'properties' : {
69-
"checkoutDir" : StringProperty,
70-
"platform" : StringProperty
69+
"CheckoutDir" : StringProperty,
70+
"Platform" : StringProperty
7171
},
7272
'state' : {
73-
"pathFmt" : PathFmtState
73+
"PathFmt" : PathFmtState
7474
}
7575
}

doc/manual/extending.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,13 @@ The following example shows two trivial properties::
365365
manifest = {
366366
'apiVersion' : "0.21",
367367
'properties' : {
368-
"checkoutDir" : StringProperty,
369-
"platform" : StringProperty
368+
"CheckoutDir" : StringProperty,
369+
"Platform" : StringProperty
370370
},
371371
}
372372

373-
The above example defines two new keywords in recipes: ``checkoutDir`` and
374-
``platform``. As verified by the ``validate`` method they need to be strings.
373+
The above example defines two new keywords in recipes: ``CheckoutDir`` and
374+
``Platform``. As verified by the ``validate`` method, they need to be strings.
375375
Because :func:`bob.input.PluginProperty.inherit` was not overridden, the recipe
376376
and higher priority classes will simply replace the value of lower priority
377377
classes. Other plugin extensions can query the value of a property by calling
@@ -383,6 +383,12 @@ If custom properties need to be propagated in the recipe dependency hierarchy,
383383
a *property state tracker* is required. A state tracker is a class that is
384384
invoked on every step when walking the dependency tree to instantiate the
385385
packages. The state tracker thus has the responsibility to calculate the final
386-
values associated with the properties for every package. Like properties there
386+
values associated with the properties for every package. Like properties, there
387387
can be more than one state tracker. Any state tracker provided by a plugin must
388388
be derived from :class:`bob.input.PluginState`.
389+
390+
It is not possible to re-define already existing recipe properties. This
391+
applies both to Bob built-in properties as well as properties defined by other
392+
plugins. Because Bob is expected to define new settings in the future, a
393+
plugin defined properties must not start with a lower case letter. These names
394+
are reserved for Bob.

pym/bob/input.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,8 @@ def __loadPlugin(self, mangledName, fileName, name):
34703470
for (i,j) in properties.items():
34713471
if not isinstance(i, str):
34723472
raise ParseError("Plugin '"+fileName+"': property name must be a string!")
3473+
if i[:1].islower():
3474+
raise ParseError(f"Plugin '{fileName}': property '{i}' must not start lower case!")
34733475
if not issubclass(j, PluginProperty):
34743476
raise ParseError("Plugin '"+fileName+"': property '" +i+"' has wrong type!")
34753477
if i in self.__properties:
@@ -3482,8 +3484,8 @@ def __loadPlugin(self, mangledName, fileName, name):
34823484
for (i,j) in states.items():
34833485
if not isinstance(i, str):
34843486
raise ParseError("Plugin '"+fileName+"': state tracker name must be a string!")
3485-
if i in ["environment", "tools", "result", "deps", "sandbox"]:
3486-
raise ParseError("Plugin '"+fileName+"': state tracker has reserved name!")
3487+
if i[:1].islower():
3488+
raise ParseError(f"Plugin '{fileName}': state tracker '{i}' must not start lower case!")
34873489
if not issubclass(j, PluginState):
34883490
raise ParseError("Plugin '"+fileName+"': state tracker '" +i+"' has wrong type!")
34893491
if i in self.__states:

test/black-box/plugin-states/plugins/path-fmt.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Sample plugin to modify path name calculation
22
#
33
# This plugin introduces two new properties to a recipe:
4-
# - checkoutDir: optional string that is appended to the source directory
5-
# - platform: optional string that is appenden to the build and dist directories
4+
# - CheckoutDir: optional string that is appended to the source directory
5+
# - Platform: optional string that is appenden to the build and dist directories
66

77
from os.path import join
88
from bob.errors import ParseError
99
from bob.input import PluginState, PluginProperty
1010

1111
def commonFormatter(step, states):
12-
s = states['pathFmt']
12+
s = states['PathFmt']
1313
if step.isCheckoutStep():
1414
base = step.getPackage().getRecipe().getName()
1515
ext = s.getCheckoutDir()
@@ -35,15 +35,15 @@ def __init__(self):
3535
self.__platformDir = None
3636

3737
def onEnter(self, env, properties):
38-
# checkoutDir is always taken from current recipe
39-
self.__checkoutDir = properties['checkoutDir'].getValue()
38+
# CheckoutDir is always taken from current recipe
39+
self.__checkoutDir = properties['CheckoutDir'].getValue()
4040
if self.__checkoutDir is not None:
41-
self.__checkoutDir = env.substitute(self.__checkoutDir, "checkoutDir")
41+
self.__checkoutDir = env.substitute(self.__checkoutDir, "CheckoutDir")
4242

43-
# platform is passed down to dependencies
44-
platform = properties['platform']
43+
# Platform is passed down to dependencies
44+
platform = properties['Platform']
4545
if platform.isPresent():
46-
self.__platformDir = env.substitute(platform.getValue(), "platform")
46+
self.__platformDir = env.substitute(platform.getValue(), "Platform")
4747

4848
def getCheckoutDir(self):
4949
return self.__checkoutDir
@@ -66,10 +66,10 @@ def validate(data):
6666
'jenkinsNameFormatter' : jenkinsFormatter
6767
},
6868
'properties' : {
69-
"checkoutDir" : StringProperty,
70-
"platform" : StringProperty
69+
"CheckoutDir" : StringProperty,
70+
"Platform" : StringProperty
7171
},
7272
'state' : {
73-
"pathFmt" : PathFmtState
73+
"PathFmt" : PathFmtState
7474
}
7575
}

test/black-box/plugin-states/recipes/lib1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# set property for special checkout subdirectory
2-
checkoutDir: "special"
2+
CheckoutDir: "special"
33
checkoutVars: [PLATFORM]
44
checkoutScript: |
55
echo "lib1 $PLATFORM"

test/black-box/plugin-states/recipes/root.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ buildScript: |
1010
packageScript: |
1111
true
1212
13-
# set two different "platform" properties that are inherited
13+
# set two different "Platform" properties that are inherited
1414
multiPackage:
1515
alpha:
16-
platform: "alpha"
16+
Platform: "alpha"
1717
environment:
1818
PLATFORM: "alpha"
1919
bravo:
20-
platform: "bravo"
20+
Platform: "bravo"
2121
environment:
2222
PLATFORM: "bravo"

0 commit comments

Comments
 (0)