Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PYCHECKGLOBS := 'examples/**/*.py' 'scripts/**/*.py' 'src/**/*.py' 'tests/**/*.p
DOCDIR := docs
MDCHECKGLOBS := 'docs/**/*.md' 'docs/**/*.rst' 'examples/**/*.md' 'notebooks/**/*.md' 'scripts/**/*.md'
MDCHECKFILES := CODE_OF_CONDUCT.md CONTRIBUTING.md DEVELOPING.md README.md
SPARSEZOO_TEST_MODE := "true"

BUILD_ARGS := # set nightly to build nightly release
TARGETS := "" # targets for running pytests: full,efficientnet,inception,resnet,vgg,ssd,yolo
Expand Down
6 changes: 5 additions & 1 deletion src/sparsezoo/requests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import os
from typing import Any, List, Union

from sparsezoo.utils import convert_to_bool

__all__ = ["BASE_API_URL", "ModelArgs", "MODELS_API_URL"]

__all__ = ["BASE_API_URL", "ModelArgs", "MODELS_API_URL", "SPARSEZOO_TEST_MODE"]

SPARSEZOO_TEST_MODE = convert_to_bool(os.getenv("SPARSEZOO_TEST_MODE"))

BASE_API_URL = (
os.getenv("SPARSEZOO_API_URL")
Expand Down
13 changes: 10 additions & 3 deletions src/sparsezoo/requests/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import requests

from sparsezoo.requests.authentication import get_auth_header
from sparsezoo.requests.base import MODELS_API_URL, ModelArgs
from sparsezoo.requests.base import MODELS_API_URL, SPARSEZOO_TEST_MODE, ModelArgs


__all__ = ["download_get_request", "DOWNLOAD_PATH"]
Expand Down Expand Up @@ -52,11 +52,18 @@ def download_get_request(
if file_name:
url = f"{url}/{file_name}"

download_args = []

if hasattr(args, "release_version") and args.release_version:
url = f"{url}?release_version={args.release_version}"
download_args.append(f"release_version={args.release_version}")

_LOGGER.debug(f"GET download from {url}")
if SPARSEZOO_TEST_MODE:
download_args.append("increment_download=False")

if download_args:
url = f"{url}?{'&'.join(download_args)}"

_LOGGER.debug(f"GET download from {url}")
response = requests.get(url=url, headers=header)
response.raise_for_status()
response_json = response.json()
Expand Down
2 changes: 1 addition & 1 deletion src/sparsezoo/requests/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def search_get_request(
search_args.extend([f"page={page}", f"page_length={page_length}"])

if args.release_version:
search_args.extend(f"release_version={args.release_version}")
search_args.append(f"release_version={args.release_version}")

search_args = "&".join(search_args)
url = f"{MODELS_API_URL}/{SEARCH_PATH}/{args.model_url_root}?{search_args}"
Expand Down
15 changes: 14 additions & 1 deletion src/sparsezoo/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import errno
import os
from typing import Union
from typing import Any, Union

from tqdm import auto, tqdm, tqdm_notebook


__all__ = [
"CACHE_DIR",
"clean_path",
"convert_to_bool",
"create_dirs",
"create_parent_dirs",
"create_tqdm_auto_constructor",
Expand All @@ -43,6 +44,18 @@ def clean_path(path: str) -> str:
return os.path.abspath(os.path.expanduser(path))


def convert_to_bool(val: Any):
"""
:param val: a value
:return: False if value is a Falsy value e.g. 0, f, false, None, otherwise True.
"""
return (
bool(val)
if not isinstance(val, str)
else bool(val) and "f" not in val.lower() and "0" not in val.lower()
)


def create_dirs(path: str):
"""
:param path: the directory path to try and create
Expand Down