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

Support for pathlib.Path.link_to() #580

Closed
JD-Veiga opened this issue Dec 31, 2020 · 8 comments
Closed

Support for pathlib.Path.link_to() #580

JD-Veiga opened this issue Dec 31, 2020 · 8 comments

Comments

@JD-Veiga
Copy link

JD-Veiga commented Dec 31, 2020

Python 3.8 has added a new method to pathlib library: Path.link_to() for creating hard links (https://docs.python.org/3/library/pathlib.html#pathlib.Path.link_to). I think that it is not supported by pyfakefs yet (v. 4.3.3).

It would be nice to mock this method since it is an easy way to create hard links.

Maybe it would be a good idea to include a FakeFilesystem.create_link() method for creating hard links (similar to FakeFilesystem.create_symlink() for soft links).

Thank you.

@mrbean-bremen
Copy link
Member

Good point, thank you!

@mrbean-bremen
Copy link
Member

@JD-Veiga - shall work in master now. Do you need a released version?

@JD-Veiga
Copy link
Author

Excellent and quick work! I have installed it from master. Thanks a lot. Happy new year!

@mrbean-bremen
Copy link
Member

Last sensible thing I did this year ;) Happy New Year to you, too!

@JD-Veiga
Copy link
Author

JD-Veiga commented Jan 2, 2021

Hi,

Everything is running fine until I have updated one of the dependencies of my code this morning. The update has installed pathlib2 and, tough I do not use directly it in my project, pyfakefs imports pathlib2 now. As a consequence, Path.link_to() has vanished because of: https://github.com/jmcgeheeiv/pyfakefs/blob/846ec97c0efe2f819f883f26ae90247e4ea55aee/pyfakefs/fake_pathlib.py#L126

I have uninstalled pathlib2 from my virtualenv but it is not a permanent solution for everyone everywhere.

Is there a way of adding link_to() to pathlib but not to pathlib2? Maybe a _FakeAccessor for pathlib and a different one for pathlib2? Maybe raising an exception when pathlib2.link_to() is called?

Thank you again.

@mrbean-bremen
Copy link
Member

Ok, I had thought pathlib2 is not used anymore (it is definitely not needed in Python 3.8). Making a separate accessor for pathlib2 is probably not worth it. I could just remove the check for pathlib2 and let it fail if you use pathlib2 instead of pathlib.
This is probably the best option, because if you want to use link_to, you cannot use pathlib2, or you would get the same exception.

@JD-Veiga
Copy link
Author

JD-Veiga commented Jan 2, 2021

I think so now that Python2 is in EOL but... everything comes back... in subtle ways... Thank you once again.

mrbean-bremen added a commit that referenced this issue Jan 2, 2021
- will fail if pathlib2 is used a in real
- see #580
@mrbean-bremen
Copy link
Member

Ok, done. Yeah, I see Python2 used still quite a bit... seems to be unkillable. Though using pathlib2 with Python 3.8 really doesn't make much sense - pathlib2 has stopped developing a couple of years ago, while pathlib is changing with each Python version.

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