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

Use file download URL as provided by the API #370

Merged
merged 2 commits into from
Sep 26, 2023
Merged

Conversation

tdg5
Copy link
Contributor

@tdg5 tdg5 commented Sep 26, 2023

Sparsezoo shouldn't be generating file download URLs, it should use the file downloads provided by the API. The download URLs from the API are cheap and allow sparsezoo to be agnostic of where the files live on the interwebs and decoupled from whatever the current file download implementation is.

@tdg5 tdg5 requested a review from horheynm September 26, 2023 15:12
horheynm
horheynm previously approved these changes Sep 26, 2023
# important, do not remove
if convert_to_bool(os.getenv("SPARSEZOO_TEST_MODE")):
download_url += "?increment_download=False"
delimiter = "&" if "?" in download_url else "?"
Copy link
Member

Choose a reason for hiding this comment

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

nice

file["url"] = get_file_download_url(
model_id=file["model_id"], file_name=file["display_name"]
)
file["url"] = get_file_download_url(file["download_url"])
Copy link
Member

Choose a reason for hiding this comment

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

where is this used now?

Copy link
Member

Choose a reason for hiding this comment

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

actually, never mind, see it was replacing the previous key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The get_file_download_url function is only called from this file, I can get rid of that method and move the logic here if you like. That would look something like:

def include_file_download_url(files: List[Dict]):
    for file in files:
        download_url = file["download_url"]
        del file["download_url"]

        # important, do not remove
        if convert_to_bool(os.getenv("SPARSEZOO_TEST_MODE")):
            delimiter = "&" if "?" in download_url else "?"
            download_url += f"{delimiter}increment_download=False"

        file["url"] = download_url

Copy link
Member

Choose a reason for hiding this comment

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

no need, looks good thanks

model_id=file["model_id"], file_name=file["display_name"]
)
file["url"] = get_file_download_url(file["download_url"])
del file["download_url"]
Copy link
Member

Choose a reason for hiding this comment

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

why delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not required, just trying to maintain the existing file dict interface of sorts. I'd think having both a url and download_url property would confuse anyone looking at the dict and trying to make sense of things

@tdg5 tdg5 merged commit 32c2793 into main Sep 26, 2023
4 checks passed
@tdg5 tdg5 deleted the use-api-download-urls branch September 26, 2023 15:34
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.

None yet

3 participants