MCPcopy Create free account
hub / github.com/alibaba/GraphScope / FixupPathFromRoot

Function FixupPathFromRoot

analytical_engine/misc/cpplint.py:2312–2360  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2310 file_path_from_root = fileinfo.RepositoryName()
2311
2312 def FixupPathFromRoot():
2313 if _root_debug:
2314 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
2315 % (_root, fileinfo.RepositoryName()))
2316
2317 # Process the file path with the --root flag if it was set.
2318 if not _root:
2319 if _root_debug:
2320 sys.stderr.write("_root unspecified\n")
2321 return file_path_from_root
2322
2323 def StripListPrefix(lst, prefix):
2324 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2325 if lst[:len(prefix)] != prefix:
2326 return None
2327 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2328 return lst[(len(prefix)):]
2329
2330 # root behavior:
2331 # --root=subdir , lstrips subdir from the header guard
2332 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
2333 PathSplitToList(_root))
2334
2335 if _root_debug:
2336 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
2337 " _root=%s)\n") % (maybe_path, file_path_from_root, _root))
2338
2339 if maybe_path:
2340 return os.path.join(*maybe_path)
2341
2342 # --root=.. , will prepend the outer directory to the header guard
2343 full_path = fileinfo.FullName()
2344 root_abspath = os.path.abspath(_root)
2345
2346 maybe_path = StripListPrefix(PathSplitToList(full_path),
2347 PathSplitToList(root_abspath))
2348
2349 if _root_debug:
2350 sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
2351 "root_abspath=%s)\n") % (maybe_path, full_path, root_abspath))
2352
2353 if maybe_path:
2354 return os.path.join(*maybe_path)
2355
2356 if _root_debug:
2357 sys.stderr.write("_root ignore, returning %s\n" % (file_path_from_root))
2358
2359 # --root=FAKE_DIR is ignored
2360 return file_path_from_root
2361
2362 file_path_from_root = FixupPathFromRoot()
2363 return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'

Callers 1

Calls 6

StripListPrefixFunction · 0.85
PathSplitToListFunction · 0.85
RepositoryNameMethod · 0.80
FullNameMethod · 0.80
writeMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected