-
Notifications
You must be signed in to change notification settings - Fork 300
Fix expand filespecs #2014
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
Fix expand filespecs #2014
Conversation
|
I see I have some pep8 issues. I'll clean those up, then push through a new commit... |
|
I've edited the test file and pushed the new version. |
| self.assertEqual(iris.io.expand_filespecs( | ||
| [os.path.join(self.tmpdir, '*')]), | ||
| [os.path.join(self.tmpdir, fname) | ||
| for fname in self.fnames]) |
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.
This line is too complex to be easily readable. (The same is true for some other lines later in the file as well.) I'd recommend breaking it up into multiple lines and using descriptive names for the temporary variables. Perhaps:
def test_absolute_path(self):
result = iris.io.expand_filespecs([os.path.join(self.tmpdir, '*')])
expected = [os.path.join(self.tmpdir, fname) for fname in self.fnames]
self.assertEqual(result, expected)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.
Many thanks, @rhattersley Those are good suggestions; I'll have a look into editing along those lines.
|
Here is a new commit, with edits to improve the readability of the code, and also to remove any pep8 line length issues. |
| Returns: | ||
| A list of matching file paths. If any of the file-specs matches no | ||
| A list of matching absolute file paths. If any of the file-specs matches no |
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.
When we have completed this PR, I think we should look at making the sort order of the returned filenames consistent and expected. The behaviour I think we need:
def expand_filespecs(file_specs):
return list_of_expanded_filenames_sorted_by_filespecs_input_order
|
On investigation of the previous Travis failures, some odd behaviour was noted from test_exapnd_filespecs.py. This behaviour consisted of alternating test successes and test failures, when the code was run locally. It appears that this could be down to the unordered output from the dictionary glob_expanded in --init--.py So, the suggested change is to go from to (Edit for typos) |
|
Interestingly, Travis appears to be finding the same set of problems this morning, even with yesterdays edit. I think this suggests that the next step is to substitute in something along the lines of @pelson 's suggestion. |
|
Here is an edit to include a sorting term within expand_filespecs(). The theory is, if value_lists is provided in a consistent order then maybe this will act to regularise the output behaviour. |
|
Thinking about it, this won't work. What sorted() is presumably going to do is take the collection of full file paths out of glob_expanded, and then rearrange them into alphabetical order. But, we need the files in the order that they're in filenames, not the full absolute paths. |
|
And the Travis tests have failed, along with the same expand failure error as before, so sorted() is indeed not the way forward. |
|
In fact, I now see that sorted() also automatically-sorts on case as well, putting upper-case letters first. So the string 'B.txt' will in fact be sorted in front of 'a.dat', which is an important subtlety. |
|
I've been having a look at the insides of expand_filespecs() and I'm starting to think some of it is unnecessary. This statement: just appears to be a complicated way of setting up the error message inside and thus might be creating an unnecessary problem, with the unpredictable-returns thing from the dictionary at glob_expanded. |
|
Perhaps the way forward might be to get rid of this stuff entirely and implement some sort of alternate approach to setting up the error message? |
|
Perhaps a better error-message might be something that makes sure that the expanded paths still include the original file names. With a term also to make sure that there isn't a null result or anything like that. |
|
i think this is not going to be completed, so I am closing the PR |
This is a fix for issue #1508 . The proposed fix changes filepath expansions in expand_filespecs() from relative paths to absolute ones.
In addition, the fix also adds a suitable test for the expand_filespecs function.
(Edit: removal of an unnecessary URL.)