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

Implement soft link and external link #87

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Implement soft link and external link #87

wants to merge 5 commits into from

Conversation

lepmik
Copy link
Member

@lepmik lepmik commented May 10, 2019

  • Link classes live in links.py module
  • They are subclass of the abstract class Link
  • Functionality should match h5py

Should fix #1
Aims for compatibility with NWB NeurodataWithoutBorders/pynwb#629

@lepmik lepmik requested review from dragly and miladh May 10, 2019 15:38
@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #87 into dev will increase coverage by 0.13%.
The diff coverage is 97.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #87      +/-   ##
==========================================
+ Coverage   95.57%   95.71%   +0.13%     
==========================================
  Files          11       12       +1     
  Lines        1604     1702      +98     
==========================================
+ Hits         1533     1629      +96     
- Misses         71       73       +2
Impacted Files Coverage Δ
tests/test_links.py 97.95% <97.95%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd8f40f...d9fbbdc. Read the comment docs.

@lepmik lepmik marked this pull request as ready for review May 11, 2019 12:48
@@ -71,7 +71,7 @@ class File(Group):
def __init__(self, directory, mode=None, allow_remove=False,
name_validation=None, plugins=None):
self._open_datasets = weakref.WeakValueDictionary({})
directory = pathlib.Path(directory) #.resolve()
directory = pathlib.Path(directory).absolute() #.resolve()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Not that I mind, just good to know why it was added.

Copy link
Member

@dragly dragly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fundamental parts look really good! I would just change some of the behavior :)

@@ -220,6 +220,12 @@ def __getitem__(self, name):
return self
return super(File, self).__getitem__(path)

def __setitem__(self, name, value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to links or is it just something we have left out from before? Seems like this is something that has been missing on File regardless of links?

@@ -413,6 +420,25 @@ def __getitem__(self, name):
)
raise NotImplementedError(error_string)

def _link(self, name, get_link=False):
link_meta = self._group(name).meta[exob.EXDIR_METANAME][exob.LINK_METANAME]
print(link_meta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed :)

@@ -2,6 +2,15 @@
EXDIR_METANAME = "exdir"
TYPE_METANAME = "type"
VERSION_METANAME = "version"
LINK_METANAME = "link"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer if the type is soft_link, external_link, etc. That reduces the level of conditional nesting - you can say if type == "external_link" instead of if type == "link" and link_type == "external". And then have the meta-groups be soft_link and external_link as well. It just reduces the confusion of which variables can go together. (No-one will think that they can just change the target from external to soft and still keep the file, for instance.

f = setup_teardown_file[3]
g = File(external_path, 'w')
f['ext'] = ExternalLink(external_path, '/missing')
with pytest.raises(KeyError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to the comment above: This should not be a KeyError. It should actually return the object that the link is pointing to.

@@ -509,20 +542,22 @@ def __len__(self):
assert_file_open(self.file)
return len([a for a in self])

def get(self, key):
def get(self, name, get_link=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the getter should first try to see if it is an object or a link, instead of forcing the user to tell it to expect a link or not. This is also how h5py works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for internal and external links
2 participants