Skip to content

Commit f3cc7cb

Browse files
committed
Update resource and codebase processing
- When you create a VirtualCodebase with multiple scans, we now prefix each scan path with a codebase-1/, codebase-2/, etc. directory in addition to the "virtual_root" shared root directory. Otherwise files data was overwritten and inconsistent when each location "files" were sharing leading path segments. - When you create a VirtualCodebase with more than one Resource, we now recreate the directory tree for any intermediary directory used in a path that is otherwise missing from files path list. In particular this behaviour changed when you create a VirtualCodebase from a pervious Codebase created with a "full_root" argument. Previously, the missing paths of a "full_root" Codebase were kept unchanged. Noet that the VirtualCodebase has always ignored the "full_root" argument. - The Resource has no rid (resource id) and no pid (parent id). Instead we now use internally a simpler mapping of {path: Resource} object. - The Codebase and VirtualCodebase are now iterable. Iterating on a codebase is the same as a top-down walk. - The Resource.path now never contains leading or trailing slash. We also normalize the path everywhere. In particular this behaviour is visible when you create a Codebase with a "full_root" argument. Previously, the paths of a "full_root" Codebase were prefixed with a slash "/". Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 017b4e5 commit f3cc7cb

15 files changed

+2153
-426
lines changed

CHANGELOG.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,52 @@ Release notes
44
Version (next)
55
------------------------------
66

7+
Version 31.0.0 - (2022-05-16)
8+
------------------------------
9+
10+
This is a major version with API-breaking behavious changes in the reosurce
11+
module.
12+
13+
- When you create a VirtualCodebase with multiple scans, we now prefix each
14+
scan path with a codebase-1/, codebase-2/, etc. directory in addition to the
15+
"virtual_root" shared root directory. Otherwise files data was overwritten
16+
and inconsistent when each location "files" were sharing leading path
17+
segments.
18+
19+
- When you create a VirtualCodebase with more than one Resource, we now recreate
20+
the directory tree for any intermediary directory used in a path that is
21+
otherwise missing from files path list.
22+
In particular this behaviour changed when you create a VirtualCodebase from
23+
a pervious Codebase created with a "full_root" argument. Previously, the
24+
missing paths of a "full_root" Codebase were kept unchanged.
25+
Noet that the VirtualCodebase has always ignored the "full_root" argument.
26+
27+
- The Resource has no rid (resource id) and no pid (parent id). Instead
28+
we now use internally a simpler mapping of {path: Resource} object.
29+
30+
- The Codebase and VirtualCodebase accepts a new "paths" argument that is list
31+
of paths. When provided, the Codebase will only contain Resources with these
32+
paths and no other resources. has no rid (resource id) and no pid (parent id).
33+
Instead we now use internally a simpler mapping of {path: Resource} object.
34+
As a result the iteration on a Codebase is faster but this requires more
35+
memory.
36+
37+
- The Codebase and VirtualCodebase are now iterable. Iterating on a codebase
38+
is the same as a top-down walk.
39+
40+
- The Resource.path now never contains leading or trailing slash. We also
41+
normalize the path everywhere. In particular this behaviour is visible when
42+
you create a Codebase with a "full_root" argument. Previously, the paths of a
43+
"full_root" Codebase were prefixed with a slash "/".
44+
45+
46+
Other changes:
47+
748
- Remove Python upper version limit.
49+
- Merge latest skeleton
50+
- fileutils.parent_directory() now accepts a "with_trail" argument.
51+
The returned directory has a trailing path separator unless with_trail is False.
52+
The default is True and the default behavious is unchanged.
853

954

1055
Version 30.2.0 - (2022-05-02)

src/commoncode/fileutils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,15 @@ def file_name(path, force_posix=False):
206206
return resource_name(path, force_posix)
207207

208208

209-
def parent_directory(path, force_posix=False):
209+
def parent_directory(path, force_posix=False, with_trail=True):
210210
"""
211211
Return the parent directory path of a file or directory `path`.
212+
The returned directory has a trailing path separator unless with_trail is False.
212213
"""
213214
left, _right = split_parent_resource(path, force_posix)
214215
use_posix = force_posix or is_posixpath(path)
215216
sep = '/' if use_posix else '\\'
216-
trail = sep if left != sep else ''
217+
trail = sep if with_trail and left != sep else ''
217218
return left + trail
218219

219220

0 commit comments

Comments
 (0)