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

Fix attribute error in read_checks function #17

Merged
merged 2 commits into from
Jan 26, 2022

Conversation

GenevieveBuckley
Copy link
Contributor

Closes #11

I tried the first example on the fastdownload README page, using the url of one of the standard fastai datasets available on S3. It raised an attribute error, because variable fmod was an empty dictionary instead of the expected pathlib object.

from fastdownload import FastDownload

url = 'https://s3.amazonaws.com/fast-ai-sample/mnist_tiny.tgz'
d = FastDownload()
path = d.get(url)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-50-389349d26777> in <module>
      3 url = 'https://s3.amazonaws.com/fast-ai-sample/mnist_tiny.tgz'
      4 d = FastDownload()
----> 5 path = d.get(url)

~/anaconda3/envs/napari-dev/lib/python3.9/site-packages/fastdownload/core.py in get(self, url, extract_key, force)
    119             data = self.data_path(extract_key, urldest(url, self.arch_path()))
    120             if data.exists(): return data
--> 121         self.download(url, force=force)
    122         return self.extract(url, extract_key=extract_key, force=force)

~/anaconda3/envs/napari-dev/lib/python3.9/site-packages/fastdownload/core.py in download(self, url, force)
     94         "Download `url` to archive path, unless exists and `self.check` fails and not `force`"
     95         self.arch_path().mkdir(exist_ok=True, parents=True)
---> 96         return download_and_check(url, urldest(url, self.arch_path()), self.module, force)
     97 
     98     def rm(self, url, rm_arch=True, rm_data=True, extract_key='data'):

~/anaconda3/envs/napari-dev/lib/python3.9/site-packages/fastdownload/core.py in download_and_check(url, fpath, fmod, force)
     61     "Download `url` to `fpath`, unless exists and `check` fails and not `force`"
     62     if not force and fpath.exists():
---> 63         if check(fmod, url, fpath): return fpath
     64         else: print("Downloading a new version of this dataset...")
     65     res = download_url(url, fpath)

~/anaconda3/envs/napari-dev/lib/python3.9/site-packages/fastdownload/core.py in check(fmod, url, fpath)
     47 def check(fmod, url, fpath):
     48     "Check whether size and hash of `fpath` matches stored data for `url` or data is missing"
---> 49     checks = read_checks(fmod).get(url)
     50     return not checks or path_stats(fpath)==checks
     51 

~/anaconda3/envs/napari-dev/lib/python3.9/site-packages/fastdownload/core.py in read_checks(fmod)
     40 def read_checks(fmod):
     41     "Evaluated contents of `download_checks.py`"
---> 42     if not fmod.exists(): return {}
     43     txt = fmod.read_text()
     44     return eval(txt) if txt else {}

AttributeError: 'dict' object has no attribute 'exists'

This PR avoids that error, by checking whether fmod is an empty dictionary before continuing.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@GenevieveBuckley
Copy link
Contributor Author

I'm not super familiar with nbdev, so if there's anything about the process I should have done differently please let me know.

I looked at both:

...but I don't think I had things working properly (for example, running nbdev_test_nbs on the master branch didn't pass cleanly, which might indicate something is wrong with my setup)

@GenevieveBuckley GenevieveBuckley changed the title Fmod exists error Fix attribute error in read_checks function Oct 5, 2021
@GenevieveBuckley
Copy link
Contributor Author

GenevieveBuckley commented Oct 5, 2021

Note: I think this is probably unrelated to #16 EDIT: perhaps not, turns out the dropbox zip file I was using to check this has something wrong with it (file seems to be corrupt). Probably worth testing it with a better example file on Dropbox.

@tcapelle
Copy link

tcapelle commented Jan 26, 2022

I have the same issue, can you take a look @jph00

@jph00 jph00 merged commit fa9c5d3 into fastai:master Jan 26, 2022
@jph00
Copy link
Member

jph00 commented Jan 26, 2022

Many thanks @GenevieveBuckley !

@seeM
Copy link
Member

seeM commented May 19, 2022

@jph00 Just wanted to note that the latest version of fastdownload on PyPI (0.0.5) still has this bug. A new release would be amazing 😄 I'm happy to help where I can.

For interest sake, I'm currently working around it by installing from GitHub (pinned to the latest commit):

pip install git+https://github.com/fastai/fastdownload.git@2ec6563fef7c92ea975871c8cbcea1a0b02917a1

@jph00 jph00 added the bug Something isn't working label May 20, 2022
@jph00
Copy link
Member

jph00 commented May 20, 2022

Oh sorry @seeM my bad! Thanks for letting me know. Just pushed a release.

@seeM
Copy link
Member

seeM commented May 20, 2022

Thank you, very much appreciated. I really love the library! It's such a pleasure to use 😌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the function read_checks has a bug
4 participants