Repository navigation
Support for Path objects in io packages - #4606
Conversation
|
@taldcroft Is this the correct approach? I tried to follow yours as in #4405. |
f2a74dc to
6682bc7
Compare
By modifying get_readable_fileobj in utils because io.ascii uses get_readable_fileobj to read.
6682bc7 to
b8b3c12
Compare
|
@anchitjain1234 - thanks, this looks promising! If you do a census throughout the project of places that use |
Also modified docstrings of io.votable.validate and io.ascii.read for indicating capability to read Path objects
Also modified docstring of fitsopen in hdulist.py
@taldcroft I grepped the whole project to find the usage of
I handled I also added a separate test for |
|
@taldcroft Could you please check the changes? |
| else: | ||
| self.simulateonly = False | ||
| # If fileobj is of type pathlib.Path | ||
| if PY3 and HAS_PATHLIB and isinstance(fileobj, Path): |
There was a problem hiding this comment.
You don't need to check PY3, all that matters is HAS_PATHLIB to make sure the second logical test will execute properly.
|
@anchitjain1234 - looks pretty good, thanks! |
|
Also pathlib can be installed on PY2: https://pypi.python.org/pypi/pathlib2/ |
|
@taldcroft Please check the changes. |
| if six.PY3: | ||
| # path might be a pathlib.Path object if HAS_PATHLIB, | ||
| # so coerce to a regular string. | ||
| if HAS_PATHLIB: |
There was a problem hiding this comment.
It occurs to me that in theory a user might be passing a unicode file name on Python 2 with the backport of pathlib independently installed. Then conversion with str() would be a problem. So maybe you need to also check isinstance(args[0], pathlib.Path)?
There was a problem hiding this comment.
@taldcroft If I understand correctly, you meant to say for example a file named x©.fits on Python 2 with the backport of pathlib independently installed would be a problem?
I cant understand why would it be a problem?
I also tested it on my system on Python 2 and Python 3 where it works correctly.
05a838d to
6ee89c3
Compare
6ee89c3 to
c7b5d20
Compare
|
@anchitjain1234 - looks good! Now you just need to add an entry to CHANGES.rst describing this update. You can put |
|
@taldcroft In |
|
@anchitjain1234 - Even if the package name is pathlib2, it will import as @taldcroft - Maybe the extra dependency should be added to a Python2 build in Travis ? |
|
@taldcroft Changelog entry added. |
|
@saimn - I think that @anchitjain1234 has a point. If pathlib2 is installed the code still needs to explicitly do: I was hoping that I think we should just merge this current version, which addresses the stated issue of providing support for bona-fide |
|
@taldcroft - Ah sorry, I tested this on a virtualenv, that I thought was based on PY2 but it seems not. The backport provides indeed a |
Support for Path objects in io packages
|
Thanks @anchitjain1234 ! And @saimn for useful review and input. |
For #4412.
Right now added support for
io.asciiby modifyingget_readable_fileobjinutilsbecauseio.asciiusesget_readable_fileobjto read.I would also try to add support for Path objects in other io packages.