-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
ValidationResult, | ||
) | ||
from sparsezoo.objects import Directory, File, NumpyDirectory, OnnxGz, Recipes | ||
from sparsezoo.utils import BASE_API_URL, convert_to_bool, save_numpy | ||
from sparsezoo.utils import convert_to_bool, save_numpy | ||
|
||
|
||
__all__ = [ | ||
|
@@ -599,9 +599,8 @@ def _copy_and_overwrite(from_path, to_path, func): | |
|
||
def include_file_download_url(files: List[Dict]): | ||
for file in files: | ||
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"]) | ||
del file["download_url"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why delete? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
|
||
def get_model_metadata_from_stub(stub: str) -> Dict[str, str]: | ||
|
@@ -637,15 +636,12 @@ def is_stub(candidate: str) -> bool: | |
|
||
|
||
def get_file_download_url( | ||
model_id: str, | ||
file_name: str, | ||
base_url: str = BASE_API_URL, | ||
download_url: str, | ||
): | ||
"""Url to download a file""" | ||
download_url = f"{base_url}/v2/models/{model_id}/files/{file_name}" | ||
|
||
# important, do not remove | ||
if convert_to_bool(os.getenv("SPARSEZOO_TEST_MODE")): | ||
download_url += "?increment_download=False" | ||
delimiter = "&" if "?" in download_url else "?" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
download_url += f"{delimiter}increment_download=False" | ||
|
||
return download_url |
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.
where is this used now?
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.
actually, never mind, see it was replacing the previous key
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.
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: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.
no need, looks good thanks