|
23 | 23 | from os.path import normpath |
24 | 24 | from posixpath import join as posixpath_join |
25 | 25 | from posixpath import normpath as posixpath_normpath |
| 26 | +from posixpath import dirname as posixpath_parent |
26 | 27 |
|
27 | 28 | import attr |
28 | 29 |
|
@@ -1169,13 +1170,21 @@ def build_path(cls, root_location, location): |
1169 | 1170 | to ``root_location`. Both locations are absolute native locations. |
1170 | 1171 | The returned path has no leading and trailing slashes. The first segment |
1171 | 1172 | of this path is always the last segment of the ``root_location``. |
| 1173 | + For example: |
| 1174 | + >>> result = Resource.build_path(r'D:\\foo\\bar', r'D:\\foo\\bar\\baz') |
| 1175 | + >>> assert result == 'bar/baz', repr(result) |
| 1176 | + >>> result = Resource.build_path('/foo/bar/', '/foo/bar/baz') |
| 1177 | + >>> assert result == 'bar/baz', result |
| 1178 | + >>> result = Resource.build_path('/foo/bar/', '/foo/bar') |
| 1179 | + >>> assert result == 'bar', result |
1172 | 1180 | """ |
1173 | 1181 | root_loc = clean_path(root_location) |
1174 | 1182 | loc = clean_path(location) |
1175 | 1183 | assert loc.startswith(root_loc) |
| 1184 | + |
1176 | 1185 | # keep the root directory name by default |
1177 | | - root_loc = parent_directory(root_loc, with_trail=True) |
1178 | | - path = loc.replace(root_loc, '', 1) |
| 1186 | + root_loc = posixpath_parent(root_loc).strip('/') |
| 1187 | + path = loc.replace(root_loc, '', 1).strip('/') |
1179 | 1188 | if TRACE: |
1180 | 1189 | logger_debug('build_path:', root_loc, loc, path) |
1181 | 1190 | return path |
@@ -1580,6 +1589,7 @@ def get_codebase_cache_dir(temp_dir): |
1580 | 1589 |
|
1581 | 1590 | @attr.s(slots=True) |
1582 | 1591 | class _CodebaseAttributes(object): |
| 1592 | + |
1583 | 1593 | def to_dict(self): |
1584 | 1594 | return attr.asdict(self, dict_factory=dict) |
1585 | 1595 |
|
|
0 commit comments