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

Function strip_first_path_segment

src/commoncode/resource.py:1657–1680  ·  view source on GitHub ↗

Return a POSIX ``path`` stripped from its first path segment unless there is only one segment in which case we return this segment. The returned path has no leading and trailing slashes. For example:: >>> strip_first_path_segment('') '' >>> strip_first_path_

(path)

Source from the content-addressed store, hash-verified

1655
1656
1657def strip_first_path_segment(path):
1658 """
1659 Return a POSIX ``path`` stripped from its first path segment unless there is
1660 only one segment in which case we return this segment. The returned path has
1661 no leading and trailing slashes.
1662
1663 For example::
1664 >>> strip_first_path_segment('')
1665 ''
1666 >>> strip_first_path_segment('foo')
1667 ''
1668 >>> strip_first_path_segment('foo/bar/baz')
1669 'bar/baz'
1670 >>> strip_first_path_segment('/foo/bar/baz/')
1671 'bar/baz'
1672 >>> strip_first_path_segment('foo/')
1673 ''
1674 """
1675 path = clean_path(path)
1676 if "/" in path:
1677 _root, _, path = path.partition("/")
1678 return path
1679 else:
1680 return ""
1681
1682
1683def get_codebase_cache_dir(temp_dir):

Callers 2

get_package_and_depsFunction · 0.90
strip_root_pathMethod · 0.85

Calls 1

clean_pathFunction · 0.85

Tested by

no test coverage detected