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

FolderData should take folder path as constructor argument #3357

Closed
ltalirz opened this issue Sep 27, 2019 · 1 comment · Fixed by #3359
Closed

FolderData should take folder path as constructor argument #3357

ltalirz opened this issue Sep 27, 2019 · 1 comment · Fixed by #3359

Comments

@ltalirz
Copy link
Member

ltalirz commented Sep 27, 2019

We discovered during the SINTEF tutorial that it is quite difficult to figure out how to create a FolderData from an existing folder (I figured it out by searching the aiida-core source code, which is not something a regular user can do).

  • When creating fd = FolderData in verdi shell and doing fd. + you see lots of methods, but the relevant one ( .put_object_from_tree) was not even visible (you would have to scroll to the end)
  • When you just want to create a FolderData to wrap a folder on your file system, "put_object_from_tree" is maybe not what you are thinking...

In my opinion, the FolderData should have a constructor argument folder to which you can pass an absolute path to a folder that will make the FolderData wrap this folder.
I think this would cover the majority of cases with a simple user interface.

Mentioning @sphuber and @giovannipizzi for comment

@sphuber
Copy link
Contributor

sphuber commented Sep 27, 2019

The way this works in aiida-core==1.0.0 is that the constructor of Data sub classes can define the keywords they want to accept in the constructor to initialize the node. In this case this would look like:

class FolderData(Data):

    def __init__(self, **kwargs):
        """Construct a new `FolderData` to which any files and folders can be added.

        To add files to a new node use the various repository methods:

            folder = FolderData()
            folder.put_object_from_tree('/absolute/path/to/directory')
            folder.put_object_from_filepath('/absolute/path/to/file.txt')

        Alternatively, in order to simply wrap a directory, the `path` keyword can be used in the constructor:

            folder = FolderData(path='/absolute/path/to/directory')
        """
        path = kwargs.pop('path', None)
        super(FolderData, self).__init__(**kwargs)
        if path:
            self.put_file_from_tree(path)

I can make a PR for this if we are happy with the interface. Since it is a FolderData I now only added option to add a directory. Should we also add one for adding a single file? Of course after construction, one can add as many other things as one wants

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.

2 participants