Skip to content

Commit

Permalink
Merge pull request #728 from dandi/gh-726
Browse files Browse the repository at this point in the history
Invoke etelemetry when constructing a DandiAPIClient; honor DANDI_NO_ET
  • Loading branch information
yarikoptic committed Jul 22, 2021
2 parents 7a3ff79 + 8959978 commit 184cc30
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
25 changes: 3 additions & 22 deletions dandi/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,10 @@ def main(ctx, log_level, pdb=False):
from ..utils import setup_exceptionhook

setup_exceptionhook()
try:
import etelemetry

try:
etelemetry.check_available_version(
"dandi/dandi-cli", __version__, lgr=lgr, raise_exception=True
)
except etelemetry.client.BadVersionError:
# note: SystemExit is based of BaseException, so is not Exception
raise SystemExit(
"DANDI CLI has detected that you are using a version that is known to "
"contain bugs, is incompatible with our current data archive, or has "
"other significant performance limitations. "
"To continue using DANDI CLI, please upgrade your dandi client to a newer "
"version (e.g., using pip install --upgrade dandi if you installed using pip). "
"If you have any issues, please contact the DANDI "
"helpdesk at https://github.com/dandi/helpdesk/issues/new/choose ."
)
except Exception as exc:
lgr.warning(
"Failed to check for a more recent version available with etelemetry: %s",
exc,
)
from ..utils import check_dandi_version

check_dandi_version()


#
Expand Down
3 changes: 2 additions & 1 deletion dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .consts import MAX_CHUNK_SIZE, known_instances, known_instances_rev
from .exceptions import NotFoundError, SchemaVersionError
from .keyring import keyring_lookup
from .utils import USER_AGENT, is_interactive, try_multiple
from .utils import USER_AGENT, check_dandi_version, is_interactive, try_multiple

lgr = get_logger()

Expand Down Expand Up @@ -222,6 +222,7 @@ def paginate(self, path, page_size=None, params=None, **kwargs):

class DandiAPIClient(RESTFullAPIClient):
def __init__(self, api_url=None, token=None):
check_dandi_version()
if api_url is None:
instance_name = os.environ.get("DANDI_INSTANCE", "dandi")
api_url = known_instances[instance_name].api
Expand Down
29 changes: 29 additions & 0 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,32 @@ def get_mime_type(filename: str, strict: bool = False) -> str:
# return mtype + '+gzip'
else:
return "application/x-" + encoding


def check_dandi_version():
if os.environ.get("DANDI_NO_ET"):
return
try:
import etelemetry

try:
etelemetry.check_available_version(
"dandi/dandi-cli", __version__, lgr=lgr, raise_exception=True
)
except etelemetry.client.BadVersionError:
# note: SystemExit is based of BaseException, so is not Exception
raise SystemExit(
"DANDI CLI has detected that you are using a version that is known to "
"contain bugs, is incompatible with our current data archive, or has "
"other significant performance limitations. "
"To continue using DANDI CLI, please upgrade your dandi client to a newer "
"version (e.g., using pip install --upgrade dandi if you installed using pip). "
"If you have any issues, please contact the DANDI "
"helpdesk at https://github.com/dandi/helpdesk/issues/new/choose ."
)
except Exception as exc:
lgr.warning(
"Failed to check for a more recent version available with etelemetry: %s",
exc,
)
os.environ["DANDI_NO_ET"] = "1"

0 comments on commit 184cc30

Please sign in to comment.