-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
dl tutorial files to tmp directory, then move them once successful #1393
Conversation
xarray/tutorial.py
Outdated
if not _os.path.exists(tmpfile): | ||
raise ValueError('File could not be downloaded, please try again') | ||
|
||
_shutil.move(tmpfile, localfile) |
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 thought that the issue wasn't that the file isn't downloaded, but rather that it is incompletely downloaded? Will this new temporary step solve this?
Is there a way to make urlretrieve
more robust, with checksums or something?
It seems like urlretrieve is coming directly from urllib. It seems in both
Python 2 and 3 ContentTooShort error should be thrown and isnt. Perhaps
checksums are the right way to go.
…On Tue, May 2, 2017 at 7:14 PM, Fabien Maussion ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In xarray/tutorial.py
<#1393 (comment)>:
>
url = '/'.join((github_url, 'raw', 'master', fullname))
- _urlretrieve(url, localfile)
+ _urlretrieve(url, tmpfile)
+
+ if not _os.path.exists(tmpfile):
+ raise ValueError('File could not be downloaded, please try again')
+
+ _shutil.move(tmpfile, localfile)
I thought that the issue wasn't that the file isn't downloaded, but rather
that it is incompletely downloaded? Will this new temporary step than solve
this?
Is there a way to make urlretrieve more robust, with checksums or
something?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1393 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABVAEVQ4rFwcddY-kEOYnaEaLHsxf_u9ks5r12RkgaJpZM4NOCuy>
.
|
Successful locally with pydata/xarray-data#9:
|
Thanks for taking this on @gidden.
I think this exists to work around the fact that IPython shows everything that isn't private in auto-complete (ipython/ipykernel#129). But we should probably switch back to normal imports in this module -- this is really more of an IPython issue. |
Ok, sounds good. `shutil` was no longer needed, but the md5 checksum was
implemented as private. So I think all is well.
…On Tue, May 2, 2017 at 2:32 PM, Stephan Hoyer ***@***.***> wrote:
Thanks for taking this on @gidden <https://github.com/gidden>.
Also not sure how best to import shutil. I followed the current pattern
for os, but am not sure why that pattern exists in this file.
I think this exists to work around the fact that IPython shows everything
that isn't private in auto-complete (ipython/ipykernel#129
<ipython/ipykernel#129>). But we should
probably switch back to normal imports in this module -- this is really
more of an IPython issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1393 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABVAEW5GuD6D_Y4ANjqM5AnK54h5BRZtks5r14TCgaJpZM4NOCuy>
.
|
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.
It's kind of ridiculous that we have to implement this logic ourselves, but this looks good to me.
xarray/tutorial.py
Outdated
@@ -18,9 +20,17 @@ | |||
_default_cache_dir = _os.sep.join(('~', '.xarray_tutorial_data')) | |||
|
|||
|
|||
def _md5(fname): |
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.
Call this something more descriptive like check_file_md5_hash
?
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.
should it remain private (for ipython completion) or 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.
I wouldn't stress about that. Given that we use it in the script in xarray-data, it's fine either way for me.
ok, this should be good to go |
Thanks @gidden, this look great to me. Could you kindly add a brief note to the "Bug fixes" section of |
I'd be slightly more comfortable if we had this being unit tested on Travis-CI, but that's somewhat tricky to setup because we don't wan to require network access for the test suite by default. You could do this by adding a flag like |
Hey @shoyer, if I have time later I will try to address the unit test issue. If I'm too late, feel free to pull this in the meantime. |
440b6da
to
349099a
Compare
hey @shoyer, @fmaussion. test decorator added with tutorial dataset unit test. i think this is good to go. |
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.
one small fix, otherwise looks good to me -- thanks!
xarray/tests/test_tutorial.py
Outdated
|
||
def setUp(self): | ||
self.testfile = 'tiny' | ||
self.testfilepath = os.path.expanduser(os.sep.join( | ||
('~', '.xarray_tutorial_data', self.testfile))) | ||
with suppress(OSError): | ||
os.remove(self.testfilepath) | ||
os.remove('{}.nc'.format(self.testfilepath)) | ||
os.remove('{}.md5'.format(self.testfilepath)) |
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 should go in its own suppress
block
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.
done!
thanks! |
closes #1392
git diff upstream/master | flake8 --diff
I'm not sure how to best add tests for this. Also not sure how best to import
shutil
. I followed the current pattern foros
, but am not sure why that pattern exists in this file. I can clean up further if this is deemed useful.