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

Function get_ancestor

src/packagedcode/utils.py:151–166  ·  view source on GitHub ↗

Return the nth-``levels_up`` ancestor Resource of ``resource`` in ``codebase`` or None. For example, with levels_up=2 and starting with a resource path of `gem-extract/metadata.gz-extract/metadata.gz-extract`, then `gem-extract/` should be returned.

(levels_up, resource, codebase)

Source from the content-addressed store, hash-verified

149
150
151def get_ancestor(levels_up, resource, codebase):
152 """
153 Return the nth-``levels_up`` ancestor Resource of ``resource`` in
154 ``codebase`` or None.
155
156 For example, with levels_up=2 and starting with a resource path of
157 `gem-extract/metadata.gz-extract/metadata.gz-extract`,
158 then `gem-extract/` should be returned.
159 """
160 rounds = 0
161 while rounds < levels_up:
162 resource = resource.parent(codebase)
163 if not resource:
164 return
165 rounds += 1
166 return resource
167
168
169def find_root_from_paths(paths, resource, codebase):

Callers 6

assembleMethod · 0.90
assemble_extracted_gemFunction · 0.90
assembleMethod · 0.90
assembleMethod · 0.90
assembleMethod · 0.90
assembleMethod · 0.90

Calls 1

parentMethod · 0.80

Tested by

no test coverage detected