jaraco / path

Object-oriented file system path manipulation
MIT License
1.11k stars 146 forks source link

Maximize compatibility with `pathlib.Path` #214

Open 5j9 opened 1 year ago

5j9 commented 1 year ago

This project does aspire to align with pathlib where possible, so it should probably do the same (and probably implement iterdir at the same time, if it's not present already).

Originally posted by @jaraco in https://github.com/jaraco/path/issues/212#issuecomment-1623882608

Here some other methods that are worth considering:

set(vars(pathlib.Path)) - set(vars(path.Path)) 
Out[9]: 
{'__slots__',
 '_make_child_relpath',
 '_scandir',
 'absolute',
 'cwd',
 'group',
 'hardlink_to',
 'home',
 'is_block_device',
 'is_char_device',
 'is_dir',
 'is_fifo',
 'is_file',
 'is_mount',
 'is_socket',
 'is_symlink',
 'iterdir',
 'lchmod',
 'link_to',
 'replace',
 'resolve',
 'rglob',
 'symlink_to'}
jaraco commented 1 year ago

Nice. Sounds good. I welcome the contributions. In cases where the functionality is duplicative and the pathlib syntax is inarguably as good, let's also deprecate any local pecularities.

jaraco commented 9 months ago

In #218, I'm working on adding support for .suffix, .with_stem, and .with_name.

jaraco commented 6 months ago

Looks like link_to was replaced by hardlink_to and removed.

jaraco commented 6 months ago

I'm looking at symlink_to and hardlink_to, and it's interesting. pathlib's implementation is very different, switching the order of arguments. It's not obvious why the order of arguments was switched (from os.path equivalents) and in fact, the order was only switched in symlink_to originally and later in hardlink_to. I'm not sure yet if the other ones should be deprecated. I'm leaning toward keeping them for now. Another difference is that pathlib doesn't return anything for symlink_to or hardlink_to, but the path implementation does. It seems to me that returning something would be useful, but I'm yet unsure what is best to return. I'll probably start with not returning anything at all (matching the pathlib behavior) unless there's a case to be made for a returned value.

jaraco commented 6 months ago

I observe that Path.owner and pathlib.Path.owner() are incompatible. It won't be possible to align those without first deprecating .owner.

jaraco commented 3 months ago

I took at replace. This case is a more difficult one, because path.Path is a str subclass, so already has a replace that's different from how pathlib.Path.replace works.

I'm thinking maybe this library can support both: