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

pathlib support for file constructor arguments #4570

Closed
ltalirz opened this issue Nov 17, 2020 · 3 comments · Fixed by #3614
Closed

pathlib support for file constructor arguments #4570

ltalirz opened this issue Nov 17, 2020 · 3 comments · Fixed by #3614

Comments

@ltalirz
Copy link
Member

ltalirz commented Nov 17, 2020

Is your feature request related to a problem? Please describe

In [1]: from aiida.orm import SinglefileData

In [2]: !pwd
/Users/leopold

In [3]: s=SinglefileData(file='/Users/leopold/nanopub.zip')

In [4]: from pathlib import Path

In [5]: s=SinglefileData(file=Path('/Users/leopold/nanopub.zip'))
-------------------------------------------------------------------------
AttributeError                          Traceback (most recent call last)
<ipython-input-5-e5ace348d29f> in <module>
----> 1 s=SinglefileData(file=Path('/Users/leopold/nanopub.zip'))

~/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/orm/nodes/data/singlefile.py in __init__(self, file, filename, **kwargs)
     45             if filename is None:
     46                 # don't assume that set_file has a 'filename' argument (remove guard in 2.0.0)
---> 47                 self.set_file(file)
     48             else:
     49                 self.set_file(file, filename=filename)

~/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/orm/nodes/data/singlefile.py in set_file(self, file, filename)
    130
    131         if is_filelike:
--> 132             self.put_object_from_filelike(file, key, mode='wb')
    133         else:
    134             self.put_object_from_file(file, key)

~/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/orm/nodes/node.py in put_object_from_filelike(self, handle, path, mode, encoding, force, key)
    637             raise TypeError("put_object_from_filelike() missing 1 required positional argument: 'path'")
    638
--> 639         self._repository.put_object_from_filelike(handle, path, mode, encoding, force)
    640
    641     def delete_object(self, path=None, force=False, key=None):

~/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/orm/utils/_repository.py in put_object_from_filelike(self, handle, key, mode, encoding, force)
    229             folder = folder.get_subfolder(basepath, create=True)
    230
--> 231         folder.create_file_from_filelike(handle, key, mode=mode, encoding=encoding)
    232
    233     def delete_object(self, key, force=False):

~/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/common/folders.py in create_file_from_filelike(self, filelike, filename, mode, encoding)
    226
    227         with open(filepath, mode=mode, encoding=encoding) as handle:
--> 228             shutil.copyfileobj(filelike, handle)
    229
    230         os.chmod(filepath, self.mode_file)

~/Applications/miniconda3/envs/aiida_rmq_py3/lib/python3.7/shutil.py in copyfileobj(fsrc, fdst, length)
     77     """copy data from file-like object fsrc to file-like object fdst"""
     78     while 1:
---> 79         buf = fsrc.read(length)
     80         if not buf:
     81             break

AttributeError: 'PosixPath' object has no attribute 'read'

Describe the solution you'd like

We should start supporting pathlib.Path objects, wherever we accept paths in string form.

@ltalirz ltalirz added the type/feature request status undecided label Nov 17, 2020
@greschd
Copy link
Member

greschd commented Nov 17, 2020

Maybe we can just revive #3614.

@ltalirz
Copy link
Member Author

ltalirz commented Nov 17, 2020

Oops - I searched for issues but didn't find one ;-)

Thanks @greschd , feel free to put me as a reviewer

@greschd
Copy link
Member

greschd commented Nov 17, 2020

It's because it was a PR, not an issue ;)

@sphuber sphuber added this to the v1.6.0 milestone Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants