Commit graph

71 commits

Author SHA1 Message Date
7374ffe283
Add pathclass.natural_sorter. 2022-08-21 13:58:44 -07:00
2996283344
If given glob pattern is an existing path, just return that. 2022-08-21 13:57:19 -07:00
7f2360d1c0
Distinguish between symlinks and ntfs junctions. 2022-04-30 07:23:51 -07:00
cb84774231
Rearrange some asserts. 2022-04-30 07:23:02 -07:00
5ddc83e3ff
Call expanduser in pathclass init. 2022-03-23 14:37:04 -07:00
8d258241e7
Let pathclass.glob('.') return cwd.
This brings it more in line with regular glob for which glob('.') = ['.'].
2022-01-19 20:23:05 -08:00
9a0be7eda9
space message 2022-01-19 19:52:46 -08:00
bcab9b34d6
Add Path.assert_disk_space. 2022-01-19 19:23:11 -08:00
77769aa2ef
Alphabetize exceptions. 2022-01-19 18:38:05 -08:00
d34103917f
Re-add the normalize_sep function, but more conservative.
Formerly I was normalizing backslash to forwardslash on unix, which is
bad. Then I removed the function because I thought normpath was the
right tool for the job. Now I'm finding a few situations I just want to
norm the sep again.
2022-01-09 16:59:09 -08:00
31156aa67c
Sort scandir entries.
In spinal.walk sorting is optional because there I prioritize
configurability and speed, but for pathclass.walk I think it
makes sense to prioritize comfort and just-works results.
2022-01-04 12:47:17 -08:00
359c255817
Make pathclass globs faster by checking scandir for stat first. 2021-12-16 21:14:35 -08:00
f2190b9bfb
Add Path.walk_directories, walk_files. 2021-12-07 12:41:35 -08:00
19afbc2105
Enforce with_child basename is str. 2021-12-02 19:32:25 -08:00
e2fd04ccf1
Remove .absolute_path thanks to fspath. 2021-12-02 19:32:08 -08:00
b288cca519
Rewrite a lot of pathclass, spinal.walk using tuple-based Path.
I was inspired by the idea of "making impossible states impossible"
and using a data model that accurately represents what we intend for
it to represent. Instead of storing the path as a string where "it's
a string but actually you're supposed to know that the parts between
os.seps are different parts and the first one is special and...", we
can use a data model that directly says that. Storing the path as a
tuple of (Drive, Part, Part) helps me focus on the semantics of the
Path as a collection of parts joined by the os.sep.

Furthermore, storing the path as a string made some operations slow.
Every time we call one of the os.path functions with a string, it
has to do a lot of normalization and edge-case handling even when we
know it wouldn't be needed. By storing the path as a tuple, we can
instantly get the drive name, parent dir name, and basename without
asking os.path to split it for us every single time. It also makes
relative path / common ancestor checks a lot easier to understand.
Fewer operations need to go into the slow functions.
2021-11-30 21:16:47 -08:00
f1b88b49fe
Raise typeerror if not Path or str, and dedent by early return. 2021-11-14 22:18:03 -08:00
6c063fd187
Add listdir_files, listdir_directories. 2021-11-07 18:59:02 -08:00
e737e60862
Revert files/directories argument to glob, use separate functions.
I thought it was clever at first, but now I'm feeling that having
mutually exclusive arguments to a single function in this case is
better served by just having two functions. Which also saves us
from ever having to deal with the exception case.
2021-11-07 18:58:35 -08:00
125681da18
Let pathclass.join take spawn_kwargs. 2021-11-07 18:55:28 -08:00
154f02f5bb
Use r-string for re.match windows drive letter. 2021-11-07 18:54:17 -08:00
281e95f184
Make force_sep a kw-only argument. 2021-11-07 18:53:57 -08:00
b68ac864fa
Return a pathclass object from @property drive. 2021-10-24 00:16:33 -07:00
a4196f2b13
Add aliases assert_is_dir, assert_not_dir. 2021-10-10 00:31:43 -07:00
05586e7e79
Let is_directory be canonical function, but keep the aliases. 2021-10-10 00:31:25 -07:00
0a1ab15637
Add convenient pathclass.read, write. 2021-10-04 17:19:20 -07:00
bebcd6c7f3
Fix docstring column wrapping. 2021-09-23 22:36:39 -07:00
cd1fce3211
Add aliases is_directory, is_folder -> is_dir. 2021-09-23 22:36:14 -07:00
446626f1ce
Add pathclass.glob, glob_many. 2021-09-23 22:36:01 -07:00
e0f37b986c
Use double backslash even in docstring. 2021-09-13 18:00:56 -07:00
0416f0babf
Discourage writes to pathclass._absolute_path. 2021-09-09 17:30:46 -07:00
63251b979b
Describe Path parameters in docstring. 2021-08-09 16:27:33 -07:00
81782383a9
Use regular path.join when constructing glob patterns.
I don't like the idea of having an intermediate Path object that isn't
a real path.
2021-08-09 08:36:20 -07:00
13bf8e2e47
Improve Windows reserved name check by adding to pathclass. 2021-07-24 12:24:24 -07:00
244691713d Add constant WINDOWS_BADCHARS for use in other programs. 2020-12-05 15:06:27 -08:00
ebe009f2a2 Add assert_not_file, assert_not_directory to round it out. 2020-12-05 14:55:02 -08:00
44d9bd9913 Add assert_is_link, assert_not_link. 2020-12-05 14:51:51 -08:00
Ethan Dalool
d29501bae7 Having removed self.spawn(other), add back Path(other). 2020-11-02 23:18:19 -08:00
Ethan Dalool
426da9b52b Let listdir spawn children with _correct_case already set. 2020-10-28 14:56:52 -07:00
Ethan Dalool
adf7353ae6 Cache _case_correct property to cut down on fs calls. 2020-10-28 14:55:49 -07:00
Ethan Dalool
a05d34ea9e Add Path.makedirs. 2020-09-24 14:16:51 -07:00
Ethan Dalool
ba88731ae2 Fix cwd. 2020-09-22 01:55:30 -07:00
Ethan Dalool
c6d7450028 Add Path.open. 2020-09-20 17:31:28 -07:00
Ethan Dalool
a2337346fb Add helpful pathclass.cwd function. 2020-09-12 10:15:14 -07:00
Ethan Dalool
9874f12a2a Return self from correct_case instead of self.absolute_path. 2020-09-02 09:11:49 -07:00
Ethan Dalool
27291df9ad Sort Pathclass by normcase instead of absolute path. 2020-09-02 08:52:13 -07:00
Ethan Dalool
53528741b2 Assert exists before trying to calculate size; explicit elif.
If you have a path that you expect to expect to be a file, it is
confusing to see the traceback where it attempts to listdir because
self.is_file failed and the else was to treat it as a dir.
I prefer this explicit exists check, and explicit dir check.
Yeah, potential for race conditions exists.
2020-08-28 17:31:31 -07:00
Ethan Dalool
3a5e160504 Add Path.__lt__ so they are sortable. 2020-07-20 18:03:48 -07:00
Ethan Dalool
453b2d2fb1 Fix pathclass.glob actually only looking at cwd.
In other news, don't ever trust anything I do.
2020-07-16 21:28:40 -07:00
Ethan Dalool
ff9895a390 Add method glob to get child items with a glob pattern. 2020-07-07 22:25:44 -07:00