-
Notifications
You must be signed in to change notification settings - Fork 51
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
Relative data file path printing #79
Conversation
We might want to add some tests to fully verify that the new parameter is working as expected. |
Codecov Report
@@ Coverage Diff @@
## master #79 +/- ##
=======================================
Coverage 88.12% 88.12%
=======================================
Files 6 6
Lines 362 362
Branches 117 117
=======================================
Hits 319 319
Misses 21 21
Partials 22 22
Continue to review full report at Codecov.
|
Added tests, two for absolute path, two for relative path. Basically, I modified the existing detached header writing tests in a clever way that encompasses new tests. cc: @ihnorton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor issues, but overall I agree with what is being done.
nrrd/tests/test_writing.py
Outdated
@@ -158,7 +158,7 @@ def test_write_detached_raw_as_nrrd(self): | |||
output_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nhdr') | |||
output_data_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nrrd') | |||
|
|||
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True) | |||
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True, relative_data_path= False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True, relative_data_path= False) | |
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True, relative_data_path=False) |
This line is > 120 characters, can you break it at this argument. Repeat for the one other case. Remove the additional space like shown.
Sorry, never explicitly stated that the syntax is to keep lines less than 120 characters, but it's just the standard I use.
nrrd/tests/test_writing.py
Outdated
@@ -228,7 +228,7 @@ def test_write_detached_ascii(self): | |||
data, header = nrrd.read(output_filename) | |||
self.assertEqual(self.expected_data, data.tostring(order='F')) | |||
self.assertEqual(header['encoding'], 'txt') | |||
self.assertEqual(header['data file'], output_data_filename) | |||
self.assertEqual(header['data file'], os.path.basename(output_data_filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output_data_filename
is equal to joined path of temp dir and the filename. We then do the basename to get the filename.
Easier if we just replace output_data_filename
with the relative filename.
Repeat for above case too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't see the relative filename exists here.
nrrd/writer.py
Outdated
@@ -183,12 +186,12 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non | |||
else: | |||
raise NRRDError('Invalid encoding specification while writing NRRD file: %s' % header['encoding']) | |||
|
|||
header['data file'] = data_filename | |||
header['data file'] = os.path.basename(data_filename) if relative_data_path else os.path.abspath(data_filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap at 120 characters please, below line is fine at just under 120.
nrrd/writer.py
Outdated
@@ -121,6 +121,9 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non | |||
Data to save to the NRRD file | |||
detached_header : :obj:`bool`, optional | |||
Whether the header and data should be saved in separate files. Defaults to :obj:`False` | |||
relative_data_path : :class:`bool` | |||
whether the data file name in detached_header is saved with relative path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line wrapped at 82 characters, only wrap at 120 characters.
Capitalize W in whether.
detached_header should be detached header because you are not referencing the boolean variable but rather the actual detached header.
I think we should include a note that this parameter is ignored if the data is attached just to be safe.
And, you say that the "data file name is saved with a relative path", but that sounds odd. The data filename isn't what is saved as a relative path, it's the data file itself.
Altogether, here's what I'm thinking. Comments welcome
Whether the data in a detached header is saved as a relative path or absolute path. This parameter is ignored if the data file is attached to the header file. Defaults to :obj:`True`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that is odd, rather the suggested one sounds like because data is not saved in the detached header. However, counter suggestion combining with yours:
Whether the data file name in detached header is saved with a relative path or absolute path.
This parameter is ignored if there is no detached header. Defaults to :obj:True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR is ready, let me know your final thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few more minor changes, sorry!
In addition, do you mind just quickly reviewing my other PRs. Look for any issues you may see with the code. I should've split it up into multiple PRs but it was just a spring cleaning type of thing.
@@ -228,7 +230,7 @@ def test_write_detached_ascii(self): | |||
data, header = nrrd.read(output_filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one small thing. Since you directly placed the string to be asserted, the output_data_filename
variable is not used. Remove that please
Same for above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will review your other PRs, but may take some time.
nrrd/writer.py
Outdated
@@ -121,6 +121,9 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non | |||
Data to save to the NRRD file | |||
detached_header : :obj:`bool`, optional | |||
Whether the header and data should be saved in separate files. Defaults to :obj:`False` | |||
relative_data_path : :class:`bool` | |||
Whether the data file name in detached header is saved with a relative path or absolute path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, rereading this now I agree with how it's set.
Just one minor thing, I usually prefer the use of filename
rather than file name
. To stay consistent let's change it. I think I have it without the space in the docs and such.
Whether the data file name in detached header is saved with a relative path or absolute path. | |
Whether the data filename in detached header is saved with a relative path or absolute path. |
@tashrifbillah No problem, we're all busy so I understand if it takes you some time. |
Fixes #78