[Notes] [Git][BuildStream/buildstream][danielsilverstone-ct/yaml-sentinel-rework] 5 commits: Check if command is a str and replace by list before checking existence



Title: GitLab

Daniel Silverstone pushed to branch danielsilverstone-ct/yaml-sentinel-rework at BuildStream / buildstream

Commits:

8 changed files:

Changes:

  • buildstream/_loader/loadelement.py
    ... ... @@ -146,8 +146,8 @@ def _extract_depends_from_node(node, *, key=None):
    146 146
         depends = _yaml.node_get(node, list, key, default_value=[])
    
    147 147
         output_deps = []
    
    148 148
     
    
    149
    -    for dep in depends:
    
    150
    -        dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[depends.index(dep)])
    
    149
    +    for index, dep in enumerate(depends):
    
    150
    +        dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
    
    151 151
     
    
    152 152
             if isinstance(dep, str):
    
    153 153
                 dependency = Dependency(dep, provenance=dep_provenance, dep_type=default_dep_type)
    
    ... ... @@ -177,10 +177,8 @@ def _extract_depends_from_node(node, *, key=None):
    177 177
                                         provenance=dep_provenance)
    
    178 178
     
    
    179 179
             else:
    
    180
    -            index = depends.index(dep)
    
    181
    -            p = _yaml.node_get_provenance(node, key=key, indices=[index])
    
    182 180
                 raise LoadError(LoadErrorReason.INVALID_DATA,
    
    183
    -                            "{}: Dependency is not specified as a string or a dictionary".format(p))
    
    181
    +                            "{}: Dependency is not specified as a string or a dictionary".format(dep_provenance))
    
    184 182
     
    
    185 183
             output_deps.append(dependency)
    
    186 184
     
    

  • buildstream/_yaml.py
    ... ... @@ -335,16 +335,9 @@ def node_get_provenance(node, key=None, indices=None):
    335 335
         return provenance
    
    336 336
     
    
    337 337
     
    
    338
    -# Helper to use utils.sentinel without unconditional utils import,
    
    339
    -# which causes issues for completion.
    
    340
    -#
    
    341
    -# Local private, but defined here because sphinx appears to break if
    
    342
    -# it's not defined before any functions calling it in default kwarg
    
    343
    -# values.
    
    344
    -#
    
    345
    -def _get_sentinel():
    
    346
    -    from .utils import _sentinel
    
    347
    -    return _sentinel
    
    338
    +# A sentinel to be used as a default argument for functions that need
    
    339
    +# to distinguish between a kwarg set to None and an unset kwarg.
    
    340
    +_sentinel = object()
    
    348 341
     
    
    349 342
     
    
    350 343
     # node_get()
    
    ... ... @@ -368,10 +361,10 @@ def _get_sentinel():
    368 361
     # Note:
    
    369 362
     #    Returned strings are stripped of leading and trailing whitespace
    
    370 363
     #
    
    371
    -def node_get(node, expected_type, key, indices=None, default_value=_get_sentinel()):
    
    364
    +def node_get(node, expected_type, key, indices=None, default_value=_sentinel):
    
    372 365
         value = node.get(key, default_value)
    
    373 366
         provenance = node_get_provenance(node)
    
    374
    -    if value is _get_sentinel():
    
    367
    +    if value is _sentinel:
    
    375 368
             raise LoadError(LoadErrorReason.INVALID_DATA,
    
    376 369
                             "{}: Dictionary did not contain expected key '{}'".format(provenance, key))
    
    377 370
     
    

  • buildstream/element.py
    ... ... @@ -451,7 +451,7 @@ class Element(Plugin):
    451 451
     
    
    452 452
             return None
    
    453 453
     
    
    454
    -    def node_subst_member(self, node, member_name, default=utils._sentinel):
    
    454
    +    def node_subst_member(self, node, member_name, default=_yaml._sentinel):
    
    455 455
             """Fetch the value of a string node member, substituting any variables
    
    456 456
             in the loaded value with the element contextual variables.
    
    457 457
     
    

  • buildstream/plugin.py
    ... ... @@ -321,7 +321,7 @@ class Plugin():
    321 321
             provenance = _yaml.node_get_provenance(node, key=member_name)
    
    322 322
             return str(provenance)
    
    323 323
     
    
    324
    -    def node_get_member(self, node, expected_type, member_name, default=utils._sentinel):
    
    324
    +    def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel):
    
    325 325
             """Fetch the value of a node member, raising an error if the value is
    
    326 326
             missing or incorrectly typed.
    
    327 327
     
    

  • buildstream/sandbox/_sandboxbwrap.py
    ... ... @@ -66,15 +66,15 @@ class SandboxBwrap(Sandbox):
    66 66
             cwd = self._get_work_directory(cwd=cwd)
    
    67 67
             env = self._get_environment(cwd=cwd, env=env)
    
    68 68
     
    
    69
    +        # Convert single-string argument to a list
    
    70
    +        if isinstance(command, str):
    
    71
    +            command = [command]
    
    72
    +
    
    69 73
             if not self._has_command(command[0], env):
    
    70 74
                 raise SandboxError("Staged artifacts do not provide command "
    
    71 75
                                    "'{}'".format(command[0]),
    
    72 76
                                    reason='missing-command')
    
    73 77
     
    
    74
    -        # We want command args as a list of strings
    
    75
    -        if isinstance(command, str):
    
    76
    -            command = [command]
    
    77
    -
    
    78 78
             # Create the mount map, this will tell us where
    
    79 79
             # each mount point needs to be mounted from and to
    
    80 80
             mount_map = MountMap(self, flags & SandboxFlags.ROOT_READ_ONLY)
    

  • buildstream/sandbox/_sandboxchroot.py
    ... ... @@ -57,15 +57,15 @@ class SandboxChroot(Sandbox):
    57 57
             cwd = self._get_work_directory(cwd=cwd)
    
    58 58
             env = self._get_environment(cwd=cwd, env=env)
    
    59 59
     
    
    60
    +        # Convert single-string argument to a list
    
    61
    +        if isinstance(command, str):
    
    62
    +            command = [command]
    
    63
    +
    
    60 64
             if not self._has_command(command[0], env):
    
    61 65
                 raise SandboxError("Staged artifacts do not provide command "
    
    62 66
                                    "'{}'".format(command[0]),
    
    63 67
                                    reason='missing-command')
    
    64 68
     
    
    65
    -        # Command must be a list
    
    66
    -        if isinstance(command, str):
    
    67
    -            command = [command]
    
    68
    -
    
    69 69
             stdout, stderr = self._get_output()
    
    70 70
     
    
    71 71
             # Create the mount map, this will tell us where
    

  • buildstream/sandbox/_sandboxdummy.py
    ... ... @@ -33,6 +33,10 @@ class SandboxDummy(Sandbox):
    33 33
             cwd = self._get_work_directory(cwd=cwd)
    
    34 34
             env = self._get_environment(cwd=cwd, env=env)
    
    35 35
     
    
    36
    +        # Convert single-string argument to a list
    
    37
    +        if isinstance(command, str):
    
    38
    +            command = [command]
    
    39
    +
    
    36 40
             if not self._has_command(command[0], env):
    
    37 41
                 raise SandboxError("Staged artifacts do not provide command "
    
    38 42
                                    "'{}'".format(command[0]),
    

  • buildstream/utils.py
    ... ... @@ -654,10 +654,6 @@ def _pretty_size(size, dec_places=0):
    654 654
         return "{size:g}{unit}".format(size=round(psize, dec_places), unit=unit)
    
    655 655
     
    
    656 656
     
    
    657
    -# A sentinel to be used as a default argument for functions that need
    
    658
    -# to distinguish between a kwarg set to None and an unset kwarg.
    
    659
    -_sentinel = object()
    
    660
    -
    
    661 657
     # Main process pid
    
    662 658
     _main_pid = os.getpid()
    
    663 659
     
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]