MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / walk

Method walk

src/commoncode/resource.py:1016–1052  ·  view source on GitHub ↗

Yield all resources for this Codebase walking its resource tree. Walk the tree top-down, depth-first if ``topdown`` is True, otherwise walk bottom-up. Each level is sorted by children woth this sort order: resource without- children first, then resource with

(self, topdown=True, skip_root=False, ignored=ignore_nothing)

Source from the content-addressed store, hash-verified

1014 return removed_paths
1015
1016 def walk(self, topdown=True, skip_root=False, ignored=ignore_nothing):
1017 """
1018 Yield all resources for this Codebase walking its resource tree. Walk
1019 the tree top-down, depth-first if ``topdown`` is True, otherwise walk
1020 bottom-up.
1021
1022 Each level is sorted by children woth this sort order: resource without-
1023 children first, then resource with-children and each group sorted by
1024 case-insensitive name.
1025
1026 If ``skip_root`` is True, the root resource is not returned unless this
1027 is a codebase with a single resource.
1028
1029 ``ignored`` is a callable that accepts two arguments, ``resource`` and
1030 ``codebase``, and returns True if ``resource`` should be ignored.
1031 """
1032 root = self.root
1033
1034 if ignored(resource=root, codebase=self):
1035 return
1036
1037 # make a copy
1038 root = attr.evolve(root)
1039
1040 # include root if no children (e.g. codebase with a single resource)
1041 if self.has_single_resource or (skip_root and not root.has_children()):
1042 skip_root = False
1043
1044 root = attr.evolve(root)
1045 if topdown and not skip_root:
1046 yield root
1047
1048 for res in root.walk(self, topdown=topdown, ignored=ignored):
1049 yield res
1050
1051 if not topdown and not skip_root:
1052 yield root
1053
1054 def __iter__(self):
1055 yield from self.walk()

Calls 2

evolveMethod · 0.80
has_childrenMethod · 0.80