[Notes] [Git][BuildStream/buildstream][jonathan/fix-identical-element] _yamlcache.py: Use a project's junction name if present



Title: GitLab

Jonathan Maw pushed to branch jonathan/fix-identical-element at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • buildstream/_yamlcache.py
    ... ... @@ -68,7 +68,7 @@ class YamlCache():
    68 68
         #    (bool): Whether the file is cached.
    
    69 69
         def is_cached(self, project, filepath):
    
    70 70
             cache_path = self._get_filepath(project, filepath)
    
    71
    -        project_name = project.name if project else ""
    
    71
    +        project_name = self._get_project_name(project)
    
    72 72
             try:
    
    73 73
                 project_cache = self._project_caches[project_name]
    
    74 74
                 if cache_path in project_cache.elements:
    
    ... ... @@ -167,7 +167,7 @@ class YamlCache():
    167 167
         #    value (decorated dict): The data to put into the cache.
    
    168 168
         def put_from_key(self, project, filepath, key, value):
    
    169 169
             cache_path = self._get_filepath(project, filepath)
    
    170
    -        project_name = project.name if project else ""
    
    170
    +        project_name = self._get_project_name(project)
    
    171 171
             try:
    
    172 172
                 project_cache = self._project_caches[project_name]
    
    173 173
             except KeyError:
    
    ... ... @@ -237,7 +237,7 @@ class YamlCache():
    237 237
         #    (decorated dict): The parsed yaml from the cache, or None if the file isn't in the cache.
    
    238 238
         def _get(self, project, filepath, key):
    
    239 239
             cache_path = self._get_filepath(project, filepath)
    
    240
    -        project_name = project.name if project else ""
    
    240
    +        project_name = self._get_project_name(project)
    
    241 241
             try:
    
    242 242
                 project_cache = self._project_caches[project_name]
    
    243 243
                 try:
    
    ... ... @@ -253,6 +253,30 @@ class YamlCache():
    253 253
                 pass
    
    254 254
             return None
    
    255 255
     
    
    256
    +    # _get_project_name():
    
    257
    +    #
    
    258
    +    # Gets a name appropriate for Project. Projects must use their junction's
    
    259
    +    # name if present, otherwise elements with the same contents under the
    
    260
    +    # same path with identically-named projects are considered the same yaml
    
    261
    +    # object, despite existing in different Projects.
    
    262
    +    #
    
    263
    +    # Args:
    
    264
    +    #    project (Project): The project this file is in, or None.
    
    265
    +    #
    
    266
    +    # Returns:
    
    267
    +    #    (str): The project's junction's name if present, the project's name,
    
    268
    +    #           or an empty string if there is no project
    
    269
    +    @staticmethod
    
    270
    +    def _get_project_name(project):
    
    271
    +        if project:
    
    272
    +            if project.junction:
    
    273
    +                project_name = project.junction.name
    
    274
    +            else:
    
    275
    +                project_name = project.name
    
    276
    +        else:
    
    277
    +            project_name = ""
    
    278
    +        return project_name
    
    279
    +
    
    256 280
     
    
    257 281
     CachedProject = namedtuple('CachedProject', ['elements'])
    
    258 282
     
    
    ... ... @@ -287,7 +311,7 @@ class BstPickler(pickle.Pickler):
    287 311
             if isinstance(obj, _yaml.ProvenanceFile):
    
    288 312
                 if obj.project:
    
    289 313
                     # ProvenanceFile's project object cannot be stored as it is.
    
    290
    -                project_tag = obj.project.name
    
    314
    +                project_tag = YamlCache._get_project_name(project)
    
    291 315
                     # ProvenanceFile's filename must be stored relative to the
    
    292 316
                     # project, as the project dir may move.
    
    293 317
                     name = os.path.relpath(obj.name, obj.project.directory)
    
    ... ... @@ -319,14 +343,17 @@ class BstUnpickler(pickle.Unpickler):
    319 343
     
    
    320 344
                 if project_tag is not None:
    
    321 345
                     for p in self._context.get_projects():
    
    322
    -                    if project_tag == p.name:
    
    346
    +                    if p.junction and project_tag == p.junction.name:
    
    347
    +                        project = p
    
    348
    +                        break
    
    349
    +                    elif project_tag == p.name:
    
    323 350
                             project = p
    
    324 351
                             break
    
    325 352
     
    
    326 353
                     name = os.path.join(project.directory, tagged_name)
    
    327 354
     
    
    328 355
                     if not project:
    
    329
    -                    projects = [p.name for p in self._context.get_projects()]
    
    356
    +                    projects = [YamlCache._get_project_name(p) for p in self._context.get_projects()]
    
    330 357
                         raise pickle.UnpicklingError("No project with name {} found in {}"
    
    331 358
                                                      .format(project_tag, projects))
    
    332 359
                 else:
    



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