Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximize compatibility with pathlib.Path #214

Open
14 of 24 tasks
5j9 opened this issue Jul 7, 2023 · 6 comments
Open
14 of 24 tasks

Maximize compatibility with pathlib.Path #214

5j9 opened this issue Jul 7, 2023 · 6 comments

Comments

@5j9
Copy link
Contributor

5j9 commented Jul 7, 2023

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 #212 (comment)

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'}
  • 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
  • owner
  • replace
  • resolve
  • rglob
  • suffix
  • symlink_to
  • with_stem
  • with_name
@jaraco
Copy link
Owner

jaraco commented Jul 7, 2023

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.

@5j9 5j9 changed the title Consider implementing other methods that exists on pathlib.Path but not yet on path.Path Consider implementing other methods that exist on pathlib.Path but not yet on path.Path Jul 7, 2023
@jaraco
Copy link
Owner

jaraco commented Feb 4, 2024

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

@jaraco jaraco changed the title Consider implementing other methods that exist on pathlib.Path but not yet on path.Path Maximize compatibility with pathlib.Path Feb 4, 2024
jaraco added a commit that referenced this issue Apr 8, 2024
@jaraco
Copy link
Owner

jaraco commented Apr 8, 2024

@jaraco
Copy link
Owner

jaraco commented Apr 8, 2024

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 added a commit that referenced this issue Apr 8, 2024
@jaraco
Copy link
Owner

jaraco commented Apr 9, 2024

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

jaraco added a commit that referenced this issue Apr 9, 2024
jaraco added a commit that referenced this issue Apr 9, 2024
jaraco added a commit that referenced this issue Jul 27, 2024
@jaraco
Copy link
Owner

jaraco commented Jul 27, 2024

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:

  • If one parameter is passed, follow the pathlib.Path logic (rename the file).
  • If two parameters are passed, perform a str.replace, but wrap in a "next" Path class.

jaraco added a commit that referenced this issue Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants